part

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: MIT Imports: 47 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// 运行环境,可选项:dev/test/prod
	ENV               EnumEnv = ""
	ENV_LOADED        bool    = false
	USE_PPROF         bool    = false
	APP_NAME          string  = ""
	APP_HOST          string  = "0.0.0.0"
	APP_PORT          int     = 0
	RPCX_SERVICE_PORT int     = 0
	INCLUDE_DEMO      bool    = false
)

Functions

func LoadConfig

func LoadConfig(forceEnv EnumEnv) (err error)

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

func NewCacheByConfig

func NewCacheByConfig(config CacheConfig) *Cache

func (*Cache) CreateKey

func (m *Cache) CreateKey(key string) string

func (*Cache) Decr

func (m *Cache) Decr(key string) (result int64, err error)

func (*Cache) Del

func (m *Cache) Del(key string) (result bool, err error)

func (*Cache) Exists

func (m *Cache) Exists(key string) (result bool, err error)

func (*Cache) Get

func (m *Cache) Get(key string) (result string, err error)

func (*Cache) GetBackend

func (m *Cache) GetBackend() (result *redis.Client, err error)

func (*Cache) GetMutex

func (m *Cache) GetMutex(key string, options ...redsync.Option) (result *redsync.Mutex)

func (*Cache) GetMyRank

func (m *Cache) GetMyRank(key string, member string, desc bool) (rank int64, score float64, err error)

func (*Cache) GetRankList

func (m *Cache) GetRankList(key string, start, stop int64, desc bool) (data []redis.Z, allCount int64, err error)

func (*Cache) Incr

func (m *Cache) Incr(key string) (result int64, err error)

func (*Cache) IncrRankScore

func (m *Cache) IncrRankScore(key string, member string, score float64) (err error)

func (*Cache) Md5

func (m *Cache) Md5(str string) string

func (*Cache) Set

func (m *Cache) Set(key string, value string) (result string, err error)

func (*Cache) SetEx

func (m *Cache) SetEx(key string, value string, ttl time.Duration) (result string, err error)

func (*Cache) UpdateRankScore

func (m *Cache) UpdateRankScore(key string, member string, score float64) (err error)

type CacheConfig

type CacheConfig struct {
	AppName  string
	Server   string
	Password string
	DataBase int
	PoolSize int
}

type Captcha

type Captcha struct {
	// contains filtered or unexported fields
}

func (*Captcha) Draw

func (m *Captcha) Draw(id string) (result *pkg.CaptchaData, err error)

func (*Captcha) New

func (m *Captcha) New() (result *pkg.CaptchaData, err error)

func (*Captcha) Reload

func (m *Captcha) Reload(id string) (result *pkg.CaptchaData, err error)

func (*Captcha) Verify

func (m *Captcha) Verify(id string, digits string) (result bool, err error)

type Channel

type Channel struct {
	// contains filtered or unexported fields
}

type DataBase

type DataBase struct {
	Enable bool
	// contains filtered or unexported fields
}

func (*DataBase) Commit

func (m *DataBase) Commit(transId string) (err error)

func (*DataBase) GetDB

func (m *DataBase) GetDB() *gorm.DB

func (*DataBase) GetTransaction

func (m *DataBase) GetTransaction(transId string) (result *gorm.DB, err error)

func (*DataBase) Rollback

func (m *DataBase) Rollback(transId string) (err error)

type DataLog

type DataLog struct {
	Id         string    `gorm:"size:20;primaryKey" json:"id"`
	Table      string    `gorm:"size:100" json:"table"`
	Action     string    `gorm:"size:10" json:"action"`
	Executor   string    `gorm:"size:50" json:"executor"`
	Content    string    `gorm:"type:longText" json:"content"`
	CreateTime time.Time `json:"createTime"`
}

func (DataLog) TableName

func (DataLog) TableName() string

type DataLogger

type DataLogger struct {
	// contains filtered or unexported fields
}

func (*DataLogger) WriteAddLog

func (m *DataLogger) WriteAddLog(entity base.IDBModel, ctx context.Context, transId string) (err error)

func (*DataLogger) WriteDelLog

func (m *DataLogger) WriteDelLog(entity base.IDBModel, ctx context.Context, transId string) (err error)

func (*DataLogger) WriteEditLog

