-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathauth.go
More file actions
38 lines (31 loc) · 734 Bytes
/
auth.go
File metadata and controls
38 lines (31 loc) · 734 Bytes
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
package grequest
type BasicAuth struct {
User string
Pass string
}
const authorization = "Authorization"
type Auth struct {
Client *HTTPClient
}
// Init status
func (c *HTTPClient) Auth() *Auth {
return &Auth{Client: c}
}
// Sets basic auth in request
func (c *Auth) SetBasic(user, pass string) *HTTPClient {
c.Client.request.basic = &BasicAuth{
User: user,
Pass: pass,
}
return c.Client
}
// Sets custom auth token in header request
func (c *Auth) SetToken(token string) *HTTPClient {
c.Client.Header().Set(authorization, token)
return c.Client
}
// Sets bearer token in header request
func (c *Auth) SetBearer(token string) *HTTPClient {
c.Client.Header().Set(authorization, "Bearer "+token)
return c.Client
}