pkg

package module
v2.0.61 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultTagName   = "json"
	DefaultDescTag   = "description"
	DefaultPageSize  = 5000
	DefaultSheetSize = 100000
	DefaultLimitSize = 100000
	DefaultSheetName = "Sheet"
)
View Source
const (
	UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36"
)

Variables

This section is empty.

Functions

func CheckExist

func CheckExist(src string) bool

CheckExist 检查文件是否存在

func CheckPermission

func CheckPermission(src string) bool

CheckPermission 检查文件权限

func DefaultFieldFunc

func DefaultFieldFunc(obj any, tag string) []string

func DefaultHeaderFunc

func DefaultHeaderFunc(ctx context.Context, l LangFunc, excel *excelize.File, fieldList []string, translateMap map[string]string) (headerCols []interface{}, err error)

func DefaultStatusFunc

func DefaultStatusFunc(ctx context.Context, l LangFunc, fieldList []string, translateMap map[string]string) (statusEnums map[string]map[string]string)

func DefaultTranslateFunc

func DefaultTranslateFunc(obj any, tag, desc string) map[string]string

func Dsn

func Dsn(m *Mysql) string

func FileCreate

func FileCreate(content bytes.Buffer, name string)

func FileMonitoringById

func FileMonitoringById(ctx context.Context, filePth string, id string, group string, hookfn func(context.Context, string, string, []byte))

func Get

func Get() []string

func GetCurrentPath

func GetCurrentPath() string

GetCurrentPath 获取当前路径,比如:E:/abc/data/test

func GetDBType

func GetDBType(link string) string

func GetExt

func GetExt(fileName string) string

GetExt 获取文件后缀

func GetFileSize

func GetFileSize(filename string) int64

GetFileSize 获取文件大小

func GetImgType

func GetImgType(p string) (string, error)

GetImgType 获取Img文件类型

func GetLocalHost

func GetLocalHost() string

GetLocalHost 获取局域网ip地址

func GetLocation

func GetLocation(ctx context.Context, ip string) string

GetLocation 获取外网ip地址

func GetNonEmptyFields

func GetNonEmptyFields(obj interface{}, tagName string) (map[string]any, error)

GetNonEmptyFields returns a map of non-empty fields of a struct

func GetSize

func GetSize(f multipart.File) (int, error)

GetSize 获取文件大小

func GetTags

func GetTags(obj any, tagName string) []string

GetTags returns a slice of any tags of a struct

func GetTagsMap

func GetTagsMap(obj any, tagName, vTagName string) map[string]string

GetTagsMap returns a map of any tags of a struct

func GetType

func GetType(p string) (string, error)

GetType 获取文件类型

func HasLocalIP added in v2.0.13

func HasLocalIP(ip net.IP) bool

HasLocalIP 检测 IP 地址是否是内网地址 通过直接对比ip段范围效率更高

func HasLocalIPAddr added in v2.0.13

func HasLocalIPAddr(ip string) bool

HasLocalIPAddr 检测 IP 地址字符串是否是内网地址

func InSlice

func InSlice(needle string, haystack []string) bool

InSlice returns true if the needle string is found in the haystack slice

func IsNotExistMkDir

func IsNotExistMkDir(src string) error

IsNotExistMkDir 检查文件夹是否存在 如果不存在则新建文件夹

func IsSlice

func IsSlice(obj any) bool

func MkDir

func MkDir(src string) error

MkDir 新建文件夹

func Open

func Open(name string, flag int, perm os.FileMode) (*os.File, error)

Open 打开文件

func PathCreate

func PathCreate(dir string) error

func PathExist

func PathExist(addr string) bool

PathExist 判断目录是否存在

func Round

func Round(f float64, n int) float64

func SaveUploadedFile

func SaveUploadedFile(file *multipart.FileHeader, dst string) error

SaveUploadedFile uploads the form file to specific dst.

func WithExportOptionsDescTag

func WithExportOptionsDescTag(tag string) func(*ExportOptions)

func WithExportOptionsErrorFunc

func WithExportOptionsErrorFunc(f ErrorFunc) func(*ExportOptions)

