sailor

package module
Version: v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2020 License: MIT Imports: 20 Imported by: 1

README

sailor

Build Status go.dev reference

Sailor is a Base Common Golang Lib.

Airdb-Defined Error Codes

Airdb reserved the error code range from 20000 to 24999 for defined Error Codes.

Error Codes

Reference

Stargazers over time

Stargazers over time

Documentation

Overview

From aws-sdk-go-v2 convert_types.go

Index

Constants

View Source
const (
	CloudPlatformAWS    = "aws"
	CloudPlatformAliyun = "aliyun"

	// The name from github. XD
	CloudPlatformTencent = "tencentyun"
)
View Source
const (
	DelimiterNewline   = "\n"
	DelimiterComma     = ","
	DelimiterDot       = "."
	DelimiterAt        = "@"
	DelimiterStar      = "*"
	DelimiterDash      = "-"
	DelimiterSlash     = "/"
	DelimiterUnderline = "_"
	DelimiterStarHex   = "\\052"
)

Delimiter const value.

View Source
const (
	OperationCreate string = "CREATE"
	OperationUpdate string = "UPDATE"
	OperationDelete string = "DELETE"
	OperationUpsert string = "UPSERT"
	OperationPatch  string = "PATCH"
	OperationPut    string = "PUT"
)

Operation const value.

View Source
const (
	FilePerm600 os.FileMode = 0600 // For secret files.
	FilePerm644 os.FileMode = 0644 // For normal files.
	FilePerm755 os.FileMode = 0755 // For directory or execute files.
)
View Source
const (
	UserAgent    = "sailor-agent/1.0.0"
	UserAgentKey = "User-Agent"
)
View Source
const (
	DefaultDNSServer = "8.8.8.8:53"
)

Variables

View Source
var DNSRetry int = 3
View Source
var DNSTimeout time.Duration = 3
View Source
var DefaultClient = &http.Client{
	Timeout: 60 * time.Second,
}
View Source
var DeployPolicyMap = map[DeployPolicy]string{

	DeployPolicyBlue: "blue",

	DeployPolicyGreen: "green",

	DeployPolicyRed: "red",

	DeployPolicyBlack: "black",
}

Functions

func Bool

func Bool(v bool) *bool

Bool returns a pointer to the bool value passed in.

func BoolMap

func BoolMap(src map[string]bool) map[string]*bool

BoolMap converts a string map of bool values into a string map of bool pointers.

func BoolSlice

func BoolSlice(src []bool) []*bool

BoolSlice converts a slice of bool values into a slice of bool pointers.

func BoolValue

func BoolValue(v *bool) bool

BoolValue returns the value of the bool pointer passed in or false if the pointer is nil.

func BoolValueMap

func BoolValueMap(src map[string]*bool) map[string]bool

BoolValueMap converts a string map of bool pointers into a string map of bool values.

func BoolValueSlice

func BoolValueSlice(src []*bool) []bool

BoolValueSlice converts a slice of bool pointers into a slice of bool values.

func BytesToString

func BytesToString(b []byte) string

b2s converts byte slice to a string without memory allocation. See https://groups.google.com/forum/#!msg/Golang-Nuts/ENgbUzYvCuU/90yGx7GUAgAJ .

Note it may break if string and/or slice header will change in the future go versions.

func DoRequest

func DoRequest(client *http.Client,
	req *http.Request,
	requestInterface RequestInterface,
	responseInterface ResponseInterface,
) error

func EnsureFileExists

func EnsureFileExists(path string)

func EnsureFolderExists

func EnsureFolderExists(folder string)

func Exec

func Exec(bin string, args []string)

func ExecCommand

func ExecCommand(bin string, args []string) (string, error)

func Exists

func Exists(path string) bool

func Float32

func Float32(v float32) *float32

Float32 returns a pointer to the float32 value passed in.

func Float32Map

func Float32Map(src map[string]float32) map[string]*float32

Float32Map converts a string map of float32 values into a string map of float32 pointers.

func Float32Slice

func Float32Slice(src []float32) []*float32

Float32Slice converts a slice of float32 values into a slice of float32 pointers.

func Float32Value

func Float32Value(v *float32) float32

Float32Value returns the value of the float32 pointer passed in or 0 if the pointer is nil.

