utils

package
v0.2.0-beta Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2026 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HttpMethodPut  = "PUT"
	HttpMethodGet  = "GET"
	HttpMethodPost = "POST"
)
View Source
const (
	Seed1 = ".alibaba_cloud_idaas_seed1"
	Seed2 = ".alibaba_cloud_idaas_seed2"
)
View Source
const (
	TermReset  = "\033[0m"
	TermBold   = "\033[1m"
	TermUnder  = "\033[4m"
	TermRed    = "\033[31m"
	TermGreen  = "\033[32m"
	TermYellow = "\033[33m"
	TermBlue   = "\033[34m"
)

Variables

View Source
var (
	UnsafeSkipCertificateVerification = idaaslog.IsOn(os.Getenv(constants.EnvUnsafeSkipCertificateVerification))
	RootCertificates                  = os.Getenv(constants.EnvRootCertificates)
)
View Source
var (
	IsNonStdOutTerminal = !terminal.IsTerminal(int(os.Stdout.Fd()))
	IsNonStdErrTerminal = !terminal.IsTerminal(int(os.Stderr.Fd()))
	IsNonTerminal       = IsNonStdOutTerminal || IsNonStdErrTerminal
)
View Source
var (
	// EnableEncryptWithMac more secure when turns on, but more stable when off
	EnableEncryptWithMac = idaaslog.IsOn(os.Getenv(constants.EnvEnableEncryptWithMac))
)
View Source
var Stderr = StdErrOut{
	// contains filtered or unexported fields
}
View Source
var Stdout = StdErrOut{
	// contains filtered or unexported fields
}
View Source
var UserAgent = GetUserAgent()

Functions

func Blue

func Blue(str string, color bool) string

func Bold

func Bold(str string, color bool) string

func BuildHttpClient

func BuildHttpClient() *http.Client

func DecryptText

func DecryptText(ciphertext string, additionalData []byte) (string, error)

func EncryptText

func EncryptText(plaintext string, additionalData []byte) (string, error)

func Fetch

func Fetch(client *http.Client, method, endpoint string, headers map[string]string) ([]byte, error)

func FetchAsString

func FetchAsString(client *http.Client, method, endpoint string, headers map[string]string) (string, error)

func FetchWithBody

func FetchWithBody(client *http.Client, method, endpoint string, headers map[string]string, requestBytes []byte) ([]byte, error)

func FetchWithBodyAsString

func FetchWithBodyAsString(client *http.Client, method, endpoint string, headers map[string]string, requestBytes []byte) (string, error)

func GetHttp

func GetHttp(getUrl string) (int, string, error)

func GetMacAddress

func GetMacAddress() (string, error)

func GetUserAgent

func GetUserAgent() string

func Green

func Green(str string, color bool) string

func NormalizeDeveloperApiEndpoint

func NormalizeDeveloperApiEndpoint(developerApiEndpoint string) string

func OpenUrl

func OpenUrl(url string) error

func ParseECDSASignatureToRs

func ParseECDSASignatureToRs(signature []byte) ([]byte, error)

ParseECDSASignatureToRs Parse DER format to R and S ECDSA DER format looks like below:

SEQUENCE {
   INTEGER r
   INTEGER s
}

Example:

SEQUENCE {
 INTEGER: 0083ef88158ebfe6065c8c9a6e00724685309a42366ff9cdf38931c0203229127c
 INTEGER: 29068abc9e216f18ac5a3831b9c7bfdb7289c757fcefda441b8cf41e774a98a9
}

func PostHttp

func PostHttp(postUrl string, parameters map[string]string) (int, string, error)

func ReadCacheFileWithEncryption

func ReadCacheFileWithEncryption(category, key string) (string, error)

func ReadCacheFileWithEncryptionCallback

func ReadCacheFileWithEncryptionCallback(category, key string, options *ReadCacheOptions) (string, error)

func ReadCacheWithEncryptionCallback

func ReadCacheWithEncryptionCallback(category, key string, cacheReadWrite CacheReadWrite, options *ReadCacheOptions) (string, error)

func Red

func Red(str string, color bool) string

func RemoveCacheFile

func RemoveCacheFile(category, key string) error

func Sha256ToBase32

func Sha256ToBase32(message string) string

func Sha256ToHex

func Sha256ToHex(message string) string

func SleepSeconds

func SleepSeconds(interval int64)

func Under

func Under(str string, color bool) string

func WBlue

func WBlue(str string) string

func WBold

func WBold(str string) string

func WGreen

func WGreen(str string) string

func WRed

func WRed(str string) string

func WUnder

func WUnder(str string) string

func WYellow

func WYellow(str string) string

func WithColor

func WithColor(str, termColor string, color bool) string

func WriteCacheFileWithEncryption

func WriteCacheFileWithEncryption(category, key string, plaintext string) error

func Yellow

func Yellow(str string, color bool) string

Types

type CacheReadWrite

type CacheReadWrite interface {
	Read(string, string) (string, error)
	Write(string, string, string) error
}

type ECDSASignature

type ECDSASignature struct {
	R, S *big.Int
}

type EncryptedFileCacheReadWrite

type EncryptedFileCacheReadWrite struct{}

func (*EncryptedFileCacheReadWrite) Read

func (e *EncryptedFileCacheReadWrite) Read(category string, key string) (string, error)

func (*EncryptedFileCacheReadWrite) Write

func (e *EncryptedFileCacheReadWrite) Write(category string, key string, content string) error

type ReadCacheOptions

type ReadCacheOptions struct {
	Context                    map[string]interface{}
	FetchContent               func() (int, string, error)
	ForceNew                   bool
	AllowExpired               bool
	IsContentExpiringOrExpired func(time *StringWithTime) bool
	IsContentExpired           func(time *StringWithTime) bool
}

type StdErrOut

type StdErrOut struct {
	// contains filtered or unexported fields
}

func (*StdErrOut) Fprintf

func (s *StdErrOut) Fprintf(format string, args ...interface{})

func (*StdErrOut) Print

func (s *StdErrOut) Print(message string)

func (*StdErrOut) Printf

func (s *StdErrOut) Printf(format string, args ...interface{})

func (*StdErrOut) Println

func (s *StdErrOut) Println(message string)

type StringWithTime

type StringWithTime struct {
	CacheTime int64                  `json:"cache_time"`
	Context   map[string]interface{} `json:"context"`
	Content   string                 `json:"content"`
}

func UnmarshalStringWithTime

func UnmarshalStringWithTime(str string) (*StringWithTime, error)

func (*StringWithTime) IsExpired

func (s *StringWithTime) IsExpired() bool

func (*StringWithTime) IsExpiredWithCustomFunc

func (s *StringWithTime) IsExpiredWithCustomFunc(isExpired func(time *StringWithTime) bool) bool

func (*StringWithTime) IsExpiringOrExpired

func (s *StringWithTime) IsExpiringOrExpired() bool

func (*StringWithTime) IsExpiringOrExpiredWithCustomFunc

func (s *StringWithTime) IsExpiringOrExpiredWithCustomFunc(isExpiringOrExpired func(time *StringWithTime) bool) bool

func (*StringWithTime) Marshal

func (s *StringWithTime) Marshal() (string, error)

type UrlBuilder

type UrlBuilder struct {
	BasePath string
	Params   url.Values
}

func NewUrlBuilder

func NewUrlBuilder(path string) *UrlBuilder

func (*UrlBuilder) AddQuery

func (b *UrlBuilder) AddQuery(key, value string)

func (*UrlBuilder) BuildUrl

func (b *UrlBuilder) BuildUrl() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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