func WithExportOptionsFieldFunc

func WithExportOptionsFieldFunc(f FieldFunc) func(*ExportOptions)

func WithExportOptionsFileName

func WithExportOptionsFileName(fileName string) func(*ExportOptions)

func WithExportOptionsFinishFunc

func WithExportOptionsFinishFunc(f FinishFunc) func(*ExportOptions)

func WithExportOptionsGraphicOptions

func WithExportOptionsGraphicOptions(g *GraphicOptions) func(*ExportOptions)

func WithExportOptionsHeaderFunc

func WithExportOptionsHeaderFunc(f HeaderFunc) func(*ExportOptions)

func WithExportOptionsI18n

func WithExportOptionsI18n(i18n *gi18n.Manager) func(*ExportOptions)

func WithExportOptionsLimitSize

func WithExportOptionsLimitSize(limit int) func(*ExportOptions)

func WithExportOptionsListFunc

func WithExportOptionsListFunc(f ListFunc) func(*ExportOptions)

func WithExportOptionsPageSize

func WithExportOptionsPageSize(pageSize int) func(*ExportOptions)

func WithExportOptionsParamsFunc

func WithExportOptionsParamsFunc(f RawFunc) func(*ExportOptions)

func WithExportOptionsPictureFunc

func WithExportOptionsPictureFunc(f PictureFunc) func(*ExportOptions)

func WithExportOptionsPictureKeys

func WithExportOptionsPictureKeys(keys []string) func(*ExportOptions)

func WithExportOptionsSheetPrefix

func WithExportOptionsSheetPrefix(prefix string) func(*ExportOptions)

func WithExportOptionsSheetSize

func WithExportOptionsSheetSize(sheetSize int) func(*ExportOptions)

func WithExportOptionsStatusFunc

func WithExportOptionsStatusFunc(f StatusFunc) func(*ExportOptions)

func WithExportOptionsSummaryFunc

func WithExportOptionsSummaryFunc(f RawFunc) func(*ExportOptions)

func WithExportOptionsTagName

func WithExportOptionsTagName(tag string) func(*ExportOptions)

func WithExportOptionsTotalFunc

func WithExportOptionsTotalFunc(f TotalFunc) func(*ExportOptions)

func WithExportOptionsTranslateFunc

func WithExportOptionsTranslateFunc(f TranslateFunc) func(*ExportOptions)

Types

type Bucket added in v2.0.30

type Bucket[T any] struct {
	Mu  sync.Locker
	Idx int
	M   map[string]T
}

Bucket 通用安全桶

func (*Bucket[T]) Del added in v2.0.30

func (b *Bucket[T]) Del(key string)

func (*Bucket[T]) Get added in v2.0.30

func (b *Bucket[T]) Get(key string) T

func (*Bucket[T]) Has added in v2.0.30

func (b *Bucket[T]) Has(key string) bool

func (*Bucket[T]) Index added in v2.0.30

func (b *Bucket[T]) Index() int

func (*Bucket[T]) Len added in v2.0.30

func (b *Bucket[T]) Len() int

func (*Bucket[T]) Set added in v2.0.31

func (b *Bucket[T]) Set(key string, item T)

type ErrorFunc

type ErrorFunc func(ctx context.Context, err error) error

type Export

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

func NewExport

func NewExport(ctx context.Context, optionFuncs ...func(*ExportOptions)) *Export

func (*Export) Run

func (e *Export) Run() (err error)

type ExportOptions

type ExportOptions struct {
	FileName      string
	PageSize      int
	SheetSize     int
	LimitSize     int
	SheetPrefix   string
	TagName       string
	DescTag       string
	PictureKeys   []string
	FieldFunc     FieldFunc
	TranslateFunc TranslateFunc
	StatusFunc    StatusFunc
	HeaderFunc    HeaderFunc
	TotalFunc     TotalFunc
	ListFunc      ListFunc
	SummaryFunc   RawFunc
	ParamsFunc    RawFunc
	FinishFunc    FinishFunc
	ErrorFunc     ErrorFunc
	PictureFunc   PictureFunc

	GraphicOptions *GraphicOptions
	// contains filtered or unexported fields
}