func (m *DataLogger) WriteEditLog(oldEntity, newEntity base.IDBModel, ctx context.Context, transId string) (err error)

func (*DataLogger) WriteUpdateLog

func (m *DataLogger) WriteUpdateLog(oldEntity base.IDBModel, newValues map[string]interface{}, ctx context.Context, transId string) (err error)

type DataUpdateLog

type DataUpdateLog struct {
	Op    string      `json:"op"`
	Path  string      `json:"path"`
	Value interface{} `json:"value"`
}

type EnumEnv

type EnumEnv string
const (
	// 开发环境
	ENUM_ENV_DEV EnumEnv = "dev"
	// 测试环境
	ENUM_ENV_TEST EnumEnv = "test"
	// 预发布环境
	ENUM_ENV_PRE EnumEnv = "pre"
	// 生产环境
	ENUM_ENV_PROD EnumEnv = "prod"
)

type ICache

type ICache interface {
	GetBackend() (result *redis.Client, err error)
	Get(key string) (result string, err error)
	Set(key string, value string) (result string, err error)
	SetEx(key string, value string, ttl time.Duration) (result string, err error)
	Del(key string) (result bool, err error)
	Exists(key string) (result bool, err error)
	Incr(key string) (result int64, err error)
	Decr(key string) (result int64, err error)
	CreateKey(key string) string
	GetMutex(key string, options ...redsync.Option) (result *redsync.Mutex)
	GetRankList(key string, start, stop int64, desc bool) (data []redis.Z, allCount int64, err error)
	UpdateRankScore(key string, member string, score float64) (err error)
	IncrRankScore(key string, member string, score float64) (err error)
	GetMyRank(key string, member string, desc bool) (rank int64, score float64, err error)
}

func NewCache

func NewCache() ICache

type ICaptcha

type ICaptcha interface {
	New() (result *pkg.CaptchaData, err error)
	Reload(id string) (result *pkg.CaptchaData, err error)
	Draw(id string) (result *pkg.CaptchaData, err error)
	Verify(id string, digits string) (result bool, err error)
}

func NewCaptcha

func NewCaptcha(cache ICache) ICaptcha

type IDataBase

type IDataBase interface {
	GetDB() *gorm.DB
	GetTransaction(transId string) (result *gorm.DB, err error)
	Commit(transId string) (err error)
	Rollback(transId string) (err error)
}

func NewDataBase

func NewDataBase(lruCache ILruCache) IDataBase

type IDataLogger

type IDataLogger interface {
	WriteAddLog(entity base.IDBModel, ctx context.Context, transId string) (err error)
	WriteDelLog(entity base.IDBModel, ctx context.Context, transId string) (err error)
	WriteEditLog(oldEntity, newEntity base.IDBModel, ctx context.Context, transId string) (err error)
	WriteUpdateLog(oldEntity base.IDBModel, newValues map[string]interface{}, ctx context.Context, transId string) (err error)
}

func NewDataLogger

func NewDataLogger(db IDataBase) IDataLogger

type IJob

type IJob interface {
	Option() JobOption
	Run()
}

type IJobCenter

type IJobCenter interface {
	RegisteJob(job IJob)
	StartJobs()
}

func NewJobCenter

func NewJobCenter() IJobCenter

type IJwtService

type IJwtService interface {
	// CreateToken 生成Token,默认存入Cookie中
	CreateToken(ctx iris.Context, claims interface{}) (token string, err error)
	// GetClaims 验证Token并返回其中包含的Claims对象指针,需要在Middleware处理后才能获得,如需手动验证,请使用VerifyToken方法,强烈建议使用此方法
	GetClaims(ctx iris.Context) (claims interface{}, err error)
	// VerifyToken 从默认渠道(Cookie)中获取Token信息并验证,验证成功后返回VerifiedToken对象,仅用于手动验证,不建议使用
	VerifyToken(ctx iris.Context) (result *jwt.VerifiedToken, err error)
	// RemoveToken 从Cookie中移除Token信息,一般用于"注销"功能
	RemoveToken(ctx iris.Context)
	// GetMiddleware 获取iris路由中间件,用于验证请求合法性
	GetMiddleware() iris.Handler
	// 获取用户JWT对象
	GetExecutorInfo(ctx iris.Context) (result pkg.BaseUserInfo, err error)
	// 获取用户请求Context
	GetExecutorContext(ctx iris.Context) context.Context
	// 获取用户请求Context
	GetExecutorContextWithInfo(ctx iris.Context) (result context.Context, info *pkg.BaseUserInfo)
	// 从cookie中获取Token
	VerifyCookieToken(token string) (result *jwt.VerifiedToken, err error)
}

