jsonem.go 861 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package jsonem
  2. import (
  3. "io"
  4. "v2ray.com/core"
  5. "v2ray.com/core/common"
  6. "v2ray.com/core/common/cmdarg"
  7. "v2ray.com/core/infra/conf"
  8. "v2ray.com/core/infra/conf/serial"
  9. "v2ray.com/core/main/confloader"
  10. )
  11. func init() {
  12. common.Must(core.RegisterConfigLoader(&core.ConfigFormat{
  13. Name: "JSON",
  14. Extension: []string{"json"},
  15. Loader: func(input interface{}) (*core.Config, error) {
  16. switch v := input.(type) {
  17. case cmdarg.Arg:
  18. cf := &conf.Config{}
  19. for _, arg := range v {
  20. newError("Reading config: ", arg).AtInfo().WriteToLog()
  21. r, err := confloader.LoadConfig(arg)
  22. common.Must(err)
  23. c, err := serial.DecodeJSONConfig(r)
  24. common.Must(err)
  25. cf.Override(c, arg)
  26. }
  27. return cf.Build()
  28. case io.Reader:
  29. return serial.LoadJSONConfig(v)
  30. default:
  31. return nil, newError("unknow type")
  32. }
  33. },
  34. }))
  35. }