util

package
v8.0.0-...-944e526 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2019 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrWalkSkipDir = errors.New("skip this directory")

ErrWalkSkipDir is the Error returned when we want to skip descending into a directory

Functions

func DecodeBasicAuthHeader

func DecodeBasicAuthHeader(header string) (string, string, error)

DecodeBasicAuthHeader decodes user and password from a basic auth header.

func Decrypt

func Decrypt(payload []byte, secret string) ([]byte, error)

Decrypt decrypts a payload with a given secret.

func EncodeMd5

func EncodeMd5(str string) string

EncodeMd5 encodes a string to md5 hex value.

func EncodePassword

func EncodePassword(password string, salt string) string

EncodePassword encodes a password using PBKDF2.

func Encrypt

func Encrypt(payload []byte, secret string) ([]byte, error)

Encrypt encrypts a payload with a given secret.

func GenerateShortUID

func GenerateShortUID() string

GenerateShortUID generates a short unique identifier.

func GetAgeString

func GetAgeString(t time.Time) string

GetAgeString returns a string representing certain time from years to minutes.

func GetBasicAuthHeader

func GetBasicAuthHeader(user string, password string) string

GetBasicAuthHeader returns a base64 encoded string from user and password.

func GetRandomString

func GetRandomString(n int, alphabets ...byte) string

GetRandomString generate random string by specify chars. source: https://github.com/gogits/gogs/blob/9ee80e3e5426821f03a4e99fad34418f5c736413/modules/base/tool.go#L58

func IsEmail

func IsEmail(str string) bool

IsEmail checks if a string is a valid email address.

func IsValidShortUID

func IsValidShortUID(uid string) bool

IsValidShortUID checks if short unique identifier contains valid characters

func JoinURLFragments

func JoinURLFragments(a, b string) string

JoinURLFragments joins two URL fragments into only one URL string.

func Md5Sum

func Md5Sum(reader io.Reader) (string, error)

Md5Sum calculates the md5sum of a stream

func Md5SumString

func Md5SumString(input string) (string, error)

Md5SumString calculates the md5sum of a string

func PBKDF2

func PBKDF2(password, salt []byte, iter, keyLen int, h func() hash.Hash) []byte

PBKDF2 implements Password-Based Key Derivation Function 2), aimed to reduce the vulnerability of encrypted keys to brute force attacks. http://code.google.com/p/go/source/browse/pbkdf2/pbkdf2.go?repo=crypto

func ParseIPAddress

func ParseIPAddress(input string) string

ParseIPAddress parses an IP address and removes port and/or IPV6 format

func RandomHex

func RandomHex(n int) (string, error)

RandomHex returns a random string from a n seed.

func SplitHostPort

func SplitHostPort(input string) (host string, port string)

SplitHostPort splits ip address/hostname string by host and port

func SplitHostPortDefault

func SplitHostPortDefault(input, defaultHost, defaultPort string) (host string, port string)

SplitHostPortDefault splits ip address/hostname string by host and port. Defaults used if no match found

func SplitString

func SplitString(str string) []string

SplitString splits a string by commas or empty spaces.

func StringsFallback2

func StringsFallback2(val1 string, val2 string) string

StringsFallback2 returns the first of two not empty strings.

func StringsFallback3

func StringsFallback3(val1 string, val2 string, val3 string) string

StringsFallback3 returns the first of three not empty strings.

func Walk

func Walk(path string, followSymlinks bool, detectSymlinkInfiniteLoop bool, walkFn WalkFunc) error

Walk walks a path, optionally following symbolic links, and for each path, it calls the walkFn passed.

It is similar to filepath.Walk, except that it supports symbolic links and can detect infinite loops while following sym links. It solves the issue where your WalkFunc needs a path relative to the symbolic link (resolving links within walkfunc loses the path to the symbolic link for each traversal).

Types

type DynMap

type DynMap map[string]interface{}

DynMap defines a dynamic map interface.

type URLQueryReader

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

URLQueryReader is a URL query type.

func NewURLQueryReader

func NewURLQueryReader(urlInfo *url.URL) (*URLQueryReader, error)

NewURLQueryReader parses a raw query and returns it as a URLQueryReader type.

func (*URLQueryReader) Get

func (r *URLQueryReader) Get(name string, def string) string

Get parse parameters from an URL. If the parameter does not exist, it returns the default value.

type WalkFunc

type WalkFunc func(resolvedPath string, info os.FileInfo, err error) error

WalkFunc is a callback function called for each path as a directory is walked If resolvedPath != "", then we are following symbolic links.

Jump to

Keyboard shortcuts

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