func Float32ValueMap

func Float32ValueMap(src map[string]*float32) map[string]float32

Float32ValueMap converts a string map of float32 pointers into a string map of float32 values.

func Float32ValueSlice

func Float32ValueSlice(src []*float32) []float32

Float32ValueSlice converts a slice of float32 pointers into a slice of float32 values.

func Float64

func Float64(v float64) *float64

Float64 returns a pointer to the float64 value passed in.

func Float64Map

func Float64Map(src map[string]float64) map[string]*float64

Float64Map converts a string map of float64 values into a string map of float64 pointers.

func Float64Slice

func Float64Slice(src []float64) []*float64

Float64Slice converts a slice of float64 values into a slice of float64 pointers.

func Float64Value

func Float64Value(v *float64) float64

Float64Value returns the value of the float64 pointer passed in or 0 if the pointer is nil.

func Float64ValueMap

func Float64ValueMap(src map[string]*float64) map[string]float64

Float64ValueMap converts a string map of float64 pointers into a string map of float64 values.

func Float64ValueSlice

func Float64ValueSlice(src []*float64) []float64

Float64ValueSlice converts a slice of float64 pointers into a slice of float64 values.

func FromDeployPolicy

func FromDeployPolicy(policy DeployPolicy) string

func GetDomainSuffix

func GetDomainSuffix(name string) string

func GetRootDomain

func GetRootDomain(name string) (string, error)

func HTTPRequest

func HTTPRequest(requestInterface RequestInterface, responseInterface ResponseInterface) error

func HTTPRequestWithClient

func HTTPRequestWithClient(client *http.Client,
	requestInterface RequestInterface,
	responseInterface ResponseInterface,
) error

func Int

func Int(v int) *int

Int returns a pointer to the int value passed in.

func Int16

func Int16(v int16) *int16

Int16 returns a pointer to the int16 value passed in.

func Int16Map

func Int16Map(src map[string]int16) map[string]*int16

Int16Map converts a string map of int16 values into a string map of int16 pointers.

func Int16Slice

func Int16Slice(src []int16) []*int16

Int16Slice converts a slice of int16 values into a slice of int16 pointers.

func Int16Value

func Int16Value(v *int16) int16

Int16Value returns the value of the int16 pointer passed in or 0 if the pointer is nil.

func Int16ValueMap

func Int16ValueMap(src map[string]*int16) map[string]int16

Int16ValueMap converts a string map of int16 pointers into a string map of int16 values.

func Int16ValueSlice

func Int16ValueSlice(src []*int16) []int16

Int16ValueSlice converts a slice of int16 pointers into a slice of int16 values.

func Int32

func Int32(v int32) *int32

Int32 returns a pointer to the int32 value passed in.

func Int32Map

func Int32Map(src map[string]int32) map[string]*int32

Int32Map converts a string map of int32 values into a string map of int32 pointers.

func Int32Slice

func Int32Slice(src []int32) []*int32

Int32Slice converts a slice of int32 values into a slice of int32 pointers.

func Int32Value

func Int32Value(v *int32) int32

Int32Value returns the value of the int32 pointer passed in or 0 if the pointer is nil.

func Int32ValueMap

func Int32ValueMap(src map[string]*int32) map[string]int32

Int32ValueMap converts a string map of int32 pointers into a string map of int32 values.

func Int32ValueSlice

func Int32ValueSlice(src []*int32) []int32

Int32ValueSlice converts a slice of int32 pointers into a slice of int32 values.

func Int64

func Int64(v int64) *int64

Int64 returns a pointer to the int64 value passed in.

func Int64Map

func Int64Map(src map[string]int64) map[string]*int64

Int64Map converts a string map of int64 values into a string map of int64 pointers.

func Int64Slice

func Int64Slice(src []int64) []*int64

Int64Slice converts a slice of int64 values into a slice of int64 pointers.

func Int64Value

func Int64Value(v *int64) int64

Int64Value returns the value of the int64 pointer passed in or 0 if the pointer is nil.

func Int64ValueMap

func Int64ValueMap(src map[string]*int64) map[string]int64

Int64ValueMap converts a string map of int64 pointers into a string map of int64 values.

func Int64ValueSlice

