libs

package
v0.0.0-...-2f9fa3e Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2020 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Config = struct {
	LogLevel string `default:"info" env:"Loglevel"`
	Bindata  bool   `default:"true" env:"Bindata"`
	Debug    bool   `default:"true" env:"Debug"`
	HTTPS    bool   `default:"false" env:"HTTPS"`
	Certpath string `default:"" env:"Certpath"`
	Certkey  string `default:"" env:"Certkey"`
	Port     int    `default:"8085" env:"PORT"`
	Host     string `default:"127.0.0.1" env:"Host"`
	Admin    struct {
		UserName        string `env:"AdminUserName" default:"username"`
		Name            string `env:"AdminName" default:"name"`
		Pwd             string `env:"AdminPwd" default:"123456"`
		RoleName        string `env:"AdminRoleName" default:"admin"`
		RoleDisplayName string `env:"TenantRoleDisplayName" default:"超级管理员"`
	}
	DB struct {
		Prefix   string `env:"DBPrefix" default:"iris_"`
		Name     string `env:"DBName" default:"goirisapi"`
		Adapter  string `env:"DBAdapter" default:"mysql"`
		Host     string `env:"DBHost" default:"localhost"`
		Port     string `env:"DBPort" default:"3306"`
		User     string `env:"DBUser" default:"root"`
		Password string `env:"DBPassword" default:""`
	}
	Redis struct {
		Host string `env:"RedisHost" default:"localhost"`
		Port string `env:"RedisPort" default:"6379"`
		Pwd  string `env:"RedisPwd" default:""`
	}
	Limit struct {
		Disable bool    `env:"LimitDisable" default:"true"`
		Limit   float64 `env:"LimitLimit" default:"1"`
		Burst   int     `env:"LimitBurst" default:"5"`
	}
	Qiniu struct {
		Enable    bool   `env:"QiniuEnable" default:"false"`
		Host      string `env:"QiniuHost" default:""`
		Accesskey string `env:"QiniuAccesskey" default:""`
		Secretkey string `env:"QiniuSecretkey" default:""`
		Bucket    string `env:"QiniuBucket" default:""`
	}
}{}
View Source
var (
	Db *gorm.DB
)
View Source
var Enforcer *casbin.Enforcer
View Source
var FlagVarDBFile string

Functions

func Base64Decode

func Base64Decode(str string) string

*

  • base64 解码
  • @method func
  • @param {[type]} t *Tools [description]
  • @return {[type]} [description]

func CWD

func CWD() string

当前目录

func DBFile

func DBFile() string

func DBFileDev

func DBFileDev() string

func DeepCopy

func DeepCopy(dst, src interface{}) error

func EXEName

func EXEName() string

func EnsureDir

func EnsureDir(dir string) (err error)

func ErrorLogFilename

func ErrorLogFilename() string

func Exist

func Exist(path string) bool

func GetRandomString

func GetRandomString(n int) string

生成随机字符串

func GetRedisUris

func GetRedisUris() []string

func HashPassword

func HashPassword(pwd string) string

func InArrayS

func InArrayS(items []string, s string) bool

InArrayS 如果 s 在 items 中,返回 true;否则,返回 false。

func InitCasbin

func InitCasbin()

func InitConfig

func InitConfig(p string)

func InitDb

func InitDb()

func InitRedisCluster

func InitRedisCluster(addrs []string, password string)

func IsPortInUse

func IsPortInUse(port int) bool

func LocalIP

func LocalIP() string

本机 ip

func LogDir

func LogDir() string

func MD5

func MD5(str string) string

md5

func ParseFlostToString

func ParseFlostToString(f float64) string

*

  • 转换浮点数为string
  • @method func
  • @param {[type]} t * Tools [description]
  • @return {[type]} [description]

func ParseInt

func ParseInt(b string, defInt int) int

*

  • string转换int
  • @method parseInt
  • @param {[type]} b string [description]
  • @return {[type]} [description]

func ParseString

func ParseString(b int) string

*

  • int转换string
  • @method parseInt
  • @param {[type]} b string [description]
  • @return {[type]} [description]

func RedisLock

func RedisLock(key, value string, expireTime time.Duration) bool

func RedisUnLock

func RedisUnLock(key, value string) error

