router/header.go

43 lines
694 B
Go
Raw Normal View History

2024-10-07 21:39:42 +00:00
package router
2024-10-07 22:14:34 +00:00
import (
"strings"
)
2024-10-07 21:39:42 +00:00
type Header map[string][]string
2024-10-08 22:04:57 +00:00
func (h Header) Parse(data any) error {
2024-10-09 01:06:53 +00:00
return genericValues(h).Parse(data, "header")
2024-10-07 22:14:34 +00:00
}
2024-10-07 21:39:42 +00:00
func (h Header) Get(key string) (value string) {
v, ok := h[key]
if !ok {
return
}
return strings.Join(v, ", ")
}
func (h Header) Set(key string, value string) {
h[key] = []string{value}
}
func (h Header) Add(key string, value string) {
h[key] = append(h[key], value)
}
func (h Header) Merge(header Header) {
for key, value := range header {
if _, exists := h[key]; exists {
continue
}
h[key] = value
}
}
func (h Header) MergeOverwrite(header Header) {
for key, value := range header {
h[key] = value
}
}