lib

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2026 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const IPPrefix = "192.168.194"

Variables

This section is empty.

Functions

func Base64FromFile

func Base64FromFile(path string) (string, string, error)

Base64FromFile 读入文件并使用Base64编码 并且计算MD5

func ConvertFtoS

func ConvertFtoS(src float64) string

ConvertFtoS 将浮点数转化为字符串 原封不动的转

func CopyStruct

func CopyStruct(src, dst interface{})

CopyStruct 结构体深度复制

func CreateCaptcha

func CreateCaptcha(bit int) string

CreateCaptcha 产生跟时间戳相关的随机数字符串 bit代表位数

func DecimalOneDigit

func DecimalOneDigit(value float64) string

DecimalOneDigit 生成报告中格式化一位小数的字符串带百分号

func EnsureDir

func EnsureDir(dirName string) error

EnsureDir 确保路径存在

func Exists

func Exists(path string) bool

Exists 判断给定路径的文件是否存在

func ExternalIP

func ExternalIP() (res []string)

func GetCurrentAbPathByCaller

func GetCurrentAbPathByCaller() string

GetCurrentAbPathByCaller 获取当前项目绝对路径

func GetCurrentDirectory

func GetCurrentDirectory() string

GetCurrentDirectory 获得当前程序目录

func GetIP

func GetIP() string

func GetLocalIP

func GetLocalIP()

GetLocalIP 获取本机IP地址

func GetParentDirectory

func GetParentDirectory(dirctory string) string

GetParentDirectory 获得父目录

func GetTypeFullName

func GetTypeFullName(myvar interface{}) string

GetType 获得类型的名称

func Getenv

func Getenv(key, fallback string) string

Getenv 获取环境变量的值 如果为空则将第二个参数作为默认值

func HealthCheckHandler

func HealthCheckHandler(w http.ResponseWriter, r *http.Request)

HealthCheckHandler 构造httptest http头

func IPS

func IPS() (ips []string)

func IsDev deprecated

func IsDev() bool

IsDev 判断当前是否开发环境。读取 cloudbrainMode 环境变量;未设置时默认 dev(旧逻辑会 log.Fatal, 但作为 library 不应让进程退出,已改为返回 true 以保持向后兼容)。

Deprecated: 推荐改用 Kratos config 的环境变量注入(KRATOS_ENV)或业务侧自行判断。

func IsMobile

func IsMobile(mobile string) bool

判断是不是真实手机号码

func RandStringBytesMaskImprSrcUnsafe

func RandStringBytesMaskImprSrcUnsafe(n int) string

func RandStringRunes

func RandStringRunes(n int) string

RandStringRunes 随机

func Unzip

func Unzip(zipPath, extractDir string) error

解压

func UploadMultipartFile

func UploadMultipartFile(client *http.Client, uri, key, path string, headers map[string]string) (*http.Response, error)

UploadMultipartFile 上传文件

func VerifyEmailFormat

func VerifyEmailFormat(email string) bool

VerifyEmailFormat 验证邮箱格式是否正确

func VerifyMobileFormat

func VerifyMobileFormat(mobileNum string) bool

VerifyMobileFormat 验证手机号格式是否正确

func VerifyMongoErr deprecated

func VerifyMongoErr(err error) bool

VerifyMongoErr 已废弃:原本用于判断 mongo 的空文档/空游标错误。 已移除 mongo-driver 依赖;若业务仍需要,请在业务侧自行 errors.Is 判断。

Deprecated: gocommon 不再绑定 mongo-driver,请在业务侧自行处理。

func Zip

func Zip(zipPath string, paths ...string) error

创建zip压缩文件

Types

type Config deprecated

type Config interface {
	Get(string) string
	GetInt(string) int
	GetBool(string) bool
}

Config 旧版配置接口。

Deprecated: 改用 conf.Loader.Scan(&Bootstrap{})。

func ReadConfigMap deprecated

func ReadConfigMap(filePath string) Config

ReadConfigMap 兼容老调用方:按 IsDev() 走 dev / prod 分支。

Deprecated: 改用 conf.Load。

func ReadConfigMapDev deprecated

func ReadConfigMapDev(filePath string) Config

ReadConfigMapDev 读取开发环境的 ConfigMap YAML 文件。

Deprecated: 改用 conf.Load。

func ReadConfigMapProd deprecated

func ReadConfigMapProd(filePath string) Config

ReadConfigMapProd 读取生产环境的 key=value 文本配置。

Deprecated: 改用 conf.Load。

type ConfigMap deprecated

type ConfigMap map[string]map[string]string

ConfigMap 旧版配置在内存中的存储结构。

Deprecated: 改用 conf.Load。

func (*ConfigMap) Get deprecated

func (c *ConfigMap) Get(key string) string

Get 通过 "module.key" 形式取值;env 后缀按 IsDev() 自动选择。

Deprecated: 改用 conf.Loader.Value(...).String()。

func (*ConfigMap) GetBool deprecated

func (c *ConfigMap) GetBool(key string) bool

GetBool 取 bool;解析失败返回 false + 日志。

Deprecated: 改用 conf.Loader.Value(...).Bool()。

func (*ConfigMap) GetInt deprecated

func (c *ConfigMap) GetInt(key string) int

GetInt 取 int;解析失败返回 0 + 日志。

Deprecated: 改用 conf.Loader.Value(...).Int()。

Directories

Path Synopsis
Package conf 提供基于 Kratos config 的统一配置加载入口。
Package conf 提供基于 Kratos config 的统一配置加载入口。

Jump to

Keyboard shortcuts

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