func Int64ValueSlice(src []*int64) []int64

Int64ValueSlice converts a slice of int64 pointers into a slice of int64 values.

func Int8

func Int8(v int8) *int8

Int8 returns a pointer to the int8 value passed in.

func Int8Map

func Int8Map(src map[string]int8) map[string]*int8

Int8Map converts a string map of int8 values into a string map of int8 pointers.

func Int8Slice

func Int8Slice(src []int8) []*int8

Int8Slice converts a slice of int8 values into a slice of int8 pointers.

func Int8Value

func Int8Value(v *int8) int8

Int8Value returns the value of the int8 pointer passed in or 0 if the pointer is nil.

func Int8ValueMap

func Int8ValueMap(src map[string]*int8) map[string]int8

Int8ValueMap converts a string map of int8 pointers into a string map of int8 values.

func Int8ValueSlice

func Int8ValueSlice(src []*int8) []int8

Int8ValueSlice converts a slice of int8 pointers into a slice of int8 values.

func IntMap

func IntMap(src map[string]int) map[string]*int

IntMap converts a string map of int values into a string map of int pointers.

func IntSlice

func IntSlice(src []int) []*int

IntSlice converts a slice of int values into a slice of int pointers.

func IntValue

func IntValue(v *int) int

IntValue returns the value of the int pointer passed in or 0 if the pointer is nil.

func IntValueMap

func IntValueMap(src map[string]*int) map[string]int

IntValueMap converts a string map of int pointers into a string map of int values.

func IntValueSlice

func IntValueSlice(src []*int) []int

IntValueSlice converts a slice of int pointers into a slice of int values.

func MillisecondsTimeValue

func MillisecondsTimeValue(v *int64) time.Time

MillisecondsTimeValue converts an int64 pointer to a time.Time value representing milliseconds sinch Epoch or time.Time{} if the pointer is nil.

func QueryDNSCnameRecord

func QueryDNSCnameRecord(domain string) *dns.CNAME

func QueryDNSSRVRecord

func QueryDNSSRVRecord(domain string) *dns.SRV

func SecondsTimeValue

func SecondsTimeValue(v *int64) time.Time

SecondsTimeValue converts an int64 pointer to a time.Time value representing seconds since Epoch or time.Time{} if the pointer is nil.

func SetFQDN

func SetFQDN(domain string) string

FQDN: A fully qualified domain name.

func String

func String(v string) *string

String returns a pointer to the string value passed in.

func StringMap

func StringMap(src map[string]string) map[string]*string

StringMap converts a string map of string values into a string map of string pointers.

func StringSlice

func StringSlice(src []string) []*string

StringSlice converts a slice of string values into a slice of string pointers.

func StringToBytes

func StringToBytes(s string) []byte

s2b converts string to a byte slice without memory allocation.

Note it may break if string and/or slice header will change in the future go versions.

func StringValue

func StringValue(v *string) string

StringValue returns the value of the string pointer passed in or "" if the pointer is nil.

func StringValueMap

func StringValueMap(src map[string]*string) map[string]string

StringValueMap converts a string map of string pointers into a string map of string values.

func StringValueSlice

func StringValueSlice(src []*string) []string

StringValueSlice converts a slice of string pointers into a slice of string values.

func TemplateGenerateFileFromReader

func TemplateGenerateFileFromReader(reader io.Reader, dstPath string, data interface{}) error

func TemplateGenerateString

func TemplateGenerateString(str string, data interface{}) (string, error)

func Time

func Time(v time.Time) *time.Time

Time returns a pointer to the time.Time value passed in.

func TimeMap

func TimeMap(src map[string]time.Time) map[string]*time.Time

TimeMap converts a string map of time.Time values into a string map of time.Time pointers.

func TimeSlice

func TimeSlice(src []time.Time) []*time.Time

TimeSlice converts a slice of time.Time values into a slice of time.Time pointers.

func TimeUnixMilli

func TimeUnixMilli(t time.Time) int64

TimeUnixMilli returns a Unix timestamp in milliseconds from "January 1, 1970 UTC". The result is undefined if the Unix time cannot be represented by an int64. Which includes calling TimeUnixMilli on a zero Time is undefined.

