-
Notifications
You must be signed in to change notification settings - Fork 0
/
http.go
43 lines (34 loc) · 889 Bytes
/
http.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
* Author: fasion
* Created time: 2024-01-05 08:49:25
* Last Modified by: fasion
* Last Modified time: 2024-01-05 13:42:19
*/
package netutils
import (
"net/http"
"github.com/fasionchan/goutils/stl"
"github.com/fasionchan/goutils/types"
)
type CookiePtr = *http.Cookie
type Cookies []*http.Cookie
func (cookies Cookies) Native() []*http.Cookie {
return cookies
}
func (cookies Cookies) Strings() types.Strings {
return stl.Map(cookies, CookiePtr.String)
}
func (cookies Cookies) String() string {
return cookies.Strings().Join("; ")
}
func NewCookiesFromMap(mapping map[string]string) Cookies {
return stl.MapMapToSlice[Cookies](mapping, func(name, value string, _ map[string]string) *http.Cookie {
return &http.Cookie{
Name: name,
Value: value,
}
})
}
func NewHeaderFromMap(m map[string]string) http.Header {
return stl.MultivalueMap[http.Header](m)
}