func NewJWT

func NewJWT() IJwtService

type ILogCenter

type ILogCenter interface {
	Log() *logrus.Logger
}

func NewLogCenter

func NewLogCenter() ILogCenter

type ILruCache

type ILruCache interface {
	Add(key, value interface{}) (success bool)
	AddEx(key, value interface{}, expire time.Duration) (success bool)
	Get(key interface{}) (result interface{}, success bool)
	Contains(key interface{}) (success bool)
	Peek(key interface{}) (result interface{}, success bool)
	ContainsOrAdd(key, value interface{}) (success, evict bool)
	Remove(key interface{})
	RemoveOldest()
	Keys() (result []interface{})
	Len() (result int)
	Purge()
}

func NewLruCache

func NewLruCache() ILruCache

type IMsgCenter

type IMsgCenter interface {
	OpenChannel(channels []string, onReceiveMsg func(*centrifuge.ClientInfo, *pkg.MsgContent)) (err error)
	CloseChannel(channels []string) (err error)
	SendMsg(channel, msgType, msg string) (err error)
	CreateAppChannelId(channel string) (result string, err error)
	GetConnToken(user string, exp int64) string
	GetSubscriptionToken(channel string, user string, exp int64) (channelId string, token string)
}

func NewMsgCenter

func NewMsgCenter(logCenter ILogCenter) IMsgCenter

type INsq

type INsq interface {
	GetProducer() (result *nsq.Producer, err error)
	GetConsumer(topic string, channel string, handler nsq.Handler) (result *nsq.Consumer, err error)
}

func NewNsq

func NewNsq() INsq

type ISessionCache

type ISessionCache interface {
	Get(ctx iris.Context, key string) (result string, err error)
	Set(ctx iris.Context, key string, value string, ttl time.Duration) (result string, err error)
	Del(ctx iris.Context, key string) (result bool, err error)
	Exists(ctx iris.Context, key string) (result bool, err error)
	Incr(ctx iris.Context, key string) (result int64, err error)
	GetCacheKey(ctx iris.Context, key string) string
}

func NewSessionCache

func NewSessionCache(cache ICache) ISessionCache

type ISwaggerService

type ISwaggerService interface {
}

func NewSwaggerService

func NewSwaggerService(app *iris.Application, spec *swag.Spec) ISwaggerService

type IUnionJD

type IUnionJD interface {
	BysubunionidPromotion(req common.Request) (result response.PromotionCodeResult, err error)
	OrderRowQuery(req common.Request) (result response.OrderRowQueryResult, err error)
	GetJDDeepLink(platform string, sourceUrl string) (result string, err error)
}

func NewUnionJD

func NewUnionJD() IUnionJD

type IWxAuth

type IWxAuth interface {
	GetCurrentUser(ctx iris.Context) (result *pkg.WxAuthInfo)
	CheckAuth(ctx iris.Context, cak string, customReturnURL string) (result bool)
	ClearAuth(ctx iris.Context) (err error)
	DoAuth(ctx iris.Context, afterAuth func(authInfo *pkg.WxAuthInfo, cak string))
	GetAuthUrl(cak string) (result string)
}

func NewWxAuth

func NewWxAuth(cache ICache, sessionCache ISessionCache, logCenter ILogCenter) IWxAuth

type JWTService

type JWTService struct {
	// contains filtered or unexported fields
}

func NewCustomJWT

func NewCustomJWT(header string) *JWTService

func (*JWTService) CreateToken

func (m *JWTService) CreateToken(ctx iris.Context, claims interface{}) (token string, err error)

CreateToken 生成Token,默认存入Cookie中

func (*JWTService) FromCookie

func (m *JWTService) FromCookie(ctx iris.Context) string

func (*JWTService) FromHeader

func (m *JWTService) FromHeader(ctx iris.Context) string

func (*JWTService) GetClaims

func (m *JWTService) GetClaims(ctx iris.Context) (claims interface{}, err error)

