37 lines
599 B
Go
37 lines
599 B
Go
package router
|
|
|
|
import "strings"
|
|
|
|
type Header map[string][]string
|
|
|
|
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
|
|
}
|
|
}
|