This utility is useful for service API's such as CloudWatch Logs which require their unix time values to be in milliseconds.

See Go stdlib https://golang.org/pkg/time/#Time.UnixNano for more information.

func TimeValue

func TimeValue(v *time.Time) time.Time

TimeValue returns the value of the time.Time pointer passed in or time.Time{} if the pointer is nil.

func TimeValueMap

func TimeValueMap(src map[string]*time.Time) map[string]time.Time

TimeValueMap converts a string map of time.Time pointers into a string. map of time.Time values.

func TimeValueSlice

func TimeValueSlice(src []*time.Time) []time.Time

TimeValueSlice converts a slice of time.Time pointers into a slice of time.Time values.

func ToDomainWithDot

func ToDomainWithDot(domain string) string

func TrimDomainDot

func TrimDomainDot(domain string) string

func Uint

func Uint(v uint) *uint

Uint returns a pointer to the uint value passed in.

func Uint16

func Uint16(v uint16) *uint16

Uint16 returns a pointer to the uint16 value passed in.

func Uint16Map

func Uint16Map(src map[string]uint16) map[string]*uint16

Uint16Map converts a string map of uint16 values into a string map of uint16 pointers.

func Uint16Slice

func Uint16Slice(src []uint16) []*uint16

Uint16Slice converts a slice of uint16 values into a slice of uint16 pointers.

func Uint16Value

func Uint16Value(v *uint16) uint16

Uint16Value returns the value of the uint16 pointer passed in or 0 if the pointer is nil.

func Uint16ValueMap

func Uint16ValueMap(src map[string]*uint16) map[string]uint16

Uint16ValueMap converts a string map of uint16 pointers into a string map of uint16 values.

func Uint16ValueSlice

func Uint16ValueSlice(src []*uint16) []uint16

Uint16ValueSlice converts a slice of uint16 pointers into a slice of uint16 values.

func Uint32

func Uint32(v uint32) *uint32

Uint32 returns a pointer to the uint32 value passed in.

func Uint32Map

func Uint32Map(src map[string]uint32) map[string]*uint32

Uint32Map converts a string map of uint32 values into a string map of uint32 pointers.

func Uint32Slice

func Uint32Slice(src []uint32) []*uint32

Uint32Slice converts a slice of uint32 values into a slice of uint32 pointers.

func Uint32Value

func Uint32Value(v *uint32) uint32

Uint32Value returns the value of the uint32 pointer passed in or 0 if the pointer is nil.

func Uint32ValueMap

func Uint32ValueMap(src map[string]*uint32) map[string]uint32

Uint32ValueMap converts a string map of uint32 pointers into a string map of uint32 values.

func Uint32ValueSlice

func Uint32ValueSlice(src []*uint32) []uint32

Uint32ValueSlice converts a slice of uint32 pointers into a slice of uint32 values.

func Uint64

func Uint64(v uint64) *uint64

Uint64 returns a pointer to the uint64 value passed in.

func Uint64Map

func Uint64Map(src map[string]uint64) map[string]*uint64

Uint64Map converts a string map of uint64 values into a string map of uint64 pointers.

func Uint64Slice

func Uint64Slice(src []uint64) []*uint64

Uint64Slice converts a slice of uint64 values into a slice of uint64 pointers.

func Uint64Value

func Uint64Value(v *uint64) uint64

Uint64Value returns the value of the uint64 pointer passed in or 0 if the pointer is nil.

func Uint64ValueMap

func Uint64ValueMap(src map[string]*uint64) map[string]uint64

Uint64ValueMap converts a string map of uint64 pointers into a string map of uint64 values.

func Uint64ValueSlice

func Uint64ValueSlice(src []*uint64) []uint64

Uint64ValueSlice converts a slice of uint64 pointers into a slice of uint64 values.

func Uint8

func Uint8(v uint8) *uint8

Uint8 returns a pointer to the uint8 value passed in.

func Uint8Map

func Uint8Map(src map[string]uint8) map[string]*uint8

Uint8Map converts a string map of uint8 values into a string map of uint8 pointers.

func Uint8Slice

func Uint8Slice(src []uint8) []*uint8

Uint8Slice converts a slice of uint8 values into a slice of uint8 pointers.

func Uint8Value