GetClaims 验证Token并返回其中包含的Claims对象指针,需要在Middleware处理后才能获得,如需手动验证,请使用VerifyToken方法,强烈建议使用此方法

func (*JWTService) GetExecutorContext

func (m *JWTService) GetExecutorContext(ctx iris.Context) context.Context

func (*JWTService) GetExecutorContextWithInfo

func (m *JWTService) GetExecutorContextWithInfo(ctx iris.Context) (result context.Context, info *pkg.BaseUserInfo)

func (*JWTService) GetExecutorInfo

func (m *JWTService) GetExecutorInfo(ctx iris.Context) (result pkg.BaseUserInfo, err error)

func (*JWTService) GetMiddleware

func (m *JWTService) GetMiddleware() iris.Handler

GetMiddleware 获取iris路由中间件,用于验证请求合法性

func (*JWTService) RemoveToken

func (m *JWTService) RemoveToken(ctx iris.Context)

RemoveToken 从Cookie中移除Token信息,一般用于"注销"功能

func (*JWTService) VerifyCookieToken

func (m *JWTService) VerifyCookieToken(token string) (result *jwt.VerifiedToken, err error)

func (*JWTService) VerifyToken

func (m *JWTService) VerifyToken(ctx iris.Context) (result *jwt.VerifiedToken, err error)

VerifyToken 从默认渠道(Cookie)中获取Token信息并验证,验证成功后返回VerifiedToken对象,仅用于手动验证,不建议使用

type JobCenter

type JobCenter struct {
	Enable bool

	JobArray []IJob
	// contains filtered or unexported fields
}

func (*JobCenter) RegisteJob

func (m *JobCenter) RegisteJob(job IJob)

func (*JobCenter) StartJobs

func (m *JobCenter) StartJobs()

type JobOption

type JobOption struct {
	// Immediately 立即执行,当设置为true时,任务将在系统启动时立即执行,不用等待Schedule,反之亦然
	Name        string
	Immediately bool
	Schedule    cron.Schedule
}

type LogCenter

type LogCenter struct {
	// contains filtered or unexported fields
}

func (*LogCenter) Log

func (m *LogCenter) Log() *logrus.Logger

type LruCache

type LruCache struct {
	// contains filtered or unexported fields
}

Cache is a thread-safe fixed size LRU cache.

func New

func New(size int) (*LruCache, error)

New creates an LRU of the given size

func NewWithEvict

func NewWithEvict(size int, onEvicted func(key interface{}, value interface{})) (*LruCache, error)

NewWithEvict constructs a fixed size cache with the given eviction callback.

func NewWithExpire

func NewWithExpire(size int, expire time.Duration) (*LruCache, error)

NewWithExpire constructs a fixed size cache with expire feature

func (*LruCache) Add

func (c *LruCache) Add(key, value interface{}) bool

Add adds a value to the cache. Returns true if an eviction occurred.

func (*LruCache) AddEx

func (c *LruCache) AddEx(key, value interface{}, expire time.Duration) bool

AddEx adds a value to the cache. Returns true if an eviction occurred.

func (*LruCache) Contains

func (c *LruCache) Contains(key interface{}) bool

Check if a key is in the cache, without updating the recent-ness or deleting it for being stale.

func (*LruCache) ContainsOrAdd

func (c *LruCache) ContainsOrAdd(key, value interface{}) (ok, evict bool)

ContainsOrAdd checks if a key is in the cache without updating the recent-ness or deleting it for being stale, and if not, adds the value. Returns whether found and whether an eviction occurred.

func (*LruCache) Get

func (c *LruCache) Get(key interface{}) (interface{}, bool)

Get looks up a key's value from the cache.

func (*LruCache) Keys

func (c *LruCache) Keys() []interface{}

Keys returns a slice of the keys in the cache, from oldest to newest.

func (*LruCache) Len

func (c *LruCache) Len() int

Len returns the number of items in the cache.

func (*LruCache) Peek

func (c *LruCache) Peek(key interface{}) (interface{}, bool)

Returns the key value (or undefined if not found) without updating the "recently used"-ness of the key.

func (*LruCache) Purge

func (c *LruCache) Purge()

Purge is used to completely clear the cache

func (*LruCache) Remove

