chore: 并入 iotlcm-app 历史到 app/(原提交 f40bda9)

This commit is contained in:
MiFaZhan
2026-11-02 13:28:00 +08:00
1107 changed files with 147143 additions and 0 deletions
@@ -0,0 +1,59 @@
package inithttp
import (
"context"
"sync"
"github.com/gogf/gf/v2/frame/g"
)
var (
httpInitFunc map[string]func(ctx context.Context) error
httpCleanupFunc map[string]func(ctx context.Context) error
rwLock sync.RWMutex
)
func RegisterHttpInitFunc(name string, fn func(ctx context.Context) error) {
rwLock.Lock()
defer rwLock.Unlock()
if httpInitFunc == nil {
httpInitFunc = make(map[string]func(ctx context.Context) error)
}
httpInitFunc[name] = fn
}
func RegisterHttpCleanupFunc(name string, fn func(ctx context.Context) error) {
rwLock.Lock()
defer rwLock.Unlock()
if httpCleanupFunc == nil {
httpCleanupFunc = make(map[string]func(ctx context.Context) error)
}
httpCleanupFunc[name] = fn
}
func InitHttp(ctx context.Context) error {
rwLock.RLock()
defer rwLock.RUnlock()
for name, fn := range httpInitFunc {
if err := fn(ctx); err != nil {
g.Log().Errorf(ctx, "httpInitFunc %s error: %v", name, err)
return err
} else {
g.Log().Infof(ctx, "httpInitFunc %s success", name)
}
}
return nil
}
func CleanupHttp(ctx context.Context) error {
rwLock.RLock()
defer rwLock.RUnlock()
for name, fn := range httpCleanupFunc {
if err := fn(ctx); err != nil {
g.Log().Errorf(ctx, "httpCleanupFunc %s error: %v", name, err)
} else {
g.Log().Infof(ctx, "httpCleanupFunc %s success", name)
}
}
return nil
}