This commit is contained in:
WJQSERVER 2024-10-06 01:36:52 +08:00
parent c78d114767
commit d33377087f
3 changed files with 24 additions and 26 deletions

View file

@ -1,44 +1,38 @@
package auth package auth
import ( import (
"fmt" "encoding/json"
"ghproxy/config" "ghproxy/config"
"log" "os"
) )
type Config struct {
Blacklist []string `json:"blacklist"`
}
var ( var (
cfg *config.Config cfg *config.Config
configfile = "/data/ghproxy/config/config.yaml" configfile = "/data/ghproxy/config/config.yaml"
blacklist *config.Blist blacklistfile = "/data/ghproxy/config/blacklist.json"
blacklist *Config
) )
func init() { func init() {
loadBlacklistConfig() blacklist = &Config{}
data, err := os.ReadFile(blacklistfile)
if err != nil {
logw("Failed to read blacklist file: %v", err)
} }
func loadConfig() { err = json.Unmarshal(data, blacklist)
var err error
// 初始化配置
cfg, err = config.LoadConfig(configfile)
if err != nil { if err != nil {
log.Fatalf("Failed to load config: %v", err) logw("Failed to unmarshal blacklist JSON: %v", err)
} }
fmt.Printf("Loaded config: %v\n", cfg)
}
func loadBlacklistConfig() {
var err error
// 初始化黑名单配置
blacklist, err = config.LoadBlacklistConfig(cfg.Blacklist.BlacklistFile)
if err != nil {
log.Fatalf("Failed to load blacklist: %v", err)
}
logw("Loaded blacklist: %v", blacklist)
} }
func CheckBlacklist(fullrepo string) bool { func CheckBlacklist(fullrepo string) bool {
forRangeCheck(blacklist.Blacklist, fullrepo) return forRangeCheck(blacklist.Blacklist, fullrepo)
return false
} }
func forRangeCheck(blist []string, fullrepo string) bool { func forRangeCheck(blist []string, fullrepo string) bool {

8
config/blacklist.json Normal file
View file

@ -0,0 +1,8 @@
{
"blacklist": [
"test/test1",
"example/repo2",
"another/repo3"
]
}

View file

@ -1,4 +0,0 @@
blacklist:
- test/test1
- example/repo2
- another/repo3