func Uint8Value(v *uint8) uint8

Uint8Value returns the value of the uint8 pointer passed in or 0 if the pointer is nil.

func Uint8ValueMap

func Uint8ValueMap(src map[string]*uint8) map[string]uint8

Uint8ValueMap converts a string map of uint8 pointers into a string map of uint8 values.

func Uint8ValueSlice

func Uint8ValueSlice(src []*uint8) []uint8

Uint8ValueSlice converts a slice of uint8 pointers into a slice of uint8 values.

func UintMap

func UintMap(src map[string]uint) map[string]*uint

UintMap converts a string map of uint values uinto a string map of uint pointers.

func UintSlice

func UintSlice(src []uint) []*uint

UintSlice converts a slice of uint values uinto a slice of uint pointers.

func UintValue

func UintValue(v *uint) uint

UintValue returns the value of the uint pointer passed in or 0 if the pointer is nil.

func UintValueMap

func UintValueMap(src map[string]*uint) map[string]uint

UintValueMap converts a string map of uint pointers uinto a string map of uint values.

func UintValueSlice

func UintValueSlice(src []*uint) []uint

UintValueSlice converts a slice of uint pointers uinto a slice of uint values.

func UnixTimeMilliSecond

func UnixTimeMilliSecond() float64

func WriteFile

func WriteFile(path string, content string) error

Types

type DeployPolicy

type DeployPolicy uint
const (
	DeployPolicyBlue DeployPolicy = iota + 1
	DeployPolicyGreen
	DeployPolicyRed
	DeployPolicyBlack
)

func ToEnv

func ToEnv(sPolicy string) DeployPolicy

type HTTPAirdbResponse

type HTTPAirdbResponse struct {
	Code    uint        `json:"code"`
	Success bool        `json:"success"`
	Data    interface{} `json:"data"`
	Error   interface{} `json:"error,omitempty"`
	Message interface{} `json:"message,omitempty"`
}

type HTTPClient

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

func (*HTTPClient) GetBody

func (client *HTTPClient) GetBody() interface{}

func (*HTTPClient) GetDebug

func (client *HTTPClient) GetDebug() bool

func (*HTTPClient) GetHeaders

func (client *HTTPClient) GetHeaders() map[string]string

func (*HTTPClient) GetMethod

func (client *HTTPClient) GetMethod() string

func (*HTTPClient) GetURL

func (client *HTTPClient) GetURL() string

func (*HTTPClient) GetUserAgent

func (client *HTTPClient) GetUserAgent() string

func (*HTTPClient) GetValues

func (client *HTTPClient) GetValues() url.Values

func (*HTTPClient) SetBody

func (client *HTTPClient) SetBody(body interface{})

func (*HTTPClient) SetDebug

func (client *HTTPClient) SetDebug()

func (*HTTPClient) SetHeaders

func (client *HTTPClient) SetHeaders(headers map[string]string)

func (*HTTPClient) SetMethod

func (client *HTTPClient) SetMethod(method string)

func (*HTTPClient) SetURL

func (client *HTTPClient) SetURL(url string)

func (*HTTPClient) SetUserAgent

func (client *HTTPClient) SetUserAgent(ua string)

func (*HTTPClient) SetValues

func (client *HTTPClient) SetValues(values url.Values)

type ProcessBar

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

func (*ProcessBar) Finish

func (bar *ProcessBar) Finish()

func (*ProcessBar) NewOption

func (bar *ProcessBar) NewOption(start, total int64)

func (*ProcessBar) NewOptionWithGraph

func (bar *ProcessBar) NewOptionWithGraph(start, total int64, graph string)

func (*ProcessBar) Play

func (bar *ProcessBar) Play(cur int64)

type RequestInterface

type RequestInterface interface {
	SetDebug()
	GetDebug() bool

	SetURL(string)
	GetURL() string

	SetMethod(string)
	GetMethod() string

	SetHeaders(headers map[string]string)
	GetHeaders() map[string]string

	SetValues(url.Values)
	GetValues() url.Values

	SetBody(interface{})
	GetBody() interface{}

	SetUserAgent(string)
	GetUserAgent() string
}

type ResponseInterface

type ResponseInterface interface{}

Directories

Path Synopsis
gin

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to