type FieldFunc

type FieldFunc func(ctx context.Context) []string

type FinishFunc

type FinishFunc func(ctx context.Context) error

type GraphicOptions

type GraphicOptions excelize.GraphicOptions

type HeaderFunc

type HeaderFunc func(ctx context.Context, excel *excelize.File) ([]interface{}, error)

type LangFunc

type LangFunc func(ctx context.Context, key string) string

type ListFunc

type ListFunc func(ctx context.Context, page, pageSize int) ([]interface{}, error)

type LocationResp

type LocationResp struct {
	Status      string  `json:"status"` // success
	Country     string  `json:"country"`
	CountryCode string  `json:"countryCode"`
	Region      string  `json:"region"`
	RegionName  string  `json:"regionName"`
	City        string  `json:"city"`
	Zip         string  `json:"zip"`
	Lat         float64 `json:"lat"`
	Lon         float64 `json:"lon"`
	Timezone    string  `json:"timezone"`
	Isp         string  `json:"isp"`
	Org         string  `json:"org"`
	As          string  `json:"as"`
	Query       string  `json:"query"`
}

type Mysql

type Mysql struct {
	Path          string `json:"path" yaml:"path"`
	Config        string `json:"config" yaml:"config"`
	Dbname        string `json:"dbname" yaml:"db-name"`
	Username      string `json:"username" yaml:"username"`
	Password      string `json:"password" yaml:"password"`
	MaxIdleConnes int    `json:"maxIdleConnes" yaml:"max-idle-connes"`
	MaxOpenConnes int    `json:"maxOpenConnes" yaml:"max-open-connes"`
	LogMode       bool   `json:"logMode" yaml:"log-mode"`
	LogZap        string `json:"logZap" yaml:"log-zap"`
}
func GetByLink(link string) Mysql

type OpenId added in v2.0.15

type OpenId struct {
	Key  string `json:"key"`   // 密匙
	KeyA string `json:"key_a"` // 密匙a会参与加解密
	KeyB string `json:"key_b"` // 密匙b会用来做数据完整性验证
	//KeyC   string `json:"key_c"`  // 密匙c用于变化生成的密文
	Salt   string `json:"salt"`   // salt
	Expiry int    `json:"expiry"` // 过期时间
	KeyLen int    `json:"key_len"`
}

func NewOpenId added in v2.0.15

func NewOpenId(keyA, keyB, salt string) *OpenId

func NewOpenIdWithKey added in v2.0.15

func NewOpenIdWithKey(key string) *OpenId

func (*OpenId) Decode added in v2.0.15

func (s *OpenId) Decode(OpenID string) (string, error)

func (*OpenId) Encode added in v2.0.15

func (s *OpenId) Encode(userId int64) (string, error)

type PictureFunc

type PictureFunc func(ctx context.Context, url string) string

type RawFunc

type RawFunc func(ctx context.Context) (any, error)

type RawStruct

type RawStruct struct {
	FieldList   []string
	HeaderCols  []interface{}
	StatusEnums map[string]map[string]string
	Obj         any
}

type ReplaceHelper

type ReplaceHelper struct {
	Root    string //路径
	OldText string //需要替换的文本
	NewText string //新的文本
}

func (*ReplaceHelper) DoWork

func (h *ReplaceHelper) DoWork() error

type StatusFunc

type StatusFunc func(ctx context.Context) map[string]map[string]string

type TotalFunc

type TotalFunc func(ctx context.Context) (int, error)

type TranslateFunc

type TranslateFunc func(ctx context.Context) map[string]string

Directories

Path Synopsis
ratelimit
ip
tus
filelocker
Package filelocker provide an upload locker based on the local file system.
Package filelocker provide an upload locker based on the local file system.
filestore
Package filestore provide a storage backend based on the local file system.
Package filestore provide a storage backend based on the local file system.
memorylocker
Package memorylocker provides an in-memory locking mechanism.
Package memorylocker provides an in-memory locking mechanism.
uid

Jump to

Keyboard shortcuts

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