utils

package module
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2020 License: MIT Imports: 14 Imported by: 12

README

go-utils

Utility function for go

Documentation

Index

Constants

View Source
const (
	// BigPicture :nodoc:
	BigPicture = "big_picture"
	// LargeIcon :nodoc:
	LargeIcon = "large_icon"
	// IOSAttachment :nodoc:
	IOSAttachment = "ios_attahcment"
)

Variables

This section is empty.

Functions

func ArrayStringPointerToArrayInt64

func ArrayStringPointerToArrayInt64(s *[]*string) []int64

ArrayStringPointerToArrayInt64 :nodoc:

func BoolPointerToBool

func BoolPointerToBool(b *bool) bool

BoolPointerToBool :nodoc:

func BoolToString

func BoolToString(b bool) string

BoolToString :nodoc:

func ContainsInt64

func ContainsInt64(a []int64, x int64) bool

ContainsInt64 tells whether a slice contains x.

func ContainsString

func ContainsString(a []string, x string) bool

ContainsString tells whether a slice contains x.

func DifferenceInt64

func DifferenceInt64(slice1 []int64, slice2 []int64) []int64

DifferenceInt64 :nodoc:

func DifferenceString

func DifferenceString(slice1 []string, slice2 []string) []string

DifferenceString :nodoc:

func Dump

func Dump(i interface{}) string

Dump to json using json marshal

func DumpIncomingContext

func DumpIncomingContext(c context.Context) string

DumpIncomingContext :nodoc:

func DumpOutGoingContext

func DumpOutGoingContext(c context.Context) string

DumpOutGoingContext :nodoc:

func Float64PointerToFloat64

func Float64PointerToFloat64(f *float64) float64

Float64PointerToFloat64 :nodoc:

func FormatTimeRFC3339

func FormatTimeRFC3339(t *time.Time) (s string)

FormatTimeRFC3339 Format time according to RFC3339Nano

func GenerateID

func GenerateID() int64

GenerateID based on current time

func GeneratePushNotificationMediaURL added in v1.1.0

func GeneratePushNotificationMediaURL(cdnURL, mediaSrcURL, imageType string) string

GeneratePushNotificationMediaURL Generates manipulated media URL for push notification purpose e.g. GeneratePushNotificationMediaURL("http://mycdn.com", "http://my.image.com/image/upload/v123/image.jpg", LargeIcon) => http://mycdn.com/image/upload/v123/image.jpg

func GenerateRandomAlphanumeric added in v1.4.0

func GenerateRandomAlphanumeric(n int) string

GenerateRandomAlphanumeric Generate random alphanumeric character adapted from https://stackoverflow.com/questions/22892120/how-to-generate-a-random-string-of-a-fixed-length-in-go

func GenerateRandomBytes

func GenerateRandomBytes(n int) ([]byte, error)

GenerateRandomBytes adapted from https://elithrar.github.io/article/generating-secure-random-numbers-crypto-rand/ GenerateRandomBytes returns securely generated random bytes. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.

func GenerateRandomString

func GenerateRandomString(n int) (string, error)

GenerateRandomString returns a securely generated random string. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.

func GenerateRandomStringURLSafe

func GenerateRandomStringURLSafe(n int) (string, error)

GenerateRandomStringURLSafe returns a URL-safe, base64 encoded securely generated random string. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.

func GetIDFromSlug added in v1.6.0

func GetIDFromSlug(slug string) string

GetIDFromSlug in base62

func GraphQLIDPointerToInt32

func GraphQLIDPointerToInt32(id *graphql.ID) int32

GraphQLIDPointerToInt32 :nodoc:

func GraphQLIDPointerToInt64

func GraphQLIDPointerToInt64(id *graphql.ID) int64

GraphQLIDPointerToInt64 :nodoc:

func GraphQLIDPointerToString

func GraphQLIDPointerToString(id *graphql.ID) string

GraphQLIDPointerToString :nodoc:

func GraphQLIDToInt32

func GraphQLIDToInt32(id graphql.ID) int32

GraphQLIDToInt32 :nodoc:

func GraphQLIDToInt64

