util

package
v1.0.14 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2019 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package util implements a set of util functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Base64Encode

func Base64Encode(data []byte) string

Base64Encode gets base64 encoded string from data.

func CheckFileExists

func CheckFileExists(filename string) bool

CheckFileExists checks if specified file exists.

func Contains

func Contains(slice []string, value string, caseInsensitive bool) bool

Contains determines whether a string slice contains a certain value. Ignore case when comparing if case insensitive.

func CreateRandomString

func CreateRandomString() string

CreateRandomString create random string

func Debug

func Debug(title, message string)

Debug generates debug info for debug mode.

func FormatTest

func FormatTest(funcName, got, expected string) string

FormatTest returns a formatted string for unit test.

func GetMD5

func GetMD5(data interface{}, base64Encode bool) string

GetMD5 gets the MD5 value from data. Param base64Encode determines whether use Base64Encode meanwhile.

func GetMapKey

func GetMapKey(m map[string]string, key string, caseInsensitive bool) string

GetMapKey returns the key of the map for a certain value. Ignore case when comparing if case insensitive.

func GetMapValue

func GetMapValue(m map[string]string, key string, caseInsensitive bool) string

GetMapValue returns the value of the map for a certain key. Ignore case when comparing if case insensitive.

func GetSha256

func GetSha256(data interface{}) string

GetSha256 gets SHA256 value from data.

func GetURIPath

func GetURIPath(uri string) string

GetURIPath returns the path part of URI.

func GetURL

func GetURL(protocol, host, uriPath string, params map[string]string) string

GetURL gets the full URL for a http request.

func GuessMimeType

func GuessMimeType(s string) string

GuessMimeType gets the MIME Type of a suffix string.

func HmacSha256Hex

func HmacSha256Hex(key, message string) string

HmacSha256Hex returns a encrypted string.

func HomeDir

func HomeDir() (string, error)

HomeDir returns the HOME directory of current login user.

func HostToURL

func HostToURL(host, protocol string) string

HostToURL returns the whole URL string.

func MapContains

func MapContains(m map[string]string, compareFunc func(string, string) bool) bool

MapContains determines whether the string map contains a uncertain value. The result is determined by compare function.

func MapKeyToLower

func MapKeyToLower(m map[string]string)

MapKeyToLower transforms each item of a map to lowercase.

func SliceToLower

func SliceToLower(slice []string)

SliceToLower transforms each item of a slice to lowercase.

func TempFile

func TempFile(content []byte, dir, prefix string) (*os.File, error)

TempFile generates a temp file with separated content.

func TempFileWithSize

func TempFileWithSize(fileSize int64) (*os.File, error)

TempFileWithSize generates a temp file with specified size.

func TimeStringToRFC1123

func TimeStringToRFC1123(str string) string

TimeStringToRFC1123 returns a formatted string of `time.RFC1123` format.

func TimeToUTCString

func TimeToUTCString(t time.Time) string

TimeToUTCString returns a utc string of a time instance.

func ToCanonicalHeaderString

func ToCanonicalHeaderString(headerMap map[string]string) string

ToCanonicalHeaderString returns the canonicalized string.

func ToCanonicalQueryString

func ToCanonicalQueryString(params map[string]string) string

ToCanonicalQueryString returns the canonicalized query string.

func ToJson

func ToJson(i interface{}, keys ...string) ([]byte, error)

ToJson converts anything to JSON.

func ToMap

func ToMap(i interface{}, keys ...string) (map[string]interface{}, error)

ToMap converts anything to a map instance.

func URIEncodeExceptSlash

func URIEncodeExceptSlash(uri string) string

URIEncodeExceptSlash encodes all characters of a string except the slash character.

func URLEncode

func URLEncode(str string) string

URLEncode encodes a string like Javascript's encodeURIComponent()

Types

This section is empty.

Notes

Bugs

Jump to

Keyboard shortcuts

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