This commit is contained in:
gotoeasy 2023-10-15 21:07:59 +08:00
parent bf24ad13fd
commit 574c748089
8 changed files with 16 additions and 19 deletions

View File

@ -84,14 +84,6 @@ func GetDirInfo(path string) (uint32, int64, error) {
return count, size, err
}
// 按M或G单位显示
func GetSizeInfo(size uint64) string {
if size > 1024*1024*1024 {
return fmt.Sprintf("%.1fG", float64(size)/1024/1024/1024)
}
return fmt.Sprintf("%.1fM", float64(size)/1024/1024)
}
// 当前日期加减天数后的yyyymmdd格式
func GetYyyymmdd(days int) string {
return time.Now().AddDate(0, 0, days).Format("20060102")

View File

@ -48,7 +48,6 @@ var enableCors bool
var pageSize int
func init() {
cmn.SetLogLevel(cmn.GetEnvStr("GLC_LOG_LEVEL", "INFO")) // 默认INFO级别日志
UpdateConfigByEnv()
// 在这个地方建目录,如果创建失败就比较难看,比如仅命令行查看版本的情景

View File

@ -6,7 +6,7 @@ require (
github.com/gin-contrib/cors v1.4.0
github.com/gin-contrib/gzip v0.0.6
github.com/gin-gonic/gin v1.9.1
github.com/gotoeasy/glang v0.9.8
github.com/gotoeasy/glang v0.10.10
github.com/shirou/gopsutil v3.21.11+incompatible
github.com/streadway/amqp v1.1.0
github.com/syndtr/goleveldb v1.0.0

View File

@ -266,6 +266,8 @@ github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWm
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gotoeasy/glang v0.9.8 h1:NaSM2AGyMM0NsEF4iLFGrp3sy5YUx/ln2VV6coClpLY=
github.com/gotoeasy/glang v0.9.8/go.mod h1:yfd1MWPdZMKF6yykUxAFkEyPTgf+lxlSfOCyxjS5sXI=
github.com/gotoeasy/glang v0.10.10 h1:yle2A/j+Vi2zFx6OimJSqFgm6cQGyk32FueJ27QvO9o=
github.com/gotoeasy/glang v0.10.10/go.mod h1:yfd1MWPdZMKF6yykUxAFkEyPTgf+lxlSfOCyxjS5sXI=
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
github.com/grpc-ecosystem/grpc-gateway v1.5.0/go.mod h1:RSKVYQBd5MCa4OVpNdGskqpgL2+G+NZTnrVHpWWfpdw=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=

View File

@ -13,17 +13,17 @@ import (
func Test_CutWords(t *testing.T) {
ws := tokenizer.CutForSearch("小明硕士毕业于中国科学院计算所后在日本京都大学深造Java和Go都学得不错Java和Go都不错的")
cmn.Println(ws)
cmn.Debug(ws)
}
func Test_GetIP(t *testing.T) {
cmn.Println(com.GetLocalIp())
cmn.Debug(com.GetLocalIp())
}
func Test_GetSubDirs(t *testing.T) {
rs := sysmnt.GetStorageList()
for i := 0; i < len(rs.Data); i++ {
cmn.Println(rs.Data[i])
cmn.Debug(rs.Data[i])
}
}
@ -47,9 +47,9 @@ func Test_all(t *testing.T) {
// time.Sleep(time.Duration(5) * time.Second)
rs := engine.Search(` them java `, "", "", "", "", make([]string, 0), 0, true)
cmn.Println("共查到", rs.Total, "件")
cmn.Debug("共查到", rs.Total, "件")
for _, v := range rs.Data {
cmn.Println(v.Id, v.Text)
cmn.Debug(v.Id, v.Text)
}
}

View File

@ -53,7 +53,7 @@ func GetStorageList() *StorageResult {
}
cnt, size, _ := com.GetDirInfo(conf.GetStorageRoot() + cmn.PathSeparator() + name)
d.TotalSize = com.GetSizeInfo(uint64(size))
d.TotalSize = cmn.GetSizeInfo(uint64(size))
d.FileCount = cnt
sum += size
@ -73,7 +73,7 @@ func GetStorageList() *StorageResult {
stat, _ := disk.Usage(conf.GetStorageRoot())
rs := &StorageResult{
Info: fmt.Sprintf("共占用空间 " + com.GetSizeInfo(uint64(sum)) + ",剩余空间 " + com.GetSizeInfo(stat.Free)),
Info: fmt.Sprintf("共占用空间 " + cmn.GetSizeInfo(uint64(sum)) + ",剩余空间 " + cmn.GetSizeInfo(stat.Free)),
Data: datas,
}
return rs

View File

@ -4,9 +4,13 @@ import (
"glc/conf"
"glc/onstart"
"runtime"
"github.com/gotoeasy/glang/cmn"
)
func main() {
cmn.SetGlcClient(cmn.NewGlcClient(&cmn.GlcOptions{Enable: false, LogLevel: "INFO"})) // 控制台INFO日志级别输出
runtime.GOMAXPROCS(conf.GetGoMaxProcess()) // 使用最大CPU数量
onstart.Run()
}

View File

@ -44,12 +44,12 @@ func StorageDeleteController(req *gweb.HttpRequest) *gweb.HttpResult {
if conf.GetSaveDays() > 0 {
ymd := cmn.Right(name, 8)
if cmn.Len(ymd) == 8 && cmn.Startwiths(ymd, "20") {
msg := fmt.Sprintf("当前是日志仓自动维护模式,最多保存 %d 天,不手动删除", conf.GetSaveDays())
msg := fmt.Sprintf("当前是日志仓自动维护模式,最多保存 %d 天,不支持手动删除", conf.GetSaveDays())
return gweb.Error500(msg)
}
}
} else if name == "logdata" {
return gweb.Error500("不能删除当前使用的唯一日志仓 " + "logdata")
return gweb.Error500("日志仓 " + name + " 正在使用,不能删除")
}
if status.IsStorageOpening(name) {