func GraphQLIDToInt64(id graphql.ID) int64

GraphQLIDToInt64 :nodoc:

func GraphQLIDToString

func GraphQLIDToString(id graphql.ID) string

GraphQLIDToString :nodoc:

func Int32PointerToInt32

func Int32PointerToInt32(i *int32) int32

Int32PointerToInt32 :nodoc:

func Int32PointerToInt64

func Int32PointerToInt64(i *int32) int64

Int32PointerToInt64 :nodoc:

func Int64ToGraphQLID

func Int64ToGraphQLID(i int64) graphql.ID

Int64ToGraphQLID :nodoc:

func Int64ToString

func Int64ToString(i int64) string

Int64ToString :nodoc:

func Int64WithLimit

func Int64WithLimit(input int64, limit int64) int64

Int64WithLimit -> Check req value bigger or not from limit.

func InterfaceBytesToInt64

func InterfaceBytesToInt64(i interface{}) int64

InterfaceBytesToInt64 will transform cached value that get from the redis to Int64

func IsEmailValid

func IsEmailValid(email string) bool

IsEmailValid -> validate email using regex

func IsNumeric

func IsNumeric(s string) bool

IsNumeric -> Check if input string is int

func IsSameSliceIgnoreOrder

func IsSameSliceIgnoreOrder(a, b []int64) bool

IsSameSliceIgnoreOrder to compare slice without order

func JoinURL

func JoinURL(baseURL string, pathElements ...string) (string, error)

JoinURL joins URL with the path elements

func LowerMapStringKey added in v1.3.0

func LowerMapStringKey(v map[string]interface{}) map[string]interface{}

func MyCaller added in v1.2.0

func MyCaller(skip int) string

MyCaller will return the method caller. skip value defines how many steps to be skipped. skip=0 will always return the MyCaller skip=1 returns the caller of the MyCaller and so on...

func Offset

func Offset(page, limit int64) int64

Offset to get offset from page and limit, min value for page = 1

func RegexEmail

func RegexEmail() *regexp.Regexp

RegexEmail returns regex for email

func Retry

func Retry(attempts int, sleep time.Duration, fn func() error) error

Retry :nodoc:

func SliceAtoi

func SliceAtoi(s []string) ([]int, error)

SliceAtoi -> convert array of string to array of integer

func SlicePointerInt32PointerToSliceInt64

func SlicePointerInt32PointerToSliceInt64(i *[]*int32) (result []int64)

SlicePointerInt32PointerToSliceInt64 :nodoc:

func StandardizeSpaces

func StandardizeSpaces(s string) string

StandardizeSpaces -> JoinURL long query to one line query

func StringPointerToFloat64

func StringPointerToFloat64(s *string) float64

StringPointerToFloat64 :nodoc:

func StringPointerToInt64

func StringPointerToInt64(s *string) int64

StringPointerToInt64 :nodoc:

func StringPointerToString

func StringPointerToString(s *string) string

StringPointerToString :nodoc:

func StringToBool

func StringToBool(s string) bool

StringToBool :nodoc:

func StringToInt64

func StringToInt64(s string) int64

StringToInt64 :nodoc:

func StringToInt64WithDefault

func StringToInt64WithDefault(s string, d int64) int64

StringToInt64WithDefault :nodoc:

func Ternary

func Ternary(condition bool, a, b interface{}) interface{}

Ternary if condition is true, return a else b

func ToByte

func ToByte(i interface{}) []byte

ToByte :nodoc:

func UnescapeString

func UnescapeString(str string) (ustr string)

UnescapeString UTF-8 string e.g. convert "\u0e27\u0e23\u0e0d\u0e32" to "วรญา"

func UniqueInt64

func UniqueInt64(elements []int64) []int64

UniqueInt64 :nodoc:

func UniqueString

func UniqueString(elements []string) []string

UniqueString :nodoc:

Types

type RetryStopper

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

RetryStopper :nodoc:

func NewRetryStopper added in v1.3.1

func NewRetryStopper(err error) RetryStopper

NewRetryStopper :nodoc:

Jump to

Keyboard shortcuts

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