func (c *LruCache) Remove(key interface{})

Remove removes the provided key from the cache.

func (*LruCache) RemoveOldest

func (c *LruCache) RemoveOldest()

RemoveOldest removes the oldest item from the cache.

type MsgCenter

type MsgCenter struct {
	Enable bool
	// contains filtered or unexported fields
}

func (*MsgCenter) CloseChannel

func (m *MsgCenter) CloseChannel(channels []string) (err error)

func (*MsgCenter) CreateAppChannelId

func (m *MsgCenter) CreateAppChannelId(channel string) (result string, err error)

func (*MsgCenter) GetConnToken

func (m *MsgCenter) GetConnToken(user string, exp int64) string

func (*MsgCenter) GetSubscriptionToken

func (m *MsgCenter) GetSubscriptionToken(channel string, user string, exp int64) (channelId string, token string)

func (*MsgCenter) OpenChannel

func (m *MsgCenter) OpenChannel(channels []string, onReceiveMsg func(*centrifuge.ClientInfo, *pkg.MsgContent)) (err error)

func (*MsgCenter) SendMsg

func (m *MsgCenter) SendMsg(channel, msgType, msg string) (err error)

type Nsq

type Nsq struct {
	// contains filtered or unexported fields
}

func (*Nsq) GetConsumer

func (m *Nsq) GetConsumer(topic string, channel string, handler nsq.Handler) (result *nsq.Consumer, err error)

func (*Nsq) GetProducer

func (m *Nsq) GetProducer() (result *nsq.Producer, err error)

type RedisStore

type RedisStore struct {
	// contains filtered or unexported fields
}

func NewRedisStore

func NewRedisStore(cache ICache) *RedisStore

func (*RedisStore) Get

func (m *RedisStore) Get(id string, clear bool) string

func (*RedisStore) Set

func (m *RedisStore) Set(id string, value string) error

func (*RedisStore) Verify

func (m *RedisStore) Verify(id, answer string, clear bool) bool

type SessionCache

type SessionCache struct {
	// contains filtered or unexported fields
}

func (*SessionCache) Del

func (m *SessionCache) Del(ctx iris.Context, key string) (result bool, err error)

func (*SessionCache) Exists

func (m *SessionCache) Exists(ctx iris.Context, key string) (result bool, err error)

func (*SessionCache) Get

func (m *SessionCache) Get(ctx iris.Context, key string) (result string, err error)

func (*SessionCache) GetCacheKey

func (m *SessionCache) GetCacheKey(ctx iris.Context, key string) string

func (*SessionCache) Incr

func (m *SessionCache) Incr(ctx iris.Context, key string) (result int64, err error)

func (*SessionCache) Set

func (m *SessionCache) Set(ctx iris.Context, key string, value string, ttl time.Duration) (result string, err error)

type SwaggerService

type SwaggerService struct {
}

type UnionJD

type UnionJD struct {
	// contains filtered or unexported fields
}

func (*UnionJD) BysubunionidPromotion

func (m *UnionJD) BysubunionidPromotion(req common.Request) (result response.PromotionCodeResult, err error)

社交媒体获取推广链接接口

func (m *UnionJD) GetJDDeepLink(platform string, sourceUrl string) (result string, err error)

生成京东Deeplink

func (*UnionJD) OrderRowQuery

func (m *UnionJD) OrderRowQuery(req common.Request) (result response.OrderRowQueryResult, err error)

查询推广订单及佣金信息

type WxAuth

type WxAuth struct {
	Enable bool
	// contains filtered or unexported fields
}

func (*WxAuth) CheckAuth

func (m *WxAuth) CheckAuth(ctx iris.Context, cak string, customReturnURL string) (result bool)

func (*WxAuth) ClearAuth

func (m *WxAuth) ClearAuth(ctx iris.Context) (err error)

func (*WxAuth) DoAuth

func (m *WxAuth) DoAuth(ctx iris.Context, afterAuth func(authInfo *pkg.WxAuthInfo, cak string))

func (*WxAuth) GetAuthUrl

func (m *WxAuth) GetAuthUrl(cak string) (result string)

func (*WxAuth) GetCurrentUser

func (m *WxAuth) GetCurrentUser(ctx iris.Context) (result *pkg.WxAuthInfo)

Jump to

Keyboard shortcuts

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