config_json.go 919 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // +build json
  2. package http
  3. import (
  4. "encoding/json"
  5. v2net "github.com/v2ray/v2ray-core/common/net"
  6. "github.com/v2ray/v2ray-core/proxy/internal/config"
  7. )
  8. func (this *Config) UnmarshalJSON(data []byte) error {
  9. type JsonConfig struct {
  10. Hosts []v2net.AddressJson `json:"ownHosts"`
  11. }
  12. jsonConfig := new(JsonConfig)
  13. if err := json.Unmarshal(data, jsonConfig); err != nil {
  14. return err
  15. }
  16. this.OwnHosts = make([]v2net.Address, len(jsonConfig.Hosts), len(jsonConfig.Hosts)+1)
  17. for idx, host := range jsonConfig.Hosts {
  18. this.OwnHosts[idx] = host.Address
  19. }
  20. v2rayHost := v2net.DomainAddress("local.v2ray.com")
  21. if !this.IsOwnHost(v2rayHost) {
  22. this.OwnHosts = append(this.OwnHosts, v2rayHost)
  23. }
  24. return nil
  25. }
  26. func init() {
  27. config.RegisterInboundConfig("http",
  28. func(data []byte) (interface{}, error) {
  29. rawConfig := new(Config)
  30. err := json.Unmarshal(data, rawConfig)
  31. return rawConfig, err
  32. })
  33. }