utils

package module
v0.0.15 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2024 License: AGPL-3.0 Imports: 26 Imported by: 0

README

utils

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotVerified data not verified
	ErrNotVerified = errors.New("data not verified")
	// ErrEmailNotVerified email not verified
	ErrEmailNotVerified = errors.New("email not verified")
	// ErrEmailAddressUsed email address used
	ErrEmailAddressUsed = errors.New("email address used")
	// ErrPhoneNotVerified phone not verified
	ErrPhoneNotVerified = errors.New("phone not verified")
	// ErrPhoneNumberUsed phone number used
	ErrPhoneNumberUsed = errors.New("phone number used")
	// ErrInvalid data invalid
	ErrInvalid = errors.New("data invalid")
	// ErrVersionInvalid version invalid
	ErrVersionInvalid = errors.New("version invalid")
	// ErrLengthInvalid invalid length
	ErrLengthInvalid = errors.New("length invalid")
	// ErrFilterInvalid invalid filter
	ErrFilterInvalid = errors.New("filter invalid")
	// ErrOrderByInvalid invalid orderby
	ErrOrderByInvalid = errors.New("orderby invalid")
	// ErrEcPublicKeyInvalid ec public key invalid
	ErrEcPublicKeyInvalid = errors.New("ec public key invalid")
	// ErrPemBlockInvalid pem block invalid
	ErrPemBlockInvalid = errors.New("pem block invalid")
	// ErrCredentialsInvalid login failed, please check your credentials
	ErrCredentialsInvalid = errors.New("login failed, please check your credentials")
)

Functions

func After

func After(d time.Duration) *time.Time

After return *time.Time

func CheckCors added in v0.0.15

func CheckCors(origin string, domain string) bool

CheckCors check cors

func CheckKeys added in v0.0.3

func CheckKeys(userRight int64, val func(key string) int64, keys ...string) bool

CheckKeys rbac check right by keys @param val func(key string) get value by key

func CheckVals added in v0.0.3

func CheckVals(userRight int64, vals ...int64) bool

CheckVal rbac check right by vals

func Cors added in v0.0.15

func Cors(set func(key string, value string), origin string, allow []string)

Cors sets the Cors (Cross-Origin Resource Sharing) related HTTP header information

func CreatePrivateKey added in v0.0.2

func CreatePrivateKey(privateKeyPEM []byte) (*ecdsa.PrivateKey, error)

CreatePrivateKey return *ecdsa.PrivateKey

func CreatePrivateKeyPEM added in v0.0.2

func CreatePrivateKeyPEM() ([]byte, error)

CreatePrivateKeyPEM create private key pem

func CreatePublicKey added in v0.0.2

func CreatePublicKey(publicKeyPEM []byte) (*ecdsa.PublicKey, error)

CreatePublicKey return *ecdsa.PublicKey

func CreatePublicKeyPEM added in v0.0.2

func CreatePublicKeyPEM(privateKey *ecdsa.PrivateKey) ([]byte, error)

CreatePublicKeyPEM create public key pem

func DirExist added in v0.0.2

func DirExist(dir string) bool

DirExist check dir

func FetchFile added in v0.0.13

func FetchFile(url string, dist string) error

FetchFile

func FileExist added in v0.0.2

func FileExist(filename string) bool

FileExist check file

func FileSize added in v0.0.2

func FileSize(size int64) string

FileSize format file size

func HomeDir added in v0.0.2

func HomeDir(path string) (string, error)

HomeDir join path with app home dir

func Int added in v0.0.5

func Int(name string, val int) error

Int validate name

func IsBool added in v0.0.2

func IsBool(attributeType string) bool

IsBool if attribute type is Numeric return true, else false

func IsInt added in v0.0.2

func IsInt(goType string) bool

IsInt when goType is: int int8 int16 int32 int64 return true

func IsNumeric added in v0.0.2

func IsNumeric(attributeType string) bool

Numeric if attribute type is Numeric return true, else false

func MakeCamel added in v0.0.2

func MakeCamel(val string) string

MakeCamel converts the given val to camel case like: user_key to userKey

func MakeCapitalize added in v0.0.2

func MakeCapitalize(str string) string

MakeCapitalize change first character to upper

func MakeKebab added in v0.0.2

func MakeKebab(val string) string

MakeKebab converts the given val to kebab case like: UserKey to user-key

func MakePlural added in v0.0.2

func MakePlural(name string) string

MakePlural convert word to plural

func MakeSafeString added in v0.0.2

func MakeSafeString(val string) string

MakeSafeString make string safe for sql

func MakeSingle added in v0.0.2

func MakeSingle(name string) string

MakeSingle convert word to single

func MakeSnake added in v0.0.2

