Documentation ¶
Index ¶
- Constants
- Variables
- func AddrI64(host string, port int64) string
- func AddrToHostPort(addr string) (string, int64, bool)
- func CamelStr(s string) string
- func CamelStrs(changeStrs []string) []string
- func CheckAndCreateDir(dir string) error
- func ConvertAssign(bytes sql.RawBytes, typ *sql.ColumnType) (interface{}, error)
- func CopyStruct(src, dst interface{})
- func Decrypt(crypted string) (string, error)
- func DeduplicationStrs(strs []string) []string
- func Encrypt(origData string) (string, error)
- func ErrorsToError(errs ...error) error
- func FileAbs(fileName string) (string, error)
- func FileDir(fileName string) string
- func FileInfo(filePath string) (os.FileInfo, error)
- func FileLineCount(name string) (int64, error)
- func Filename(path string) string
- func ForwardRequest(c *gin.Context, targetUrl string, timeout int64)
- func GenerateHashByString(_value string) int
- func GetExistsStrs(from []string, to []string) []string
- func GetExistsStrsPrefix(from []string, to []string, toPrefix string) []string
- func GetInterfaceFieldValue(v interface{}, fieldName string) (interface{}, error)
- func GetRandStr(strs []string) string
- func GetSignKey() string
- func GetStructFieldNames(v interface{}) ([]string, error)
- func GetStructFieldNamesWithPrefix(v interface{}, prefix string) ([]string, error)
- func GetSuffix(str string, suffixSep string) string
- func GetURLRaw(url, query string, hearders map[string]string) ([]byte, error)
- func HasPrefixAll(strs []string, prefix string) bool
- func Hostname() (string, error)
- func InterfaceToStruct(i interface{}, mode interface{}) (interface{}, error)
- func InterfaceToUrlQuery(data interface{}, ignoreEmpty bool) (string, error)
- func IsNil(i interface{}) bool
- func MakeDirAll(dir string) error
- func ObjToMap(data interface{}) (map[string]interface{}, error)
- func PKCS5Padding(ciphertext []byte, blockSize int) []byte
- func PKCS5UnPadding(origData []byte) []byte
- func PathExists(p string) (bool, error)
- func PostURLRaw(url string, data interface{}, hearders map[string]string, timeout int64) ([]byte, error)
- func PostURLRaw2xx(url string, data interface{}, hearders map[string]string) ([]byte, error)
- func PostUploadRaw(url string, filename string, hearders map[string]string) ([]byte, error)
- func RandN(n int) int
- func RandNInt64(n int64) int64
- func RandString(n int) string
- func ReadBinaryFile(filename string) ([]byte, error)
- func ReflectSetNotDefaultFieldValue(prefix string, baseObj, modifyObj interface{}) error
- func RemoveFile(filePath string) error
- func ReplaceAllStrs(oldStrs []string, old string, new string) []string
- func ReturnError(c *gin.Context, code int, err error)
- func ReturnFile(c *gin.Context, fileName string, path string)
- func ReturnList(c *gin.Context, obj interface{}, total int)
- func ReturnListError(c *gin.Context, code int, err error)
- func ReturnSuccess(c *gin.Context, obj interface{})
- func SetInterfaceFieldValue(v interface{}, fieldName string, fieldValue interface{}) error
- func SetObjFieldFromOtherObj(fieldName string, fromObj interface{}, toObj interface{}) error
- func SetObjFieldsFromOtherObj(fieldNames []string, fromObj interface{}, toObj interface{}) error
- func SetSignKey(key string) string
- func SnakeStr(s string) string
- func SnakeStrs(changeStrs []string) []string
- func SplitStringAndFilterEmpty(data string, sep string) []string
- func SqlConvertStrToNormalDateStr(ori string, scale int64) (string, error)
- func SqlConvertStrToNormalDatetimeStr(ori string, scale int64) (string, error)
- func SqlConvertStrToNormalTimeStr(ori string, scale int64) (string, error)
- func StrToInt64(data string) (int64, error)
- func StrToTime(formatStr, timeStr string, zone *time.Location) (time.Time, error)
- func StrsToInt64s(datas []string) ([]int64, error)
- func StrsToMap(strs []string) map[string]struct{}
- func StrsToUnique(strs []string) []string
- func SuffixIsNumAll(strs []string, suffixSep string) bool
- func ToJsonStr(data interface{}) string
- func ToJsonStrPretty(data interface{}) string
- func WriteDataToFile(filePath string, data []byte) (int, error)
- func WriteStringsToFile(datas []string, filename string) error
- func ZipCompress(filePath, dest string) error
- type CustomClaims
- type JWT
Constants ¶
View Source
const ( // 2023-07-19T14:44:45.439291+08:00 DatetimeFormat = "2006-01-02 15:04:05" DatetimeFormat1 = "2006-01-02 15:04:05.0" DatetimeFormat2 = "2006-01-02 15:04:05.00" DatetimeFormat3 = "2006-01-02 15:04:05.000" DatetimeFormat4 = "2006-01-02 15:04:05.0000" DatetimeFormat5 = "2006-01-02 15:04:05.00000" DatetimeFormat6 = "2006-01-02 15:04:05.000000" NationalDatetimeFormat = "2006-01-02T15:04:05Z07:00" NationalDatetimeFormat1 = "2006-01-02T15:04:05.0Z07:00" NationalDatetimeFormat2 = "2006-01-02T15:04:05.00Z07:00" NationalDatetimeFormat3 = "2006-01-02T15:04:05.000Z07:00" NationalDatetimeFormat4 = "2006-01-02T15:04:05.0000Z07:00" NationalDatetimeFormat5 = "2006-01-02T15:04:05.00000Z07:00" NationalDatetimeFormat6 = "2006-01-02T15:04:05.000000Z07:00" DateFormat = "2006-01-02" TimeFormat = "15:04:05" TimeFormat1 = "15:04:05.0" TimeFormat2 = "15:04:05.00" TimeFormat3 = "15:04:05.000" TimeFormat4 = "15:04:05.0000" TimeFormat5 = "15:04:05.00000" TimeFormat6 = "15:04:05.000000" )
View Source
const ( ResponseCodeOk = 100000 ResponseCodeTokenErr = 300000 ResponseCodeErr = 500000 )
View Source
const (
DefaultTimeout = 30
)
View Source
const (
JS_SAFE_MAX_INT = 9007199254740992
)
Variables ¶
View Source
var ( TokenExpired error = errors.New("Token 过期") TokenNotValidYet error = errors.New("Token 没有激活") TokenMalformed error = errors.New("Token 格式不正确") TokenInvalid error = errors.New("Token 无效") TokenNotFound error = errors.New("Token 获取不到") SignKey string = "easydb_api_20211105" )
一些常量
Functions ¶
func AddrToHostPort ¶
获取host port, 是否是host port
func ConvertAssign ¶
func ConvertAssign(bytes sql.RawBytes, typ *sql.ColumnType) (interface{}, error)
func CopyStruct ¶
func CopyStruct(src, dst interface{})
func DeduplicationStrs ¶
func ErrorsToError ¶
func FileLineCount ¶
func GetExistsStrs ¶
func GetExistsStrsPrefix ¶
func GetInterfaceFieldValue ¶
func GetStructFieldNames ¶
func HasPrefixAll ¶
func InterfaceToStruct ¶
func InterfaceToStruct(i interface{}, mode interface{}) (interface{}, error)
func InterfaceToUrlQuery ¶
func MakeDirAll ¶
func PKCS5Padding ¶
func PKCS5UnPadding ¶
func PostURLRaw ¶
func PostURLRaw(url string, data interface{}, hearders map[string]string, timeout int64) ([]byte, error)
Post请求
func PostURLRaw2xx ¶
func PostUploadRaw ¶
func RandNInt64 ¶
func RandString ¶
func ReadBinaryFile ¶
func ReflectSetNotDefaultFieldValue ¶
将不是默认字段值, 设置为值定的字段值
func RemoveFile ¶
func SetInterfaceFieldValue ¶
func SetObjFieldFromOtherObj ¶
func StrToInt64 ¶
func StrsToInt64s ¶
func StrsToUnique ¶
func SuffixIsNumAll ¶
func ToJsonStrPretty ¶
func ToJsonStrPretty(data interface{}) string
func WriteStringsToFile ¶
func ZipCompress ¶
Types ¶
type CustomClaims ¶
type CustomClaims struct { Username string `json:"username" request:"username"` Password string `json:"password" request:"password"` Role string `json:"role" request:"role"` jwt.StandardClaims }
载荷,可以加一些自己需要的信息
func NewCustomClaims ¶
func NewCustomClaims(username, password, role string) *CustomClaims
func TokenToClaims ¶
func TokenToClaims(token string) (*CustomClaims, error)
type JWT ¶
type JWT struct {
SigningKey []byte
}
JWT 签名结构
func (*JWT) CreateToken ¶
func (j *JWT) CreateToken(claims CustomClaims) (string, error)
CreateToken 生成一个token
func (*JWT) ParseToken ¶
func (j *JWT) ParseToken(tokenString string) (*CustomClaims, error)
解析Tokne
Source Files ¶
Click to show internal directories.
Click to hide internal directories.