base

package
v0.0.0-...-7b2405d Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2023 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const TimeFormat = "2006-01-02 15:04:05"
View Source
const TimeZone = "Asia/Shanghai"

Variables

View Source
var Errs = map[string]*Errors{
	"ERR_UNKNOW_ERROR":     {0, "未知系统错误"},
	"ERR_NOERROR":          {1, ""},
	"SUCCESS":              {1, ""},
	"ERR_TOO_MANY_REQUEST": {429, "操作过于频繁, 请稍候再试"},
	"ERR_CANNOT_OPERATION": {430, "不可执行此操作"},

	"ERR_PARAM":         {1000, "参数错误"},
	"ERR_UNLOGIN":       {1001, "请先注册登录"},
	"ERR_INVALID_TOKEN": {1002, "无效的token"},
	"ERR_UNAUTHORIZED":  {1004, "您没有权限访问该数据"},
	"ERR_DATA_DECODE":   {1005, "数据解析失败"},
	"ERR_HTTP_BASEURL":  {1006, "请设置 baseurl"},
	"ERR_TCP_TIMEOUT":   {1504, "TCP接口响应超时"},
	"ERR_HTTP_TIMEOUT":  {1505, "HTTP接口响应超时"},

	"ERR_MYSQL":              {2000, "MySQL错误"},
	"ERR_MYSQL_INSTALL_FAIL": {2001, "数据插入失败"},
	"ERR_MYSQL_DELETE_FAIL":  {2002, "数据删除失败"},
	"ERR_MYSQLPOOL_FAIL":     {2004, "mysql连接池丢失"},
	"ERR_REDIS":              {2100, "Reids错误"},
	"ERR_REDISPOOL_FAIL":     {2104, "redis连接池丢失"},
	"ERR_IDGEN_FAIL":         {2404, "id生成失败"},
}

Functions

func Bool2Int

func Bool2Int(b bool) int

func Byte2String

func Byte2String(b []byte) string

Byte2String 字节数组转 string

func CheckFileExist

func CheckFileExist(filename string) bool

func Excp

func Excp(errString string) error

func FileName

func FileName(name, ext string) string

FileName filter invalid string

func FilePath

func FilePath(name, ext string, escape bool) (string, error)

FilePath gen valid file path

func FileSize

func FileSize(filePath string) (int, bool, error)

FileSize return the file size of the specified path file

func Float642String

func Float642String(v float64, p int) string

Float642String float64 转 string

func GenEndHtml

func GenEndHtml() (result string)

func GenHLevelHtml

func GenHLevelHtml(level int, startTag bool) (result string)

func GenPageBreak

func GenPageBreak() (result string)

func GenPdf

func GenPdf(buf *bytes.Buffer, fileName string) (err error)

func GenStartHtml

func GenStartHtml() (result string)

func GetCurrentDirectory

func GetCurrentDirectory() string

func GetMdHeader

func GetMdHeader(level int) string

func GetParentDirectory

func GetParentDirectory(directory string) string

func GetParseParam

func GetParseParam(param string) string

func Int2String

func Int2String(intval int) string

Int2String int 转 string

func Int642String

func Int642String(intval int64) string

Int642String int64 转 string

func LimitLength

func LimitLength(s string, length int) string

LimitLength cut string

func Mkdir

func Mkdir(elem ...string) (string, error)

Mkdir mkdir path

func PathExists

func PathExists(path string) (bool, error)

func SaveFile

func SaveFile(name, content string) (err error)

func StrToTime

func StrToTime(s string) time.Time

func StrToTimeUtc8

func StrToTimeUtc8(s string) time.Time

func String2Float64

func String2Float64(str string) (float64, error)

String2Float64 string 转 float64

func String2Int

func String2Int(str string) (int, error)

String2Int 字符串 转 int

func String2Int64

func String2Int64(str string) (int64, error)

String2Int64 字符串 转 int64

func String2Uint

func String2Uint(str string) uint

String2Uint string 转 uint

func TimeToStr

func TimeToStr(t time.Time) string

func Uint642String

func Uint642String(intval uint64) string

func UnmarshalJSON

func UnmarshalJSON(data []byte, v interface{}) error

UnmarshalJSON 将 data 中的 json 格式的数据, 解析到 v

func UnmarshalReader

func UnmarshalReader(r io.Reader, v interface{}) error

UnmarshalReader 将 r 中的 json 格式的数据, 解析到 v

func ValidateJSONTimeType

func ValidateJSONTimeType(field reflect.Value) interface{}

ValidateJSONTimeType gin 验证器 binding:"required"

func WriteFileWithTrunc

func WriteFileWithTrunc(filename, content string) (err error)

Types

type Controller

type Controller struct {
	Ctx    *gin.Context
	UserID int64
	// UserInfo        UserInfo
	Permission      bool
	Jwt             string
	Client          string
	ClientID        string
	AppName         string
	AppVersion      string
	AppID           int
	Platform        string
	PhoneModel      string
	PhoneSysVersion string
	UmAliasType     string
	UmDeviceToken   string
}

func NewController

func NewController(ctx *gin.Context) (ctl *Controller)

func (*Controller) Error

func (ctl *Controller) Error(e error, opt ...interface{})

func (*Controller) Success

func (ctl *Controller) Success(result interface{})

type Errors

type Errors struct {
	Code    int
	Message string
}

type JSONTime

type JSONTime struct {
	time.Time
}

JSONTime format json time field by myself

func (JSONTime) MarshalJSON

func (t JSONTime) MarshalJSON() ([]byte, error)

MarshalJSON on JSONTime format Time field with Y-m-d H:i:s

func (*JSONTime) Scan

func (t *JSONTime) Scan(v interface{}) error

Scan value of time.Time

func (*JSONTime) UnmarshalJSON

func (t *JSONTime) UnmarshalJSON(data []byte) (err error)

func (JSONTime) Value

func (t JSONTime) Value() (driver.Value, error)

Value insert timestamp into mysql need this function.

type Model

type Model struct {
}

Jump to

Keyboard shortcuts

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