config.go 609 B

12345678910111213141516171819202122232425262728293031
  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. UDPEnabled bool `json:"udp"`
  14. }
  15. func (config SocksConfig) IsNoAuth() bool {
  16. return config.AuthMethod == AuthMethodNoAuth
  17. }
  18. func (config SocksConfig) IsPassword() bool {
  19. return config.AuthMethod == AuthMethodUserPass
  20. }
  21. func Load(rawConfig []byte) (SocksConfig, error) {
  22. config := SocksConfig{}
  23. err := json.Unmarshal(rawConfig, &config)
  24. return config, err
  25. }