Skip to content

Commit

Permalink
update README
Browse files Browse the repository at this point in the history
  • Loading branch information
imroc committed Jan 26, 2020
1 parent 46bda37 commit d679d25
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,24 +105,24 @@ header.Set("Accept", "application/json")
req.Get("https://www.baidu.com", header)
```

#### Set Header From Struct
Use `HeaderFromStruct` func to parse your struct
You can also set header from struct, use `HeaderFromStruct` func to parse your struct
``` go
type HeaderStruct struct {
UserAgent string `json:"User-Agent"`
Authorization string `json:"Authorization"`
}
UserAgent string `json:"User-Agent"`
Authorization string `json:"Authorization"`
}

func main(){
h := HeaderStruct{
"V1.0.0",
"roc",
}

authHeader := req.HeaderFromStruct(h)
req.Get("https://www.baidu.com", authHeader, req.Header{"User-Agent": "V1.1"})
}
```

Note: Please add tag 'json' to your argument in struct to let you customize the key name of your header
> Note: Please add tag 'json' to your argument in struct to let you customize the key name of your header
## <a name="Set-Param">Set Param</a>
Use `req.Param` (it is actually a `map[string]interface{}`)
Expand Down
19 changes: 19 additions & 0 deletions doc/README_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,25 @@ header.Set("Accept", "application/json")
req.Get("https://www.baidu.com", header)
```

你可以使用 `struct` 来设置请求头,用 `HeaderFromStruct` 这个函数来解析你的 `struct`
``` go
type HeaderStruct struct {
UserAgent string `json:"User-Agent"`
Authorization string `json:"Authorization"`
}

func main(){
h := HeaderStruct{
"V1.0.0",
"roc",
}

authHeader := req.HeaderFromStruct(h)
req.Get("https://www.baidu.com", authHeader, req.Header{"User-Agent": "V1.1"})
}
```
> 注:请给你的 struct 加上 json tag.
## <a name="Set-Param">设置请求参数</a>
Use `req.Param` (它实际上是一个 `map[string]interface{}`)
``` go
Expand Down

0 comments on commit d679d25

Please sign in to comment.