mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-12-27 21:06:35 +08:00
实现公用的IP名单
This commit is contained in:
48
internal/web/actions/default/ui/showTip.go
Normal file
48
internal/web/actions/default/ui/showTip.go
Normal file
@@ -0,0 +1,48 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package ui
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/iwind/TeaGo"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"io/ioutil"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var tipKeyMap = map[string]bool{}
|
||||
var tipKeyLocker = sync.Mutex{}
|
||||
var tipConfigFile = "tip.json"
|
||||
|
||||
func init() {
|
||||
TeaGo.BeforeStart(func(server *TeaGo.Server) {
|
||||
// 从配置文件中加载已关闭的tips
|
||||
data, err := ioutil.ReadFile(Tea.ConfigFile(tipConfigFile))
|
||||
if err == nil {
|
||||
var m = map[string]bool{}
|
||||
err = json.Unmarshal(data, &m)
|
||||
if err == nil {
|
||||
tipKeyLocker.Lock()
|
||||
tipKeyMap = m
|
||||
tipKeyLocker.Unlock()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
type ShowTipAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *ShowTipAction) RunPost(params struct {
|
||||
Code string
|
||||
}) {
|
||||
tipKeyLocker.Lock()
|
||||
_, ok := tipKeyMap[params.Code]
|
||||
tipKeyLocker.Unlock()
|
||||
|
||||
this.Data["visible"] = !ok
|
||||
|
||||
this.Success()
|
||||
}
|
||||
Reference in New Issue
Block a user