config.go 577 B

123456789101112131415161718192021222324252627282930
  1. package json
  2. import (
  3. "encoding/json"
  4. )
  5. const (
  6. AuthMethodNoAuth = "noauth"
  7. AuthMethodUserPass = "password"
  8. )
  9. type SocksConfig struct {
  10. AuthMethod string `json:"auth"`
  11. Username string `json:"user"`
  12. Password string `json:"pass"`
  13. }
  14. func (config SocksConfig) IsNoAuth() bool {
  15. return config.AuthMethod == AuthMethodNoAuth
  16. }
  17. func (config SocksConfig) IsPassword() bool {
  18. return config.AuthMethod == AuthMethodUserPass
  19. }
  20. func Load(rawConfig []byte) (SocksConfig, error) {
  21. config := SocksConfig{}
  22. err := json.Unmarshal(rawConfig, &config)
  23. return config, err
  24. }