mirror of
https://github.com/WJQSERVER-STUDIO/ghproxy.git
synced 2026-02-03 16:21:11 +08:00
46 lines
860 B
Go
46 lines
860 B
Go
package auth
|
|
|
|
import (
|
|
"encoding/json"
|
|
"ghproxy/config"
|
|
"os"
|
|
)
|
|
|
|
type Config struct {
|
|
Blacklist []string `json:"blacklist"`
|
|
}
|
|
|
|
var (
|
|
cfg *config.Config
|
|
configfile = "/data/ghproxy/config/config.yaml"
|
|
blacklistfile = "/data/ghproxy/config/blacklist.json"
|
|
blacklist *Config
|
|
)
|
|
|
|
func init() {
|
|
blacklist = &Config{}
|
|
|
|
data, err := os.ReadFile(blacklistfile)
|
|
if err != nil {
|
|
logw("Failed to read blacklist file: %v", err)
|
|
}
|
|
|
|
err = json.Unmarshal(data, blacklist)
|
|
if err != nil {
|
|
logw("Failed to unmarshal blacklist JSON: %v", err)
|
|
}
|
|
}
|
|
|
|
func CheckBlacklist(fullrepo string) bool {
|
|
return forRangeCheck(blacklist.Blacklist, fullrepo)
|
|
}
|
|
|
|
func forRangeCheck(blist []string, fullrepo string) bool {
|
|
for _, blocked := range blist {
|
|
if blocked == fullrepo {
|
|
return true
|
|
}
|
|
}
|
|
logw("%s not in blacklist", fullrepo)
|
|
return false
|
|
}
|