Documentation
¶
Index ¶
- Constants
- func AddDuration(d time.Duration) int64
- func AesDecrypt(key, ciphertext []byte) (buf []byte, err error)
- func AesEncrypt(key, plaintext []byte) (buf []byte, err error)
- func BytesToString(b []byte) string
- func CalculateAge(birthday time.Time) int
- func CalculateFileHash(filePath string) (string, error)
- func CheckValue(db *gorm.DB, key, defaultValue, format string, autoload, public bool)
- func CleanText(s string, opts *Options) string
- func ConfigureConnectionPool(db *gorm.DB)
- func CopyFile(src, dst string) error
- func Difference[T comparable](slice1, slice2 []T) []T
- func EndOfDay(t time.Time) time.Time
- func EnsureDirectory(path string) error
- func FileExists(path string) bool
- func GenerateID() string
- func GetBoolEnv(key string) bool
- func GetBoolValue(db *gorm.DB, key string) bool
- func GetContentType(suffix string) (tp string)
- func GetCrc16(val int64) uint16
- func GetDistance(lon1, lat1, lon2, lat2 float64) float64
- func GetEnv(key string) string
- func GetFileSize(filePath string) (int64, error)
- func GetFileType(buf []byte) (fileType string)
- func GetFileTypeBySuffix(suffix string) int32
- func GetFloatEnv(key string) float64
- func GetFloatEnvWithDefault(key string, defaultValue float64) float64
- func GetIntEnv(key string) int64
- func GetIntEnvWithDefault(key string, defaultValue int) int
- func GetIntValue(db *gorm.DB, key string, defaultVal int) int
- func GetLocationByIP(ip string) (country, city, location string)
- func GetLocationByIPWithPconline(ip string) (country, city, location string)
- func GetRealAddressByIP(ip string) string
- func GetValue(db *gorm.DB, key string) string
- func InArray[T comparable](needle T, haystack []T) bool
- func InitDatabase(logWrite io.Writer, driver, dsn string) (*gorm.DB, error)
- func InitGlobalCache(maxSize int, expiration time.Duration)
- func Intersect[T comparable](slice1, slice2 []T) []T
- func IsDirectory(path string) bool
- func IsFile(path string) bool
- func IsInternalIP(ip string) bool
- func Join[T any](arg []T, str string) string
- func LoadAutoloads(db *gorm.DB)
- func LoadEnv(env string) error
- func LoadEnvs(objPtr any)
- func LookupEnv(key string) (value string, found bool)
- func MD5(str string) string
- func MakeMigrates(db *gorm.DB, insts []any) error
- func Merge[T any](slice1, slice2 []T) []T
- func MillisFromTime(t time.Time) int64
- func NowUnix() int64
- func RC4Decrypt(str string, key []byte) string
- func RC4Encrypt(str string, key []byte) string
- func ReadFile(filename string) ([]byte, error)
- func RemoveDirectory(path string) error
- func RemoveFile(path string) error
- func SetIPServiceLogger(logger *zap.Logger)
- func SetIPServiceTimeout(timeout time.Duration)
- func SetValue(db *gorm.DB, key, value, format string, autoload, public bool)
- func SixteenMD5(str string) string
- func StartOfDay(t time.Time) time.Time
- func StringToBytes(s string) []byte
- func TimeFromMillis(millis int64) time.Time
- func UnZlib(in []byte) (out []byte)
- func Unique[T comparable](slice []T) []T
- func WriteFile(filename string, data []byte) error
- func Yesterday() time.Time
- func Zlib(in []byte) (out []byte)
- type Config
- type ExpiredLRUCache
- type IPGeolocationResponse
- type IPLocationResponse
- type IPLocationService
- type Options
- type Snowflake
Constants ¶
const ( ENV_CONFIG_CACHE_SIZE = "CONFIG_CACHE_SIZE" ENV_CONFIG_CACHE_EXPIRED = "CONFIG_CACHE_EXPIRED" )
const ( // PCONLINE_IP_URL IP地址查询API(国内) PCONLINE_IP_URL = "http://whois.pconline.com.cn/ipJson.jsp" // IP_API_URL IP地址查询API(国际) IP_API_URL = "http://ip-api.com/json/" // UNKNOWN 未知地址 UNKNOWN = "Unknown" // INTERNAL_IP 内网IP标识 INTERNAL_IP = "内网IP" // LOCAL_NETWORK 本地网络 LOCAL_NETWORK = "Local Network" )
const ( FILE_TYPE_IMAGE int32 = 3 FILE_TYPE_FILE int32 = 4 FILE_TYPE_AUDIO int32 = 5 FILE_TYPE_MEDIA int32 = 6 )
const ENV_DB_DRIVER = "DB_DRIVER"
const ENV_DSN = "DSN"
Variables ¶
This section is empty.
Functions ¶
func AddDuration ¶
func AesDecrypt ¶
func AesEncrypt ¶
func CalculateAge ¶
func CalculateFileHash ¶
CalculateFileHash 计算文件的SHA1哈希
func CheckValue ¶
func ConfigureConnectionPool ¶
ConfigureConnectionPool configure database connection pool
func Difference ¶
func Difference[T comparable](slice1, slice2 []T) []T
Difference get difference set slice1-intersection
func GetBoolEnv ¶
func GetContentType ¶
func GetDistance ¶
GetDistance Calculate distance between two points
func GetFileType ¶
func GetFileTypeBySuffix ¶
func GetFloatEnv ¶
func GetFloatEnvWithDefault ¶
GetFloatEnvWithDefault gets float environment variable with default value
func GetIntEnvWithDefault ¶
GetIntEnvWithDefault gets int environment variable with default value
func GetLocationByIP ¶
GetLocationByIP 根据IP获取地理位置信息(国家、城市、完整位置)
func GetLocationByIPWithPconline ¶
GetLocationByIPWithPconline 使用pconline API获取IP地理位置(国内IP更准确)
func GetRealAddressByIP ¶
GetRealAddressByIP 根据IP获取真实地址(兼容旧接口,返回完整地址字符串)
func InArray ¶
func InArray[T comparable](needle T, haystack []T) bool
InArray check if element is in array
func InitGlobalCache ¶
func LoadAutoloads ¶
func MillisFromTime ¶
func RC4Decrypt ¶
func RC4Encrypt ¶
func SetIPServiceLogger ¶
SetIPServiceLogger 设置IP服务的logger
func SetIPServiceTimeout ¶
SetIPServiceTimeout 设置IP服务的超时时间
func SixteenMD5 ¶
func TimeFromMillis ¶
Types ¶
type Config ¶
type Config struct {
ID uint `json:"id" gorm:"primaryKey"`
Key string `json:"key" gorm:"size:128;uniqueIndex"`
Desc string `json:"desc" gorm:"size:200"`
Autoload bool `json:"autoload" gorm:"index"`
Public bool `json:"public" gorm:"index" default:"false"`
Format string `json:"format" gorm:"size:20" default:"text" comment:"json,yaml,int,float,bool,text"`
Value string
CreatedAt time.Time `json:"-" gorm:"autoCreateTime"`
UpdatedAt time.Time `json:"-" gorm:"autoUpdateTime"`
}
func LoadPublicConfigs ¶
type ExpiredLRUCache ¶
type ExpiredLRUCache[K comparable, V any] struct { *lru.Cache[K, expiredLRUCacheValue[V]] // contains filtered or unexported fields }
var GlobalCache *ExpiredLRUCache[string, any]
GlobalCache is a global cache instance that supports generic key-value pairs
func NewExpiredLRUCache ¶
func NewExpiredLRUCache[K comparable, V any](size int, expired time.Duration) *ExpiredLRUCache[K, V]
func (*ExpiredLRUCache[K, V]) Add ¶
func (c *ExpiredLRUCache[K, V]) Add(key K, value V) (evicted bool)
func (*ExpiredLRUCache[K, V]) Contains ¶
func (c *ExpiredLRUCache[K, V]) Contains(key K) bool
func (*ExpiredLRUCache[K, V]) Get ¶
func (c *ExpiredLRUCache[K, V]) Get(key K) (value V, ok bool)
func (*ExpiredLRUCache[K, V]) Remove ¶
func (c *ExpiredLRUCache[K, V]) Remove(key K) (present bool)
type IPGeolocationResponse ¶
type IPGeolocationResponse struct {
Country string `json:"country"`
CountryCode string `json:"countryCode"`
Region string `json:"region"`
City string `json:"city"`
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"`
Status string `json:"status"`
Message string `json:"message"`
}
IPGeolocationResponse IP地理位置API响应(ip-api格式)
type IPLocationResponse ¶
IPLocationResponse IP地理位置查询响应结构(pconline格式)
type IPLocationService ¶
type IPLocationService struct {
// contains filtered or unexported fields
}
IPLocationService IP地理位置服务
func NewIPLocationService ¶
func NewIPLocationService(logger *zap.Logger) *IPLocationService
NewIPLocationService 创建IP地理位置服务
func NewIPLocationServiceWithPconline ¶
func NewIPLocationServiceWithPconline(logger *zap.Logger) *IPLocationService
NewIPLocationServiceWithPconline 创建使用pconline API的IP地理位置服务(国内IP更准确)
func (*IPLocationService) GetLocation ¶
func (ils *IPLocationService) GetLocation(ip string) (country, city, location string, err error)
GetLocation 获取IP地理位置(返回国家、城市、完整位置字符串)
type Snowflake ¶
type Snowflake struct {
// contains filtered or unexported fields
}
var SnowflakeUtil *Snowflake