mirror of
https://github.com/aykhans/dodo.git
synced 2025-04-16 09:53:12 +00:00
Merge pull request #95 from aykhans/fix/types
🐛 Fix 'AppendByKey' method of the '[]KeyValue[string, []string]' types
This commit is contained in:
commit
aa6ec450b8
3
main.go
3
main.go
@ -36,6 +36,9 @@ func main() {
|
|||||||
utils.PrintErrAndExit(errors.Join(errs...))
|
utils.PrintErrAndExit(errors.Join(errs...))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// for _, param := range conf.Params {
|
||||||
|
// fmt.Printf("%s: %v\n", param.Key, param.Value)
|
||||||
|
// }
|
||||||
requestConf := config.NewRequestConfig(conf)
|
requestConf := config.NewRequestConfig(conf)
|
||||||
requestConf.Print()
|
requestConf.Print()
|
||||||
|
|
||||||
|
0
output.txt
Normal file
0
output.txt
Normal file
@ -21,7 +21,7 @@ func (cookies Cookies) String() string {
|
|||||||
|
|
||||||
displayLimit := 3
|
displayLimit := 3
|
||||||
|
|
||||||
for i, item := range cookies {
|
for i, item := range cookies[:min(len(cookies), displayLimit)] {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
buffer.WriteString(",\n")
|
buffer.WriteString(",\n")
|
||||||
}
|
}
|
||||||
@ -96,18 +96,18 @@ func (cookies *Cookies) Set(value string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cookies *Cookies) AppendByKey(key string, value string) {
|
func (cookies *Cookies) AppendByKey(key, value string) {
|
||||||
if existingValue := cookies.GetValue(key); existingValue != nil {
|
if item := cookies.GetValue(key); item != nil {
|
||||||
*cookies = append(*cookies, KeyValue[string, []string]{Key: key, Value: append(existingValue, value)})
|
*item = append(*item, value)
|
||||||
} else {
|
} else {
|
||||||
*cookies = append(*cookies, KeyValue[string, []string]{Key: key, Value: []string{value}})
|
*cookies = append(*cookies, KeyValue[string, []string]{Key: key, Value: []string{value}})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cookies *Cookies) GetValue(key string) []string {
|
func (cookies Cookies) GetValue(key string) *[]string {
|
||||||
for _, cookie := range *cookies {
|
for i := range cookies {
|
||||||
if cookie.Key == key {
|
if cookies[i].Key == key {
|
||||||
return cookie.Value
|
return &cookies[i].Value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -21,7 +21,7 @@ func (headers Headers) String() string {
|
|||||||
|
|
||||||
displayLimit := 3
|
displayLimit := 3
|
||||||
|
|
||||||
for i, item := range headers {
|
for i, item := range headers[:min(len(headers), displayLimit)] {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
buffer.WriteString(",\n")
|
buffer.WriteString(",\n")
|
||||||
}
|
}
|
||||||
@ -96,18 +96,18 @@ func (headers *Headers) Set(value string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (headers *Headers) AppendByKey(key string, value string) {
|
func (headers *Headers) AppendByKey(key, value string) {
|
||||||
if existingValue := headers.GetValue(key); existingValue != nil {
|
if item := headers.GetValue(key); item != nil {
|
||||||
*headers = append(*headers, KeyValue[string, []string]{Key: key, Value: append(existingValue, value)})
|
*item = append(*item, value)
|
||||||
} else {
|
} else {
|
||||||
*headers = append(*headers, KeyValue[string, []string]{Key: key, Value: []string{value}})
|
*headers = append(*headers, KeyValue[string, []string]{Key: key, Value: []string{value}})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (headers *Headers) GetValue(key string) []string {
|
func (headers Headers) GetValue(key string) *[]string {
|
||||||
for _, header := range *headers {
|
for i := range headers {
|
||||||
if header.Key == key {
|
if headers[i].Key == key {
|
||||||
return header.Value
|
return &headers[i].Value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -21,7 +21,7 @@ func (params Params) String() string {
|
|||||||
|
|
||||||
displayLimit := 3
|
displayLimit := 3
|
||||||
|
|
||||||
for i, item := range params {
|
for i, item := range params[:min(len(params), displayLimit)] {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
buffer.WriteString(",\n")
|
buffer.WriteString(",\n")
|
||||||
}
|
}
|
||||||
@ -96,18 +96,18 @@ func (params *Params) Set(value string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (params *Params) AppendByKey(key string, value string) {
|
func (params *Params) AppendByKey(key, value string) {
|
||||||
if existingValue := params.GetValue(key); existingValue != nil {
|
if item := params.GetValue(key); item != nil {
|
||||||
*params = append(*params, KeyValue[string, []string]{Key: key, Value: append(existingValue, value)})
|
*item = append(*item, value)
|
||||||
} else {
|
} else {
|
||||||
*params = append(*params, KeyValue[string, []string]{Key: key, Value: []string{value}})
|
*params = append(*params, KeyValue[string, []string]{Key: key, Value: []string{value}})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (params *Params) GetValue(key string) []string {
|
func (params Params) GetValue(key string) *[]string {
|
||||||
for _, param := range *params {
|
for i := range params {
|
||||||
if param.Key == key {
|
if params[i].Key == key {
|
||||||
return param.Value
|
return ¶ms[i].Value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user