util

package
v0.0.0-...-0843407 Latest Latest
Warning

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

Go to latest
Published: May 26, 2022 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//CodeStatusError for server error
	CodeStatusServerError int = 500
	//CodeStatusNormal for client error
	CodeStatusClientError int = 400
	//CodeStatusNormal normal statu
	CodeStatusNormal int = 200
)
View Source
const DATE_FORMAT = "2006-01-02 15:04:05"
View Source
const DATE_T_FORMAT = "2006-01-02T15:04:05"
View Source
const DATE_T_Z_FORMAT = "2006-01-02T15:04:05Z"
View Source
const DT_FORMAT = "2006-01-02"
View Source
const (
	//----------------------------------
	RedisNotFoundItem = "redisNotFoundItem"
)

Variables

View Source
var CnTime *time.Location
View Source
var GlobK8sConfig *rest.Config

statistics log

Functions

func BatchSet

func BatchSet(k string, data interface{}, c redis.Conn) error

BatchSet

func CacheGetAllKey

func CacheGetAllKey(dataname string) []string

CacheGetAllKey 获取一个cache中的所有field

func CacheSetDataPlus

func CacheSetDataPlus(dataname string, dataField string) int

CacheSetDataPlus 缓存一些数据,每隔一段时间再更新数据库,避免db较大压力

func Catchs

func Catchs()

func CheckKey

func CheckKey(k string, c redis.Conn) bool

func DelFile

func DelFile(fileList []string)

func DelKey

func DelKey(k string, c redis.Conn) error

func DianZhan

func DianZhan(tablename, channelStr, docid string, userid int, c redis.Conn) int

DianZhan 点赞,点过的就取消点赞

func FileExists

func FileExists(path string) bool

func GetCurDate

func GetCurDate() string

func GetCurTime

func GetCurTime() string

func GetDB

func GetDB() *gorm.DB

func GetDianZhan

func GetDianZhan(tablename, channelStr, docid string, userid int, c redis.Conn) int

GetDianZhan 查看某个作品是否已经点赞

func GetInt

func GetInt(k string) (int, error)

GetInt 获取数字

func GetJsonByte

func GetJsonByte(k string) ([]byte, error)

GetJsonByte GetJsonByte

func GetKeyFromRedisByLabel

func GetKeyFromRedisByLabel(tabelname string, label string) string

GetKeyFromRedisByLabel 根据名称获取它在redis里面的Key标签

func GetKeyTTL

func GetKeyTTL(k string) int

GetKeyTTL 获取这个key的剩余过期时间,秒

func GetRandomString

func GetRandomString(l int) string

func GetTZHTime

func GetTZHTime(hours time.Duration) string

func HDEL

func HDEL(k string, filed interface{}, c redis.Conn) error

HDEL 哈希表get

func HGETALL

func HGETALL(k string) ([]interface{}, error)

HGETALL 哈希表get

func HMGet

func HMGet(k string, filed interface{}, c redis.Conn) (interface{}, error)

HMGet 哈希表get

func HMGetPojo

func HMGetPojo(k string, filed interface{}, pojo DBPojo, c redis.Conn) error

HMGetPojo 在不关闭redis的情况下 读取数据

func HMHINCRBY

func HMHINCRBY(k string, filed interface{}, incre int) error

HMHINCRBY 哈希表的 某个field 自增

func HMSet

func HMSet(k string, filed interface{}, value interface{}, c redis.Conn) error

HMSet 统一redis开关

func HTTPGet

func HTTPGet(urlpath string, query url.Values) (result map[string]interface{}, err error)

HTTPGet get request

func HTTPPost

func HTTPPost(url string, requestBody string) (map[string]interface{}, error)

HTTPPost post request

func HVALS

func HVALS(k string, c redis.Conn) ([]string, error)

HVALS 哈希表get

func InitConfig

func InitConfig(path string)

func InitDB

func InitDB() (err error)

connect to database

func InitRedis

func InitRedis() error

InitRedis 初始化redis连接池

func InitStatisticsLog

func InitStatisticsLog()

func IsLetter

func IsLetter(chars rune) bool

func LBatchpush

func LBatchpush(k string, data interface{}, c redis.Conn) error

LBatchpush 插入多个

func LREM

func LREM(k string, count int, value interface{}) (err error)

LREM 移除

func LSET

func LSET(k string, index int, value string) error

LSET 插入多个

func LTRIM

func LTRIM(k string, start, stop int) (err error)

LTRIM 只保留左边的多少个

func LocalTimeToUTC

func LocalTimeToUTC(strTime string) time.Time

func LoggerToFile

func LoggerToFile() gin.HandlerFunc

func Lpush

func Lpush(k string, data interface{}) error

Lpush 插入多个

func LpushString

func LpushString(k string, data string) (count int, err error)

LpushString 插入多个Object

func Lrange

func Lrange(k string, start, end int) ([]int, error)

Lrange 获取

func LrangeString

func LrangeString(k string, start, end int) ([]string, error)

LrangeString 从左边获取多个

func NewRedisPool

func NewRedisPool(redisURL, pswd string, db int) (redisErr error)

NewRedisPool return redis pool

func PlusBatchOne

func PlusBatchOne(k string, c redis.Conn) int

PlusOne 值累加1

func PraseTimeInt

func PraseTimeInt(stringTime string) int64

Time string to timestamp

func PraseTimeTint

func PraseTimeTint(tsStr string) int64

func ReadAll

func ReadAll(filePth string) ([]byte, error)

func RedisClose

func RedisClose(c redis.Conn)

