Merge pull request #95 from aykhans/fix/types

🐛 Fix 'AppendByKey' method of the '[]KeyValue[string, []string]' types
This commit is contained in:
Aykhan Shahsuvarov 2025-03-19 04:06:47 +04:00 committed by GitHub
commit aa6ec450b8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 27 additions and 24 deletions

View File

@ -36,6 +36,9 @@ func main() {
utils.PrintErrAndExit(errors.Join(errs...))
}
// for _, param := range conf.Params {
// fmt.Printf("%s: %v\n", param.Key, param.Value)
// }
requestConf := config.NewRequestConfig(conf)
requestConf.Print()

0
output.txt Normal file
View File

View File

@ -21,7 +21,7 @@ func (cookies Cookies) String() string {
displayLimit := 3
for i, item := range cookies {
for i, item := range cookies[:min(len(cookies), displayLimit)] {
if i > 0 {
buffer.WriteString(",\n")
}
@ -96,18 +96,18 @@ func (cookies *Cookies) Set(value string) error {
return nil
}
func (cookies *Cookies) AppendByKey(key string, value string) {
if existingValue := cookies.GetValue(key); existingValue != nil {
*cookies = append(*cookies, KeyValue[string, []string]{Key: key, Value: append(existingValue, value)})
func (cookies *Cookies) AppendByKey(key, value string) {
if item := cookies.GetValue(key); item != nil {
*item = append(*item, value)
} else {
*cookies = append(*cookies, KeyValue[string, []string]{Key: key, Value: []string{value}})
}
}
func (cookies *Cookies) GetValue(key string) []string {
for _, cookie := range *cookies {
if cookie.Key == key {
return cookie.Value
func (cookies Cookies) GetValue(key string) *[]string {
for i := range cookies {
if cookies[i].Key == key {
return &cookies[i].Value
}
}
return nil

View File

@ -21,7 +21,7 @@ func (headers Headers) String() string {
displayLimit := 3
for i, item := range headers {
for i, item := range headers[:min(len(headers), displayLimit)] {
if i > 0 {
buffer.WriteString(",\n")
}
@ -96,18 +96,18 @@ func (headers *Headers) Set(value string) error {
return nil
}
func (headers *Headers) AppendByKey(key string, value string) {
if existingValue := headers.GetValue(key); existingValue != nil {
*headers = append(*headers, KeyValue[string, []string]{Key: key, Value: append(existingValue, value)})
func (headers *Headers) AppendByKey(key, value string) {
if item := headers.GetValue(key); item != nil {
*item = append(*item, value)
} else {
*headers = append(*headers, KeyValue[string, []string]{Key: key, Value: []string{value}})
}
}
func (headers *Headers) GetValue(key string) []string {
for _, header := range *headers {
if header.Key == key {
return header.Value
func (headers Headers) GetValue(key string) *[]string {
for i := range headers {
if headers[i].Key == key {
return &headers[i].Value
}
}
return nil

View File

@ -21,7 +21,7 @@ func (params Params) String() string {
displayLimit := 3
for i, item := range params {
for i, item := range params[:min(len(params), displayLimit)] {
if i > 0 {
buffer.WriteString(",\n")
}
@ -96,18 +96,18 @@ func (params *Params) Set(value string) error {
return nil
}
func (params *Params) AppendByKey(key string, value string) {
if existingValue := params.GetValue(key); existingValue != nil {
*params = append(*params, KeyValue[string, []string]{Key: key, Value: append(existingValue, value)})
func (params *Params) AppendByKey(key, value string) {
if item := params.GetValue(key); item != nil {
*item = append(*item, value)
} else {
*params = append(*params, KeyValue[string, []string]{Key: key, Value: []string{value}})
}
}
func (params *Params) GetValue(key string) []string {
for _, param := range *params {
if param.Key == key {
return param.Value
func (params Params) GetValue(key string) *[]string {
for i := range params {
if params[i].Key == key {
return &params[i].Value
}
}
return nil