1
0

config.go 528 B

1234567891011121314151617181920212223242526272829303132
  1. package proxy
  2. import (
  3. "bufio"
  4. "encoding/json"
  5. "os"
  6. )
  7. // Config 保存代理服务器的配置
  8. type Config struct {
  9. Port string `json:"port"`
  10. Auth bool `json:"auth"`
  11. User map[string]string `json:"user"`
  12. }
  13. // 从指定json文件读取config配置
  14. func (c *Config) GetConfig(filename string) error {
  15. configFile, err := os.Open(filename)
  16. if err != nil {
  17. return err
  18. }
  19. defer configFile.Close()
  20. br := bufio.NewReader(configFile)
  21. err = json.NewDecoder(br).Decode(c)
  22. if err != nil {
  23. return err
  24. }
  25. return nil
  26. }