config_json.go 573 B

12345678910111213141516171819202122232425
  1. package json
  2. //go:generate errorgen
  3. import (
  4. "io"
  5. "v2ray.com/core"
  6. "v2ray.com/core/common"
  7. "v2ray.com/core/common/platform/ctlcmd"
  8. )
  9. func init() {
  10. common.Must(core.RegisterConfigLoader(&core.ConfigFormat{
  11. Name: "JSON",
  12. Extension: []string{"json"},
  13. Loader: func(input io.Reader) (*core.Config, error) {
  14. jsonContent, err := ctlcmd.Run([]string{"config"}, input)
  15. if err != nil {
  16. return nil, newError("failed to execute v2ctl to convert config file.").Base(err).AtWarning()
  17. }
  18. return core.LoadConfig("protobuf", "", &jsonContent)
  19. },
  20. }))
  21. }