util

package
v5.7.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 7, 2024 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BasicDateFormat     = "20060102T150405Z"
	Algorithm           = "SDK-HMAC-SHA256"
	HeaderXDate         = "X-Sdk-Date"
	HeaderHost          = "host"
	HeaderAuthorization = "Authorization"
	HeaderContentSha256 = "X-Sdk-Content-Sha256"
)
View Source
const (
	BaiduDateFormat = "2006-01-02T15:04:05Z"
)
View Source
const ConfigFilePathENV = "DDNS_CONFIG_FILE_PATH"
View Source
const DockerEnvFile string = "/.dockerenv"

DockerEnvFile Docker容器中包含的文件

View Source
const IPCacheTimesENV = "DDNS_IP_CACHE_TIMES"

Variables

View Source
var ForceCompareGlobal = true

Functions

func AliyunSigner

func AliyunSigner(accessKeyID, accessSecret string, params *url.Values)

AliyunSigner AliyunSigner

func AuthHeaderValue

func AuthHeaderValue(signature, accessKey string, signedHeaders []string) string

Get the finalized value for the "Authorization" header. The signature parameter is the output from SignStringToSign

func BaiduCanonicalURI

func BaiduCanonicalURI(r *http.Request) string

func BaiduSigner

func BaiduSigner(accessKeyID, accessSecret string, r *http.Request)

BaiduSigner set Authorization header

func CanonicalHeaders

func CanonicalHeaders(r *http.Request, signerHeaders []string) string

CanonicalHeaders

func CanonicalQueryString

func CanonicalQueryString(r *http.Request) string

CanonicalQueryString

func CanonicalRequest

func CanonicalRequest(r *http.Request, signedHeaders []string) (string, error)

Build a CanonicalRequest from a regular request string

CanonicalRequest =

HTTPRequestMethod + '\n' +
CanonicalURI + '\n' +
CanonicalQueryString + '\n' +
CanonicalHeaders + '\n' +
SignedHeaders + '\n' +
HexEncode(Hash(RequestPayload))

func CanonicalURI

func CanonicalURI(r *http.Request) string

CanonicalURI returns request uri

func CreateHTTPClient

func CreateHTTPClient() *http.Client

CreateHTTPClient Create Default HTTP Client

func CreateNoProxyHTTPClient

func CreateNoProxyHTTPClient(network string) *http.Client

CreateNoProxyHTTPClient Create NoProxy HTTP Client

func GetConfigFilePath

func GetConfigFilePath() string

GetConfigFilePath 获得配置文件路径

func GetConfigFilePathDefault

func GetConfigFilePathDefault() string

GetConfigFilePathDefault 获得默认的配置文件路径

func GetHTTPResponse

func GetHTTPResponse(resp *http.Response, url string, err error, result interface{}) error

GetHTTPResponse 处理HTTP结果,返回序列化的json

func GetHTTPResponseOrg

func GetHTTPResponseOrg(resp *http.Response, url string, err error) ([]byte, error)

GetHTTPResponseOrg 处理HTTP结果,返回byte

func GetRequestIPStr added in v5.0.4

func GetRequestIPStr(r *http.Request) (addr string)

GetRequestIPStr get IP string from request

func HexEncodeSHA256Hash

func HexEncodeSHA256Hash(body []byte) (string, error)

HexEncodeSHA256Hash returns hexcode of sha256

func HmacSha256Hex

func HmacSha256Hex(secret, message string) string

func HmacSign

func HmacSign(signMethod string, httpMethod string, appKeySecret string, vals url.Values) (signature []byte)

func HmacSignToB64

func HmacSignToB64(signMethod string, httpMethod string, appKeySecret string, vals url.Values) (signature string)

func IsPrivateNetwork

func IsPrivateNetwork(remoteAddr string) bool

IsPrivateNetwork 是否为私有地址 https://en.wikipedia.org/wiki/Private_network

func IsRunInDocker

func IsRunInDocker() bool

IsRunInDocker 是否在docker中运行

func NewDialerResolver added in v5.6.1

func NewDialerResolver(s string)

NewDialerResolver 使用 s 将 dialer.Resolver 设置为新的 net.Resolver。

s:用于创建新 net.Resolver 的字符串。

func OpenExplorer

func OpenExplorer(url string)

OpenExplorer 打开本地浏览器

func RequestPayload

func RequestPayload(r *http.Request) ([]byte, error)

RequestPayload

func SetInsecureSkipVerify added in v5.6.1

func SetInsecureSkipVerify()

SetInsecureSkipVerify 将所有 http.Transport 的 InsecureSkipVerify 设置为 true

func SignStringToSign

func SignStringToSign(stringToSign string, signingKey []byte) (string, error)

Create the HWS Signature.

func SignedHeaders

func SignedHeaders(r *http.Request) []string

SignedHeaders

func StringToSign

func StringToSign(canonicalRequest string, t time.Time) (string, error)

Create a "String to Sign".

func TencentCloudSigner added in v5.3.0

func TencentCloudSigner(secretId string, secretKey string, r *http.Request, action string, payload string)

TencentCloudSigner 腾讯云签名方法 v3 https://cloud.tencent.com/document/api/1427/56189#Golang

func WriteString added in v5.3.0

func WriteString(strs ...string) string

WriteString 使用 strings.Builder 生成字符串并返回 string https://pkg.golang.ir/strings#Builder

Types

type IpCache

type IpCache struct {
	Addr          string // 缓存地址
	Times         int    // 剩余次数
	TimesFailedIP int    // 获取ip失败的次数
}

IpCache 上次IP缓存

func (*IpCache) Check

func (d *IpCache) Check(newAddr string) bool

type Signer

type Signer struct {
	Key    string
	Secret string
}

Signature HWS meta

func (*Signer) Sign

func (s *Signer) Sign(r *http.Request) error

SignRequest set Authorization header

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL