config_json.go 651 B

12345678910111213141516171819202122232425262728
  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/buf"
  8. "v2ray.com/core/common/platform/ctlcmd"
  9. )
  10. func init() {
  11. common.Must(core.RegisterConfigLoader(&core.ConfigFormat{
  12. Name: "JSON",
  13. Extension: []string{"json"},
  14. Loader: func(input io.Reader) (*core.Config, error) {
  15. jsonContent, err := ctlcmd.Run([]string{"config"}, input)
  16. if err != nil {
  17. return nil, newError("failed to execute v2ctl to convert config file.").Base(err).AtWarning()
  18. }
  19. return core.LoadConfig("protobuf", "", &buf.MultiBufferContainer{
  20. MultiBuffer: jsonContent,
  21. })
  22. },
  23. }))
  24. }