func MakeSnake(val string) string

MakeSnake converts the given val to snake case like: UserKey,userKey to user_key

func MakeStudly added in v0.0.2

func MakeStudly(val string) string

MakeStudly converts the given val to studly case like: user_key, userKey to UserKey

func MakeTitle added in v0.0.2

func MakeTitle(val string) string

MakeTitle converts the given val to title case like: UserKey,userKey to user_key

func MakeUrl added in v0.0.2

func MakeUrl(val string) string

MakeUrl converts the given val to url like: UserKey to user/key

func MatchAlphabet added in v0.0.2

func MatchAlphabet(val string) bool

MatchAlphabet check alphabet

func MatchDomain added in v0.0.2

func MatchDomain(val string) bool

MatchDomain check domain

func MatchEmail added in v0.0.2

func MatchEmail(val string) bool

MatchEmail check email

func MatchPhone added in v0.0.2

func MatchPhone(val string) bool

MatchPhone check phone

func MySQLSplit added in v0.0.2

func MySQLSplit(data []byte, atEOF bool) (advance int, token []byte, err error)

MySQLSplit split function for the Scanner

func Now

func Now() *time.Time

Now return *time.Time

func OpenBrowser added in v0.0.12

func OpenBrowser(url string) error

OpenBrowser attempts to open the specified URL in the default browser of the user.

func RString added in v0.0.5

func RString(name string, val *string) error

RString validate name

func RandString added in v0.0.8

func RandString(l int) (string, error)

RandString random string

func RandomString

func RandomString(l int) (string, error)

RandomString random string with [a-zA-Z0-9]

func RandomStringWithCharset added in v0.0.7

func RandomStringWithCharset(l int, characters string) (string, error)

RandStringWithCharset rand string

func ReadJSON added in v0.0.2

func ReadJSON(filename string, v interface{}) error

ReadJSON read json to data

func ReleaseLexer added in v0.0.15

func ReleaseLexer(lexer *Lexer)

func SqlFilter

func SqlFilter(filter string, w io.Writer, args *[]any, prefix string, fn func(key string, val string) (string, interface{}, error)) error

SqlFilter create sql for filter and args

func SqlOrderBy

func SqlOrderBy(orderBy string, w io.Writer, prefix string, fn func(variableName string) (string, string, string, error)) error

SqlOrderBy create sql for order by

func String added in v0.0.5

func String(name string, val string) error

String validate name

func TarFile added in v0.0.2

func TarFile(src string) (string, error)

TarFile compress file with gzip

func TryFetchFile added in v0.0.13

func TryFetchFile(url string, dist string, retry int) error

TryFetchFile

func TryParse added in v0.0.2

func TryParse(val string, attributeType string) (interface{}, error)

func Uint64 added in v0.0.5

func Uint64(name string, val uint64) error

Uint64 validate name

func ValidateDomain added in v0.0.2

func ValidateDomain(domain ...string) error

ValidateDomain validate domain

func ValidateEmail added in v0.0.2

func ValidateEmail(email ...string) error

ValidateEmail validate email

func ValidateName added in v0.0.2

func ValidateName(name ...string) error

ValidateName validate name

func ValidatePhone added in v0.0.2

func ValidatePhone(phone ...string) error

ValidatePhone validate phone number

func Where added in v0.0.2

func Where(where string, fn func(key string, op string, val string))

Where parse where

func WriteJSON added in v0.0.2

func WriteJSON(filename string, v interface{}, overwrite bool) error

WriteJSON write data to json

func ZipFile added in v0.0.4

func ZipFile(src string) (string, error)

ZipFile compress file with zip

Types

type Lexer added in v0.0.15

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

func CreateLexer added in v0.0.15

func CreateLexer(data []byte) *Lexer

func (*Lexer) Advance added in v0.0.15

func (l *Lexer) Advance()

func (*Lexer) Expect added in v0.0.15

func (l *Lexer) Expect(c byte) error

func (*Lexer) Peek added in v0.0.15

func (l *Lexer) Peek() byte

func (*Lexer) ReadBool added in v0.0.15

func (l *Lexer) ReadBool() (bool, error)

func (*Lexer) ReadFloatArray added in v0.0.15

func (l *Lexer) ReadFloatArray() ([]float64, error)

func (*Lexer) ReadInt added in v0.0.15

func (l *Lexer) ReadInt() (int, error)

func (*Lexer) ReadString added in v0.0.15

func (l *Lexer) ReadString() (string, error)

func (*Lexer) SkipValue added in v0.0.15

func (l *Lexer) SkipValue() error

func (*Lexer) SkipWhitespace added in v0.0.15

func (l *Lexer) SkipWhitespace()

Jump to

Keyboard shortcuts

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