Files
2025-04-15 12:59:17 +08:00

33 lines
616 B
Go

package httpclient
import (
"time"
)
type HeaderMap map[string]string
func WithHeader(header HeaderMap) HTTPOption {
return func(c *HTTPCli) {
for k, v := range header {
c.req.Header.Set(k, v)
}
}
}
func WithTimeout(timeout time.Duration) HTTPOption {
return func(c *HTTPCli) {
c.client.Timeout = timeout
}
}
func WithStream() HTTPOption {
return func(c *HTTPCli) {
c.req.Header.Set("Accept", "text/event-stream")
}
}
func WithTokenHeaderOption(token string) HTTPOption {
m := map[string]string{"Authorization": "Bearer " + token, "Content-Type": "application/json"}
return WithHeader(m)
}