RedisClose 关闭redis连接

func RedisGet

func RedisGet(k string, c redis.Conn) ([]byte, error)

RedisGet GetJsonByte

func RedisOpen

func RedisOpen() redis.Conn

RedisOpen 打开redis连接

func Rpush

func Rpush(k string, data int) error

Rpush 插入多个

func RpushString

func RpushString(k string, data string) (count int, err error)

RpushString 插入多个Object

func Rrange

func Rrange(k string, start, end int) ([]int, error)

Rrange 从右边获取最新的数据

func SADD

func SADD(k string, fileID int) error

SADD 用来向set里面增加

func SADDString

func SADDString(k string, value string) error

SADDString 用来向set里面增加string

func SMEMBERS

func SMEMBERS(k string) (interface{}, error)

SMEMBERS 获取k的所有memebers

func Set

func Set(k string, data interface{}) error

Set key:value

func SetKeyExpire

func SetKeyExpire(k string, ex int, c redis.Conn)

func SetKeyWithExpire

func SetKeyWithExpire(k string, data interface{}, ex int, c redis.Conn) error

func StatisticsLog

func StatisticsLog(sd *StatisticsData) error

func StringsToJSON

func StringsToJSON(str string) string

StringsToJSON StringsToJSON

func TimeConverStr

func TimeConverStr(ts, oldLayout, newLayout string) string

func TimeStrToInt

func TimeStrToInt(ts, layout string) int64

func TimeTConverStr

func TimeTConverStr(ts string) string

func ZADD

func ZADD(key string, score int, value interface{}, c redis.Conn) error

ZADD 用来向Zset里面增加

Types

type AuthingConfig

type AuthingConfig struct {
	UserPoolID  string `json:"userPoolID"`
	Secret      string `json:"secret"`
	AppID       string `json:"appID"`
	AppSecret   string `json:"appSecret"`
	RedirectURI string `json:"redirect_uri"`
}

Authing Config

type BuildParam

type BuildParam struct {
	Arch             []string `json:"arch"`
	Release          []string `json:"release"`
	BuildType        []string `json:"buildType"`
	OpeneulerMinimal string   `json:"openeulerMinimal"`
	CustomRpmAPI     string   `json:"customRpmAPI"`
	PackageName      string   `json:"packageName"`
}

type BuildServer

type BuildServer struct {
	ApiUrl              string `json:"apiUrl"`
	OmniRepoAPI         string `json:"omniRepoAPI"`
	OmniRepoAPIInternal string `json:"omniRepoAPIInternal"`
}

Build Server

type Config

type Config struct {
	AppName        string         `json:"app_name"`
	AppModel       string         `json:"app_model"`
	AppHost        string         `json:"app_host"`
	AppPort        int            `json:"app_port"`
	Database       DatabaseConfig `json:"database"`
	RedisConfig    RedisConfig    `json:"redis_config"`
	BuildParam     BuildParam     `json:"buildParam"`
	DefaultPkgList PkgList
	CustomPkgList  PkgList
	WSConfig       WSConfig      `json:"ws_config"`
	K8sConfig      K8sConfig     `json:"k8s"`
	AuthingConfig  AuthingConfig `json:"authing"`
	JwtConfig      JwtConfig     `json:"jwt"`
	BuildServer    BuildServer   `json:"buildServer"`
	Statistic      Statistic     `json:"statistic"`
}

app config

func GetConfig

func GetConfig() *Config

external

type DBPojo

type DBPojo interface {
	TableName() string
}

type DatabaseConfig

type DatabaseConfig struct {
	Driver   string `json:"driver"`
	DBUser   string `json:"db_user"`
	Password string `json:"password"`
	DBHost   string `json:"db_host"`
	DBPort   string `json:"db_port"`
	DbName   string `json:"db_name"`
	Chartset string `json:"charset"`
	ShowSql  bool   `json:"show_sql"`
}

sql config

type JsonData

type JsonData struct {
	Code   int         `json:"code"`
	Title  interface{} `json:"title"`
	Attach interface{} `json:"attach,omitempty"`
	Data   interface{} `json:"data"`
	Other  interface{} `json:"other,omitempty"`
}

JsonData export to clent

func ExportData

func ExportData(code int, title interface{}, data ...interface{}) *JsonData

ExportData ExportData

type JwtConfig

type JwtConfig struct {
	Expire int    `json:"expire"`
	JwtKey string `json:"jwtKey"`
}

Jwt Jwt

type K8sConfig

type K8sConfig struct {
	Namespace string `json:"namespace"`
	Image     string `json:"image"`
	FfileType string `json:"ffileType"`
}

type PkgList

type PkgList struct {
	Packages []string `json:"packages"`
}

type RedisConfig

type RedisConfig struct {
	Addr     string `json:"addr"`
	Port     string `json:"port"`
	Password string `json:"password"`
	Db       int    `json:"db"`
}

Redis config

type Statistic

type Statistic struct {
	Dir           string `json:"dir"`
	LogFile       string `json:"log_file"`
	LogFileSize   int64  `json:"log_file_size"`
	LogFileSuffix string `json:"log_file_suffix"`
}

Statistic function

type StatisticsData

type StatisticsData struct {
	UserId       int
	UserName     string
	UserProvider string
	UserEmail    string
	EventType    string
	State        string
	StateMessage string
	Body         interface{}
}

type WSConfig

type WSConfig struct {
	Host        string `json:"host"`
	Port        int    `json:"port"`
	CheckOrigin bool   `json:"check_origin"`
}

websocket config

Jump to

Keyboard shortcuts

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