func StructToMap

func StructToMap(obj interface{}) map[string]interface{}

*

  • 结构体转换成map对象
  • @method func
  • @param {[type]} t *Tools [description]
  • @return {[type]} [description]

func StructToString

func StructToString(data interface{}) string

*

  • 结构体转成json 字符串
  • @method StruckToString
  • @param {[type]} data interface{} [description]

func SubString

func SubString(str string, start, length int) string

*

  • 字符串截取
  • @method func
  • @param {[type]} t *Tools [description]
  • @return {[type]} [description]

func TimeFormat

func TimeFormat(time *time.Time) string

*

  • 时间格式化
  • @method func
  • @param {[type]} t *Tools [description]
  • @return {[type]} [description]

func UnitJoin

func UnitJoin(ss []uint, sep string) string

连接 unit slice 为字符串

func WorkInDir

func WorkInDir(f func(), dir string)

func WwwPath

func WwwPath() string

Types

type GeneratePhoneNumber

type GeneratePhoneNumber struct {
	CacheData []string
}

func (*GeneratePhoneNumber) CreatePhoneNumber

func (*GeneratePhoneNumber) CreatePhoneNumber() string

生成随机手机号码

func (*GeneratePhoneNumber) CreateUniquePhoneNumber

func (g *GeneratePhoneNumber) CreateUniquePhoneNumber() string

生成唯一随机手机号码

type Lists

type Lists struct {
	Data  interface{} `json:"data"`
	Total int         `json:"total"`
}

type RedisCluster

type RedisCluster struct {
	*redisc.Cluster
}

func GetRedisClusterClient

func GetRedisClusterClient() *RedisCluster

func (*RedisCluster) Close

func (rc *RedisCluster) Close()

func (*RedisCluster) Del

func (rc *RedisCluster) Del(keys ...interface{}) (int, error)

func (*RedisCluster) Do

func (rc *RedisCluster) Do(cmd string, args ...interface{}) (interface{}, error)

func (*RedisCluster) Exists

func (rc *RedisCluster) Exists(key string) bool

func (*RedisCluster) Expire

func (rc *RedisCluster) Expire(key string, seconds int) (interface{}, error)

func (*RedisCluster) GetKey

func (rc *RedisCluster) GetKey(key string) (interface{}, error)

func (*RedisCluster) HGetAll

func (rc *RedisCluster) HGetAll(key string) (interface{}, error)

func (*RedisCluster) HIncrBy

func (rc *RedisCluster) HIncrBy(key string, field string, incr int64) (interface{}, error)

func (*RedisCluster) HMSet

func (rc *RedisCluster) HMSet(key string, values ...interface{}) (interface{}, error)

func (*RedisCluster) LLen

func (rc *RedisCluster) LLen(key string) int

func (*RedisCluster) LPush

func (rc *RedisCluster) LPush(key string, values ...interface{}) (interface{}, error)

func (*RedisCluster) LRange

func (rc *RedisCluster) LRange(key string, start, end int) (interface{}, error)

func (*RedisCluster) LTrim

func (rc *RedisCluster) LTrim(key string, start, end int) (interface{}, error)

func (*RedisCluster) Members

func (rc *RedisCluster) Members(key string) (interface{}, error)

func (*RedisCluster) RPush

func (rc *RedisCluster) RPush(key string, values ...interface{}) (interface{}, error)

func (*RedisCluster) Sadd

func (rc *RedisCluster) Sadd(key string, members ...interface{}) (interface{}, error)

func (*RedisCluster) Scard

func (rc *RedisCluster) Scard(key string) (interface{}, error)

func (*RedisCluster) Send

func (rc *RedisCluster) Send(cmd string, args ...interface{}) error

func (*RedisCluster) Set

func (rc *RedisCluster) Set(key string, value interface{}, ttl ...time.Duration) (interface{}, error)

func (*RedisCluster) SetNX

func (rc *RedisCluster) SetNX(key string, value interface{}, expireSeconds int) bool

type Response

type Response struct {
	Code int64       `json:"code"`
	Msg  interface{} `json:"message"`
	Data interface{} `json:"data"`
}

func ApiResource

func ApiResource(code int64, objects interface{}, msg string) (r *Response)

Jump to

Keyboard shortcuts

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