util

package
v6.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: MIT Imports: 27 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 BackupDNS = []string{"1.1.1.1", "8.8.8.8", "9.9.9.9", "223.5.5.5"}

BackupDNS will be used if DNS error occurs.

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 GenerateToken added in v6.5.0

func GenerateToken(username string) string

GenerateToken 生成Token

func GetConfigFilePath

func GetConfigFilePath() string

GetConfigFilePath 获得配置文件路径

func GetConfigFilePathDefault

func GetConfigFilePathDefault() string

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

func GetHTTPResponse

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

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

func GetHTTPResponseOrg

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

GetHTTPResponseOrg 处理HTTP结果,返回byte

func GetRequestIPStr

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 InitBackupDNS added in v6.3.1

func InitBackupDNS(customDNS, lang string)

func InitLogLang

func InitLogLang(lang string) string

func IsPrivateNetwork

func IsPrivateNetwork(remoteAddr string) bool

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

func IsRunInDocker

func IsRunInDocker() bool

IsRunInDocker 是否在docker中运行

func Log

func Log(key string, args ...interface{})

func LogStr

func LogStr(key string, args ...interface{}) string

func LookupHost added in v6.2.0

func LookupHost(url string) error

LookupHost looks up the host based on the given URL using the dialer.Resolver. A wrapper for net.Resolver.LookupHost.

func OpenExplorer

func OpenExplorer(url string)

OpenExplorer 打开本地浏览器

func Ordinal added in v6.2.1

func Ordinal(x int, lang string) string

Ordinal returns the ordinal format of the given number.

See also: https://github.com/dustin/go-humanize/blob/master/ordinals.go

func RequestPayload

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

RequestPayload

func SetDNS added in v6.2.0

func SetDNS(dns string)

SetDNS sets the dialer.Resolver to use the given DNS server.

func SetInsecureSkipVerify

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 SplitLines added in v6.2.2

func SplitLines(s string) []string

SplitLines splits a string into lines by '\r\n' or '\n'.

func StringToSign

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

Create a "String to Sign".

func TencentCloudSigner

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 WaitInternet added in v6.3.0

func WaitInternet(addresses []string)

Wait blocks until the Internet is connected.

See also:

func WriteString

func WriteString(strs ...string) string

WriteString creates a new string using 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