mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-11-15 13:43:48 +08:00
发布v2.15.1版本,更新内容请查看:https://github.com/bufanyun/hotgo/blob/v2.0/docs/guide-zh-CN/start-update-log.md
This commit is contained in:
@@ -47,6 +47,11 @@ func GetModelTable(m *gdb.Model) (tablesInit, tables string) {
|
||||
return
|
||||
}
|
||||
|
||||
// EscapeFieldsToSlice 将转义过的字段转换为字段集切片
|
||||
func EscapeFieldsToSlice(s string) []string {
|
||||
return gstr.Explode(",", gstr.Replace(gstr.Replace(s, "`,`", ","), "`", ""))
|
||||
}
|
||||
|
||||
// GetMapKeys 获取map的所有key
|
||||
func GetMapKeys[K comparable](m map[K]any) []K {
|
||||
j := 0
|
||||
|
||||
@@ -19,6 +19,7 @@ import (
|
||||
"net/url"
|
||||
"reflect"
|
||||
"time"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -53,6 +54,7 @@ func ExportByStructs(ctx context.Context, tags []string, list interface{}, fileN
|
||||
widthRow = v
|
||||
}
|
||||
}
|
||||
|
||||
if err = f.SetColWidth(sheetName, "A", widthRow, 30); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -75,18 +77,19 @@ func ExportByStructs(ctx context.Context, tags []string, list interface{}, fileN
|
||||
}
|
||||
}
|
||||
|
||||
// 强转类型
|
||||
writer := ghttp.RequestFromCtx(ctx).Response.Writer
|
||||
w, ok := interface{}(writer).(*ghttp.ResponseWriter)
|
||||
if !ok {
|
||||
return gerror.New("Response.Writer uninitialized!")
|
||||
r := ghttp.RequestFromCtx(ctx)
|
||||
if r == nil {
|
||||
err = gerror.New("ctx not http request")
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/octet-stream")
|
||||
w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=%s.xlsx", url.QueryEscape(fileName)))
|
||||
w.Header().Set("Content-Transfer-Encoding", "binary")
|
||||
w.Header().Set("Access-Control-Expose-Headers", "Content-Disposition")
|
||||
|
||||
if err = f.Write(w); err != nil {
|
||||
writer := r.Response.Writer
|
||||
writer.Header().Set("Content-Type", "application/octet-stream")
|
||||
writer.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=%s.xlsx", url.QueryEscape(fileName)))
|
||||
writer.Header().Set("Content-Transfer-Encoding", "binary")
|
||||
writer.Header().Set("Access-Control-Expose-Headers", "Content-Disposition")
|
||||
|
||||
if err = f.Write(writer); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -103,7 +106,7 @@ func ExportByStructs(ctx context.Context, tags []string, list interface{}, fileN
|
||||
// letter 生成完整的表头
|
||||
func letter(length int) []string {
|
||||
var str []string
|
||||
for i := 0; i < length; i++ {
|
||||
for i := 1; i <= length; i++ {
|
||||
str = append(str, numToChars(i))
|
||||
}
|
||||
return str
|
||||
@@ -123,3 +126,15 @@ func numToChars(num int) string {
|
||||
}
|
||||
return cols
|
||||
}
|
||||
|
||||
// NextLetter 传入一个字母,获取下一个字母
|
||||
func NextLetter(input string) string {
|
||||
if len(input) == 0 {
|
||||
return ""
|
||||
}
|
||||
upperInput := unicode.ToUpper(rune(input[0]))
|
||||
if upperInput >= 'A' && upperInput < 'Z' {
|
||||
return string(upperInput + 1)
|
||||
}
|
||||
return "A"
|
||||
}
|
||||
|
||||
@@ -13,17 +13,10 @@ import (
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
"github.com/gogf/gf/v2/os/glog"
|
||||
"github.com/gogf/gf/v2/os/grpool"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"hotgo/internal/consts"
|
||||
"hotgo/utility/encrypt"
|
||||
)
|
||||
|
||||
// AppName 应用名称
|
||||
func AppName(ctx context.Context) string {
|
||||
return g.Cfg().MustGet(ctx, "appName", "hotgo").String()
|
||||
}
|
||||
|
||||
// RouterPrefix 获取应用路由前缀
|
||||
func RouterPrefix(ctx context.Context, app string) string {
|
||||
return g.Cfg().MustGet(ctx, "router."+app+".prefix", "/"+app+"").String()
|
||||
@@ -35,7 +28,7 @@ func FilterMaskDemo(ctx context.Context, src g.Map) g.Map {
|
||||
return nil
|
||||
}
|
||||
|
||||
if !g.Cfg().MustGet(ctx, "hotgo.isDemo", false).Bool() {
|
||||
if !IsDemo(ctx) {
|
||||
return src
|
||||
}
|
||||
|
||||
@@ -82,22 +75,14 @@ func CheckPassword(input, salt, hash string) (err error) {
|
||||
}
|
||||
|
||||
// SafeGo 安全的调用协程,遇到错误时输出错误日志而不是抛出panic
|
||||
func SafeGo(ctx context.Context, f func(ctx context.Context), lv ...interface{}) {
|
||||
var level = glog.LEVEL_ERRO
|
||||
if len(lv) > 0 {
|
||||
level = gconv.Int(lv[0])
|
||||
}
|
||||
|
||||
err := grpool.AddWithRecover(ctx, func(ctx context.Context) {
|
||||
f(ctx)
|
||||
}, func(ctx context.Context, err error) {
|
||||
func SafeGo(ctx context.Context, f func(ctx context.Context), lv ...int) {
|
||||
g.Go(ctx, f, func(ctx context.Context, err error) {
|
||||
var level = glog.LEVEL_ERRO
|
||||
if len(lv) > 0 {
|
||||
level = lv[0]
|
||||
}
|
||||
Logf(level, ctx, "SafeGo exec failed:%+v", err)
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
Logf(level, ctx, "SafeGo AddWithRecover err:%+v", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func Logf(level int, ctx context.Context, format string, v ...interface{}) {
|
||||
|
||||
31
server/utility/simple/system_config.go
Normal file
31
server/utility/simple/system_config.go
Normal file
@@ -0,0 +1,31 @@
|
||||
// Package simple
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2024 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package simple
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
// AppName 应用名称
|
||||
func AppName(ctx context.Context) string {
|
||||
return g.Cfg().MustGet(ctx, "system.appName", "hotgo").String()
|
||||
}
|
||||
|
||||
// Debug debug
|
||||
func Debug(ctx context.Context) bool {
|
||||
return g.Cfg().MustGet(ctx, "system.debug", true).Bool()
|
||||
}
|
||||
|
||||
// IsDemo 是否为演示系统
|
||||
func IsDemo(ctx context.Context) bool {
|
||||
return g.Cfg().MustGet(ctx, "system.isDemo", true).Bool()
|
||||
}
|
||||
|
||||
// IsCluster 是否为集群部署
|
||||
func IsCluster(ctx context.Context) bool {
|
||||
return g.Cfg().MustGet(ctx, "system.isCluster", true).Bool()
|
||||
}
|
||||
32
server/utility/tree/tree_list.go
Normal file
32
server/utility/tree/tree_list.go
Normal file
@@ -0,0 +1,32 @@
|
||||
// Package tree
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2024 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package tree
|
||||
|
||||
type Node interface {
|
||||
ID() int64 // 获取节点ID
|
||||
PID() int64 // 获取父级节点ID
|
||||
SetChildren(children []Node) // 设置子节点数据
|
||||
}
|
||||
|
||||
// ListToTree 根据上下级关系将列表数据转为树状数据
|
||||
func ListToTree(pid int64, nodes []Node) (list []Node, err error) {
|
||||
for _, v := range nodes {
|
||||
if v.PID() == pid {
|
||||
item := v
|
||||
|
||||
// 递归添加子节点
|
||||
child, err := ListToTree(v.ID(), nodes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(child) > 0 {
|
||||
item.SetChildren(child)
|
||||
}
|
||||
list = append(list, item)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user