utils

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2024 License: GPL-3.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Db      *gorm.DB
	Rdb     *redis.Client
	Casbin  *casbin.Enforcer
	Bleve   []bleve.Index
	CacheDb []*badger.DB
)
View Source
var SseClients = make(map[string]chan string, 0)

<script>

if ('EventSource' in window) {
    let token = document.querySelector("#token").value
    var eventsoure = new EventSource(`http://127.0.0.1:8080/sse/${token}`,{ withCredentials: true })
    eventsoure.onmessage = function(event){
        console.log("message=", event.data)
    }
}else{
    document.write("No support eventsource")
}

</script>

Functions

func Aes128Decrypt

func Aes128Decrypt(str string, opts ...Option) (s string)

AES对称解密

func Aes128Encrypt

func Aes128Encrypt(str string, opts ...Option) (s string)

AES对称加密

func BadgerBatch

func BadgerBatch(dats []map[string]string, opts ...Option) error

批处理新增数据

func BadgerExists

func BadgerExists(key string, opts ...Option) bool

判断指定key缓存是否存在

func BadgerGet

func BadgerGet(key string, opts ...Option) (any, error)

根据key取缓存

func BadgerRemove

func BadgerRemove(key string, opts ...Option) error

删除指定key的缓存

func BadgerScan

func BadgerScan(prefix string, opts ...Option) ([]map[string]any, uint64, error)

从缓存中查询对应的key和值

func BadgerScanKeyOnly

func BadgerScanKeyOnly(prefix string, opts ...Option) ([]string, uint64, error)

从缓存中只查询对应的key

func BadgerSet

func BadgerSet(key string, data any, opts ...Option) error

设置缓存key和值以及时效

func BleveDocCount

func BleveDocCount(opt ...Option) (uint64, error)

搜索引擎文档总数

func BleveDocument

func BleveDocument(id string, opts ...Option) (map[string]any, error)

根据id得到搜索引擎中文档内容

func BleveIndex

func BleveIndex(id string, data map[string]any, opts ...Option) error

内容加入搜索引擎

func BleveRemove

func BleveRemove(id string, opts ...Option) error

删除搜索引擎中指定文档

func BleveSearch

func BleveSearch(s string, opts ...Option) ([]map[string]any, int64, error)

搜索引擎搜索指定关键字

func CloseAllDbs

func CloseAllDbs()

关闭所有连接

func GetSnowflakeOrderNo

func GetSnowflakeOrderNo() int64

生成雪花订单号

func InitBadger

func InitBadger(opts ...Option)

初始化kV缓存

func InitBleve

func InitBleve(opts ...Option) error

初始化搜索引擎

func InitCasbin

func InitCasbin(csvfile string, sub any)

权限控制初始化

func InitDirectory

func InitDirectory(npath ...string) (string, bool)

初始化指定目录

func InitGormDB

func InitGormDB(opts ...Option)

初始化mysql数据库

func InitPsqlDB

func InitPsqlDB(opts ...Option)

初始化postgresql数据库

func InitRedis

func InitRedis(opts ...Option)

初始化redis数据库

func JwtCreate

func JwtCreate(data map[string]any, opts ...Option) (string, error)

创建JWT加密字串

func JwtValidate

func JwtValidate(tokenString string, opts ...Option) (any, error)

检测JWT加密字串

func MD5

func MD5(str string, is16 bool) string

md5加密

func RsaDecrypt

func RsaDecrypt(ciphertext []byte, opts ...Option) ([]byte, error)

非对称解密

func RsaEncrypt

func RsaEncrypt(origData []byte, opts ...Option) ([]byte, error)

非对称加密

func SHA1

func SHA1(str string) string

sha1加密

func SHA256

func SHA256(data string) string

sha256加密

Types

type Option

type Option func(options *options)

func WithAesKeyAndIv

func WithAesKeyAndIv(key, iv string) Option

func WithCacheFolder

func WithCacheFolder(folderName string) Option

func WithDSN

func WithDSN(dsn string) Option

func WithDbType

func WithDbType(dbtype string) Option

func WithField

func WithField(field string) Option

func WithIdleConns

func WithIdleConns(idleConns int) Option

func WithIndex

func WithIndex(index int) Option

func WithJwtSecureKey

func WithJwtSecureKey(jwtSecureKey string) Option

func WithKeyword

func WithKeyword(keyword string) Option

func WithMaxLifeTime

func WithMaxLifeTime(maxLifeTime int) Option

func WithPage added in v0.0.3

func WithPage(page int) Option

func WithPageSize added in v0.0.3

func WithPageSize(pagesize int) Option

func WithPubicPrivateKey

func WithPubicPrivateKey(publicKey, privateKey string) Option

func WithReturnField

func WithReturnField(field string) Option

func WithSortField added in v0.0.3

func WithSortField(field string) Option

func WithTotal

func WithTotal(total int) Option

func WithTtl

func WithTtl(ttl int) Option

func WithmaxConns

func WithmaxConns(maxConns int) Option

type SseHander

type SseHander struct {
}

func (*SseHander) BoardcaseMap

func (c *SseHander) BoardcaseMap(data map[string]interface{}, tokens ...string) error

广播hashmap

func (*SseHander) BoardcaseText

func (c *SseHander) BoardcaseText(msg string, tokens ...string) error

广播文本

func (*SseHander) Handler

func (c *SseHander) Handler(ctx *gin.Context)

sse处理函数

Jump to

Keyboard shortcuts

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