You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
simpleRequest/authorization.go

38 lines
819 B
Go

/*
2 years ago
*FileName: auth.go
*Author: JJXu
*CreateTime: 2022/3/24 12:09
*Description:
*/
package simpleRequest
import (
"encoding/base64"
"fmt"
)
type Authorization struct {
simpleReq *SimpleRequest
}
2 years ago
// Basic
// Description: 身份验证使用bearer 令牌bearer 令牌
// receiver s
// param username
// param password
func (s *Authorization) Bearer(token string) {
3 years ago
s.simpleReq.headers.Set("Authorization", fmt.Sprintf("Bearer %v", token))
}
2 years ago
// Basic
// Description: 身份验证的基本验证方案
// receiver s
// param username
// param password
func (s *Authorization) Basic(username, password string) {
authStr := fmt.Sprintf("%v:%v", username, password)
data := base64.StdEncoding.EncodeToString([]byte(authStr))
3 years ago
s.simpleReq.headers.Set("Authorization", fmt.Sprintf("Basic %v", data))
}