utils

package
v1.8.6 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2019 License: Apache-2.0 Imports: 19 Imported by: 76

Documentation

Index

Constants

View Source
const (
	// EncryptHeaderV1 ...
	EncryptHeaderV1 = "<enc-v1>"
)

Variables

View Source
var RepoRegexp = regexp.MustCompile(fmt.Sprintf("^%s(/%s)*$", nameComponent, nameComponent))

RepoRegexp is regular expression to match repo name, for example, 'busybox', 'stage/busybox'

View Source
var TagRegexp = regexp.MustCompile(`^[\w][\w.-]{0,127}$`)

TagRegexp is regular expression to match image tags, for example, 'v1.0'

Functions

func ConvertMapToStruct

func ConvertMapToStruct(object interface{}, values interface{}) error

ConvertMapToStruct is used to fill the specified struct with map.

func Encrypt

func Encrypt(content string, salt string) string

Encrypt encrypts the content with salt

func GenerateRandomString

func GenerateRandomString() string

GenerateRandomString generates a random string

func GetStrValueOfAnyType added in v1.8.0

func GetStrValueOfAnyType(value interface{}) string

GetStrValueOfAnyType return string format of any value, for map, need to convert to json

func IsContainIllegalChar added in v1.8.0

func IsContainIllegalChar(s string, illegalChar []string) bool

IsContainIllegalChar ...

func IsIllegalLength added in v1.8.0

func IsIllegalLength(s string, min int, max int) bool

IsIllegalLength ...

func ParseEndpoint

func ParseEndpoint(endpoint string) (*url.URL, error)

ParseEndpoint parses endpoint to a URL

func ParseOfftime added in v1.6.0

func ParseOfftime(offtime int64) (hour, minite, second int)

ParseOfftime ...

func ParseProjectIDOrName

func ParseProjectIDOrName(value interface{}) (int64, string, error)

ParseProjectIDOrName parses value to ID(int64) or name(string)

func ParseRepository

func ParseRepository(repository string) (project, rest string)

ParseRepository splits a repository into two parts: project and rest

func ParseTimeStamp

func ParseTimeStamp(timestamp string) (*time.Time, error)

ParseTimeStamp parse timestamp to time

func ReversibleDecrypt

func ReversibleDecrypt(str, key string) (string, error)

ReversibleDecrypt decrypts the str with aes/base64 or base 64 depending on "header"

func ReversibleEncrypt

func ReversibleEncrypt(str, key string) (string, error)

ReversibleEncrypt encrypts the str with aes/base64

func SafeCastBool added in v1.5.2

func SafeCastBool(value interface{}) bool

SafeCastBool --

func SafeCastFloat64 added in v1.5.2

func SafeCastFloat64(value interface{}) float64

SafeCastFloat64 --

func SafeCastInt added in v1.5.2

func SafeCastInt(value interface{}) int

SafeCastInt --

func SafeCastString added in v1.5.2

func SafeCastString(value interface{}) string

SafeCastString -- cast a object to string saftely

func TestTCPConn

func TestTCPConn(addr string, timeout, interval int) error

TestTCPConn tests TCP connection timeout: the total time before returning if something is wrong with the connection, in second interval: the interval time for retring after failure, in second

func TrimLower added in v1.6.0

func TrimLower(str string) string

TrimLower ...

func ValidateRepo added in v1.7.1

func ValidateRepo(repo string) bool

ValidateRepo validates whether a repo name is valid.

func ValidateTag added in v1.7.1

func ValidateTag(tag string) bool

ValidateTag validates whether a tag is valid.

Types

type Link struct {
	// URL : url part of header
	URL string
	// Rel : prev or next
	Rel string
}

Link : HTTP link header

type Links []*Link

Links : multiple link

func ParseLink(raw string) Links

ParseLink parses the raw link header to Links

func (Links) Next

func (l Links) Next() string

Next returns the URL indicated by "next" rel.

func (Links) Prev

func (l Links) Prev() string

Prev returns the URL indicated by "prev" rel.

type TimeMarker

type TimeMarker struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

TimeMarker is used to control an action not to be taken frequently within the interval

func ScanOverviewMarker

func ScanOverviewMarker() *TimeMarker

ScanOverviewMarker ...

func (*TimeMarker) Check

func (t *TimeMarker) Check() bool

Check returns true if the current time is after the mark by this marker, and the caction the mark guards and be taken.

func (*TimeMarker) Mark

func (t *TimeMarker) Mark()

Mark tries to mark a future time, which is after the duration of interval from the time it's called.

func (*TimeMarker) Next

func (t *TimeMarker) Next() time.Time

Next returns the time of the next mark.

Directories

Path Synopsis
uaa

Jump to

Keyboard shortcuts

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