MCPcopy Create free account
hub / github.com/0xUnixIO/pulse / loadConfig

Method loadConfig

internal/ipsentinel/nodehandler.go:36–71  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

34}
35
36func (h *NodeHandler) loadConfig() (Config, error) {
37 h.cfgMu.RLock()
38 if h.cfgCache != nil {
39 cfg := *h.cfgCache
40 h.cfgMu.RUnlock()
41 return cfg, nil
42 }
43 h.cfgMu.RUnlock()
44
45 h.cfgMu.Lock()
46 defer h.cfgMu.Unlock()
47
48 // 二次检查,防止并发写入
49 if h.cfgCache != nil {
50 return *h.cfgCache, nil
51 }
52
53 data, err := os.ReadFile(h.configFilePath())
54 if os.IsNotExist(err) {
55 return Config{
56 LangParams: "hl=en&gl=US",
57 ValidURLSuffix: "com",
58 }, nil
59 }
60 if err != nil {
61 return Config{}, err
62 }
63
64 var cfg Config
65 if err := json.Unmarshal(data, &cfg); err != nil {
66 return Config{}, err
67 }
68 cfgCopy := cfg
69 h.cfgCache = &cfgCopy
70 return cfg, nil
71}
72
73func (h *NodeHandler) saveConfig(cfg Config) error {
74 if err := os.MkdirAll(h.dataDir, 0o750); err != nil {

Callers 4

DispatchMethod · 0.95
handleDetectGoogleMethod · 0.95
handleRunMethod · 0.95
handleGetConfigMethod · 0.95

Calls 1

configFilePathMethod · 0.95

Tested by

no test coverage detected