Skip to content

Commit

Permalink
update grpc and viper version &
Browse files Browse the repository at this point in the history
fixed bug for httpclient add header.
  • Loading branch information
yoyofx committed Dec 14, 2023
1 parent 73e5608 commit d79eafa
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/httpclient/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ type Request struct {
func (c *Request) Header(key, value string) *Request {
c.mutex.Lock()
defer c.mutex.Unlock()
if c.header == nil {
c.header = map[string][]string{}
}
c.header.Add(key, value)
if strings.ToLower(key) == "content-type" {
c.contentType = value
Expand Down Expand Up @@ -66,11 +69,19 @@ func (c *Request) GET(url string) *Request {
func (c *Request) ContentType(value string) *Request {
c.mutex.Lock()
defer c.mutex.Unlock()
if c.header == nil {
c.header = map[string][]string{}
}
c.header.Set("Content-Type", value)
c.contentType = value
return c
}

func (c *Request) WithContentTypeAsJson() *Request {
c.ContentType("application/json")
return c
}

// WithHost 添加请求头host
func (c *Request) WithHost(host string) *Request {
c.host = host
Expand Down

0 comments on commit d79eafa

Please sign in to comment.