config_json.go 808 B

12345678910111213141516171819202122232425262728293031323334
  1. package json
  2. //go:generate go run v2ray.com/core/common/errors/errorgen
  3. import (
  4. "io"
  5. "v2ray.com/core"
  6. "v2ray.com/core/common"
  7. "v2ray.com/core/common/cmdarg"
  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. r, err := confloader.LoadExtConfig(v)
  19. if err != nil {
  20. return nil, newError("failed to execute v2ctl to convert config file.").Base(err).AtWarning()
  21. }
  22. return core.LoadConfig("protobuf", "", r)
  23. case io.Reader:
  24. return serial.LoadJSONConfig(v)
  25. default:
  26. return nil, newError("unknow type")
  27. }
  28. },
  29. }))
  30. }