github.com/Uhtred009/v2ray-core-1@v4.31.2+incompatible/main/jsonem/jsonem.go (about)

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