Documentation ¶
Overview ¶
Package utils
工具包,提供更好用的常用函数和工具类
Package utils
Index ¶
- Constants
- Variables
- func ArchiveFile(fileName string, dst string, autoClear bool) error
- func Backup(src, back string) error
- func BackupOld(src, back string) error
- func CMDAsync(envs []string, cmd ...string) error
- func CMDRaw(envs []string, cmd ...string) *exec.Cmd
- func CMDRun(envs []string, cmd ...string) (string, error)
- func CMDWithContext(envs []string, cmd ...string) (string, error)
- func CalDir(dirs ...string) string
- func CalcFileSize(s int64) string
- func CalcPathDepth(offsetDir, dir string) int
- func CheckAsync(query *gin.Context) bool
- func ClearFile(f string) error
- func CreateFile(f string) error
- func CreateFileX(f string) error
- func CreateOrCoverFile(f string) error
- func FileExist(p string) bool
- func FileExistOrCreate(p string) error
- func FileNotExist(p string) bool
- func GetAppDir() string
- func GetFileSize(file string) int64
- func ParseBson(file string, r interface{}) error
- func ParseJson(data []byte, m interface{}) error
- func ParseJsonFile(fileName string, m interface{}) error
- func PrettyJson(v interface{}) string
- func RandomPort() int
- func RemoveFile(f string) error
- func Rotate(appLog string) error
- func Save2Json(m interface{}) ([]byte, error)
- func Save2JsonFile(m interface{}, fileName string) error
- func SaveBson(data interface{}, file string) error
- func TimeCalcString(last time.Time) string
- func TimeCalcUnix(last time.Time) int64
- func TimeNowBetterSep() string
- func TimeNowFormat(layout string) string
- func TimeNowString() string
- func TimeNowUnix() int64
- func TimeNowYearDay() string
- func TimeToLocal(t time.Time) time.Time
- type File
Constants ¶
View Source
const ( BASH = "bash" RUN = "-c" )
命令行运行 会开启新的sid 不会和主进程共用终端
View Source
const ( ArchiveType = ".tar.gz" RotateSize = 20 << 20 // 20mb )
View Source
const ( MINPort = 10000 MaxPort = 20000 )
View Source
const ( TimeFormat = "2006/1/2 15:04:05" TimeFormatDay = "2006/1/2" TimeForLogger = "2006-1-2 15:04:05" TimeBetterSep = "2006-1-2-15-04-05" )
View Source
const ( // MaxDepth 可以通过环境变量ApolloMaxDepth自定义 MaxDepth = 5 KB = 1024 MB = 2 << 20 GB = 2 << 30 )
Variables ¶
View Source
var ( BackBase = "backup-%s.zip" // 拼接ServiceRoot BackupFlag = "/var/.backup" BackTmp = "/tmp/Apollo" )
View Source
var ApolloMaxDepth int
Functions ¶
func ArchiveFile ¶
ArchiveFile 打包文件 默认为tar.gz fileName 要打包的文件 dst 要生成的文件名 autoClear 自动清空文件 写时复制 会导致writeToolong 将当前文件备份到tmp后压缩并删除
func CMDWithContext ¶
CMDWithContext 执行结束后会杀死父进程来关闭shell
func CalcPathDepth ¶
CalcPathDepth 计算路径深度 offsetDir 初始目录需要减去这个长度 eg: offset: /code/gen dir: /code/gen/map depth = 4 - 3 = 1
func FileExistOrCreate ¶
func FileNotExist ¶
func PrettyJson ¶
func PrettyJson(v interface{}) string
func RandomPort ¶
func RandomPort() int
func Save2JsonFile ¶
Save2JsonFile 保存为json文件
Types ¶
Click to show internal directories.
Click to hide internal directories.