mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-11-09 10:43:47 +08:00
发布v2.4.4版本,本次为优化版本。更新内容请查看:https://github.com/bufanyun/hotgo/blob/v2.0/docs/guide-zh-CN/start-update-log.md
This commit is contained in:
@@ -116,7 +116,7 @@ func (l *gCurd) initInput(ctx context.Context, in *CurdPreviewInput) (err error)
|
||||
return err
|
||||
}
|
||||
|
||||
initStep(ctx, in)
|
||||
initStep(in)
|
||||
in.options.dictMap = make(g.Map)
|
||||
|
||||
if len(in.Config.Application.Crud.Templates)-1 < in.In.GenTemplate {
|
||||
@@ -138,7 +138,7 @@ func (l *gCurd) initInput(ctx context.Context, in *CurdPreviewInput) (err error)
|
||||
return
|
||||
}
|
||||
|
||||
func initStep(ctx context.Context, in *CurdPreviewInput) {
|
||||
func initStep(in *CurdPreviewInput) {
|
||||
in.options.Step = new(CurdStep)
|
||||
in.options.Step.HasMaxSort = HasMaxSort(in.masterFields)
|
||||
in.options.Step.HasAdd = gstr.InArray(in.options.HeadOps, "add")
|
||||
@@ -642,7 +642,7 @@ func (l *gCurd) generateWebViewContent(ctx context.Context, in *CurdPreviewInput
|
||||
func (l *gCurd) generateSqlContent(ctx context.Context, in *CurdPreviewInput) (err error) {
|
||||
var (
|
||||
name = "source.sql"
|
||||
config = g.DB(in.In.DbName).GetConfig()
|
||||
config = g.DB("default").GetConfig()
|
||||
tplData = g.Map{
|
||||
"dbName": config.Name,
|
||||
"menuTable": config.Prefix + "admin_menu",
|
||||
@@ -652,7 +652,7 @@ func (l *gCurd) generateSqlContent(ctx context.Context, in *CurdPreviewInput) (e
|
||||
)
|
||||
|
||||
if in.options.Menu.Pid > 0 {
|
||||
tplData["mainComponent"] = "ParentLayout" //gstr.LcFirst(in.In.VarName)
|
||||
tplData["mainComponent"] = "ParentLayout"
|
||||
}
|
||||
|
||||
genFile.Path = file.MergeAbs(in.Config.Application.Crud.Templates[in.In.GenTemplate].SqlPath, convert.CamelCaseToUnderline(in.In.VarName)+"_menu.sql")
|
||||
|
||||
@@ -54,10 +54,6 @@ type WhoisRegionData struct {
|
||||
|
||||
// WhoisLocation 通过Whois接口查询IP归属地
|
||||
func WhoisLocation(ctx context.Context, ip string) (*IpLocationData, error) {
|
||||
if !validate.IsIp(ip) {
|
||||
return nil, fmt.Errorf("invalid input ip:%v", ip)
|
||||
}
|
||||
|
||||
response, err := g.Client().Timeout(10*time.Second).Get(ctx, whoisApi+ip)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -90,10 +86,6 @@ func WhoisLocation(ctx context.Context, ip string) (*IpLocationData, error) {
|
||||
|
||||
// Cz88Find 通过Cz88的IP库查询IP归属地
|
||||
func Cz88Find(ctx context.Context, ip string) (*IpLocationData, error) {
|
||||
if !validate.IsIp(ip) {
|
||||
return nil, fmt.Errorf("invalid input ip:%v", ip)
|
||||
}
|
||||
|
||||
loc, err := iploc.OpenWithoutIndexes("./resource/ip/qqwry-utf8.dat")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%v for help, please go to: https://github.com/kayon/iploc", err.Error())
|
||||
@@ -129,6 +121,13 @@ func IsJurisByIpTitle(title string) bool {
|
||||
|
||||
// GetLocation 获取IP归属地信息
|
||||
func GetLocation(ctx context.Context, ip string) (*IpLocationData, error) {
|
||||
if !validate.IsIp(ip) {
|
||||
return nil, fmt.Errorf("invalid input ip:%v", ip)
|
||||
}
|
||||
|
||||
if validate.IsLocalIPAddr(ip) {
|
||||
return nil, fmt.Errorf("must be a public ip:%v", ip)
|
||||
}
|
||||
method := g.Cfg().MustGet(ctx, "hotgo.ipMethod", "cz88")
|
||||
if method.String() == "whois" {
|
||||
return WhoisLocation(ctx, ip)
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package tcp
|
||||
|
||||
import "github.com/gogf/gf/v2/os/gtime"
|
||||
|
||||
// 定时任务
|
||||
const (
|
||||
cronHeartbeatVerify = "tcpHeartbeatVerify"
|
||||
cronHeartbeat = "tcpHeartbeat"
|
||||
cronAuthVerify = "tcpAuthVerify"
|
||||
)
|
||||
|
||||
// 认证分组
|
||||
@@ -15,10 +18,11 @@ const (
|
||||
|
||||
// AuthMeta 认证元数据
|
||||
type AuthMeta struct {
|
||||
Group string `json:"group"`
|
||||
Name string `json:"name"`
|
||||
AppId string `json:"appId"`
|
||||
SecretKey string `json:"secretKey"`
|
||||
Group string `json:"group"`
|
||||
Name string `json:"name"`
|
||||
AppId string `json:"appId"`
|
||||
SecretKey string `json:"secretKey"`
|
||||
EndAt *gtime.Time `json:"-"`
|
||||
}
|
||||
|
||||
// CallbackEvent 回调事件
|
||||
|
||||
@@ -27,9 +27,24 @@ func (server *Server) startCron() {
|
||||
for _, client := range server.clients {
|
||||
if client.heartbeat < gtime.Timestamp()-300 {
|
||||
client.Conn.Close()
|
||||
server.Logger.Debugf(server.Ctx, "client heartbeat timeout, about to reconnect.. auth:%+v", client.Auth)
|
||||
server.Logger.Debugf(server.Ctx, "client heartbeat timeout, close conn. auth:%+v", client.Auth)
|
||||
}
|
||||
}
|
||||
}, server.getCronKey(cronHeartbeatVerify))
|
||||
}
|
||||
|
||||
// 认证检查
|
||||
if gcron.Search(server.getCronKey(cronAuthVerify)) == nil {
|
||||
gcron.AddSingleton(server.Ctx, "@every 300s", func(ctx context.Context) {
|
||||
if server.clients == nil {
|
||||
return
|
||||
}
|
||||
for _, client := range server.clients {
|
||||
if client.Auth.EndAt.Before(gtime.Now()) {
|
||||
client.Conn.Close()
|
||||
server.Logger.Debugf(server.Ctx, "client auth expired, close conn. auth:%+v", client.Auth)
|
||||
}
|
||||
}
|
||||
}, server.getCronKey(cronAuthVerify))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,6 +107,7 @@ func (server *Server) onServerLogin(args ...interface{}) {
|
||||
Name: in.Name,
|
||||
AppId: in.AppId,
|
||||
SecretKey: models.SecretKey,
|
||||
EndAt: models.EndAt,
|
||||
},
|
||||
heartbeat: gtime.Timestamp(),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user