Documentation ¶
Overview ¶
Package util provides a variety of handy functions while developing backends
Index ¶
- Constants
- func ADtoROC(adStr, format string) (TW_Date string, err error)
- func CheckParam(param map[string]interface{}, target map[string][]string) (bool, map[string]string)
- func CheckRequiredAndParam(param map[string]interface{}, requireFields []string, ...) (bool, map[string]string)
- func CheckStruct(s interface{}) (bool, error)
- func CheckTimeFormat(tim string) error
- func CreatePrivateKeyPem(filePath string, priv *rsa.PrivateKey) error
- func DecodeMap(ecodeMapStr string) (*map[string]interface{}, error)
- func DecodePublicKey(base64Key string) (*rsa.PublicKey, error)
- func DecodeString(encodeStr string, privateKey *rsa.PrivateKey) (*bytes.Buffer, error)
- func DecodeToken(token string) map[string]interface{}
- func DecodeTokenByKey(req *http.Request, key string) map[string]interface{}
- func EncodeMap(dataMap *map[string]interface{}) (string, error)
- func EncodePublicKey(publicKey crypto.PublicKey) (*bytes.Buffer, error)
- func EncodePublicKeyPem(publicKey crypto.PublicKey) (*bytes.Buffer, error)
- func EncodeString(str string, publicKey *rsa.PublicKey) (*bytes.Buffer, error)
- func FileExists(filename string) bool
- func GetClientInfo(req *http.Request) map[string]interface{}
- func GetClientKey(req *http.Request) string
- func GetCtxVal(req *http.Request, ck CtxKey) interface{}
- func GetFirstDayOfMonth() time.Time
- func GetFloat64(v interface{}) float64
- func GetFloat64WithDP(v interface{}, dp int) float64
- func GetFullUrlStr(req *http.Request) string
- func GetHost(req *http.Request) string
- func GetMutiFormPostValue(req *http.Request, fileKeys []string, valueKeys []string) (map[string]RequestFile, map[string]interface{}, error)
- func GetPathVars(req *http.Request, keys []string) map[string]interface{}
- func GetPostValue(req *http.Request, defaultEmpty bool, keys []string) (map[string]interface{}, error)
- func GetQueryValue(req *http.Request, keys []string, defaultEmpty bool) map[string]interface{}
- func GetUTCTime(t time.Time) float64
- func InitValidator()
- func IntToFixStrLen(val int, length int) (string, error)
- func IsAlpha(str string) bool
- func IsBool(str string) (bool, error)
- func IsFloat64(param string, bound []float64) (float64, error)
- func IsHomeNum(number string) bool
- func IsIdNumber(id string) bool
- func IsInt(param string, bound []int) (int, error)
- func IsLegalPhoneNumber(num string) (bool, error)
- func IsLogin(req *http.Request) bool
- func IsMAC(mac string) bool
- func IsMail(param string) (bool, error)
- func IsMobileNum(number string) bool
- func IsStrInList(input string, target ...string) bool
- func IsVATnumber(num string) bool
- func IsValidPwd(str string) (bool, error)
- func JoinStrWithQuotation(separateSymbol string, quotation string, strs ...string) string
- func ListContextValue(ctx interface{}, inner bool)
- func MD5(str string) string
- func MD5Byte(data []byte) string
- func ParserDataRequest(req *http.Request, data interface{}) error
- func ReadPrivateKeyPem(filePath string) (*rsa.PrivateKey, error)
- func RemoveScriptTag(htmlStr string) (string, error)
- func ReturnExist(ori interface{}, new interface{}) interface{}
- func SHA1(str string) string
- func SetCtxKeyVal(r *http.Request, ck CtxKey, val interface{}) *http.Request
- func StrAppend(strs ...string) string
- func ToStrAry(input interface{}) []string
- type CtxKey
- type Pagination
- type PaginationSource
- type RequestFile
- Bugs
Constants ¶
const ( SymbolComma = "," SymbolSingleQuotation = "'" )
const (
MaxLimit = 300
)
Variables ¶
This section is empty.
Functions ¶
func CheckParam ¶
CheckParam can help to verify if the input is valid or not.
Input:
s : input map for validation. target : A map indicates that what validation should be applied to the input.
Output:
bool : Return true if valid, otherwise a false is returned. error : the output of the detail of the error.
func CheckRequiredAndParam ¶
func CheckStruct ¶
CheckStruct can help to verify the content of the struct with tags. It accepts recursive structs.
Remember to Add valid:"[tags]" to the struct.
func CheckTimeFormat ¶
CheckTimeFormat is use to check if the string is correct time format or not
func CreatePrivateKeyPem ¶
func CreatePrivateKeyPem(filePath string, priv *rsa.PrivateKey) error
func DecodeString ¶
func DecodeToken ¶
func EncodePublicKeyPem ¶
func FileExists ¶
func GetClientInfo ¶
func GetClientKey ¶
func GetFirstDayOfMonth ¶
func GetFloat64 ¶ added in v0.8.9
func GetFloat64(v interface{}) float64
func GetFloat64WithDP ¶ added in v0.8.9
指定小數點位數
func GetFullUrlStr ¶
func GetMutiFormPostValue ¶
func GetPostValue ¶
func GetQueryValue ¶
func GetUTCTime ¶ added in v0.8.8
func InitValidator ¶
func InitValidator()
InitValidator is used to initialize the validator. Call this funtion before using any validator.
func IsFloat64 ¶
IsFloat64 can help to verify if the input is Float64 and the value is within the range or not.
If the bound array is not 2, it will skip the ranging test
func IsInt ¶
IsInt can help to verify if the input is Int and the value is within the range or not.
If the bound array is not 2, it will skip the ranging test
func IsLegalPhoneNumber ¶ added in v0.6.7
func IsMobileNum ¶
func IsStrInList ¶
IsStrInList can help to see if input is one of the target or not. a non-empty error will be returned if input does match any of the target.
func IsValidPwd ¶
func JoinStrWithQuotation ¶
func ListContextValue ¶ added in v1.0.0
func ListContextValue(ctx interface{}, inner bool)
func ParserDataRequest ¶ added in v0.17.0
func ReadPrivateKeyPem ¶
func ReadPrivateKeyPem(filePath string) (*rsa.PrivateKey, error)
func RemoveScriptTag ¶
func ReturnExist ¶
func ReturnExist(ori interface{}, new interface{}) interface{}
ReturnExist will return new if new is not empty else return original
Types ¶
type Pagination ¶
type Pagination interface { Output(w io.Writer) error GetRows() interface{} GetAllPages() int64 GetPage() int64 }
func NewPagination ¶
func NewPagination( source PaginationSource, limit, page int64, format func(i interface{}) map[string]interface{}, ) (Pagination, error)
type PaginationSource ¶
type RequestFile ¶
type RequestFile struct { ReqFile multipart.File ReqHeader *multipart.FileHeader }
Notes ¶
Bugs ¶
haha