hosts.go 311 B

1234567891011121314151617181920212223
  1. package main
  2. import (
  3. "encoding/json"
  4. "os"
  5. "sync"
  6. )
  7. var (
  8. HOSTS = make(map[string][]string)
  9. LOCKER = new(sync.Mutex)
  10. )
  11. func InitSites() error {
  12. LOCKER.Lock()
  13. defer LOCKER.Unlock()
  14. f, e := os.Open(*HOSTS_FILE)
  15. if e != nil {
  16. return e
  17. }
  18. defer f.Close()
  19. return json.NewDecoder(f).Decode(&HOSTS)
  20. }