simpleRequest/authorization.go
= 9bff109127 1. 优化说明文档
2. 添加了部分测试用例
2022-12-09 21:43:15 +08:00

42 lines
857 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* @FileName: auth.go
* @Author: JJXu
* @CreateTime: 2022/3/24 上午12:09
* @Description:
*/
package simpleRequest
import (
"encoding/base64"
"fmt"
)
type Authorization struct {
simpleReq *SimpleRequest
}
//
// Basic
// @Description: 身份验证使用bearer 令牌bearer 令牌
// @receiver s
// @param username
// @param password
//
func (s *Authorization) Bearer(token string) {
s.simpleReq.headers.Set("Authorization", fmt.Sprintf("Bearer %v", token))
}
//
// 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))
s.simpleReq.headers.Set("Authorization", fmt.Sprintf("Basic %v", data))
}