github.com/imannamdari/v2ray-core/v5@v5.0.5/main/commands/all/merge_doc.go (about) 1 package all 2 3 import ( 4 "github.com/imannamdari/v2ray-core/v5/main/commands/base" 5 ) 6 7 var docMerge = &base.Command{ 8 UsageLine: "{{.Exec}} config-merge", 9 Short: "config merge logic", 10 Long: ` 11 Merging of config files is applied in following commands: 12 13 {{.Exec}} run -c c1.json -c c2.json ... 14 {{.Exec}} test -c c1.yaml -c c2.yaml ... 15 {{.Exec}} convert c1.json dir1 ... 16 {{.Exec}} api ado c1.json dir1 ... 17 {{.Exec}} api rmi c1.json dir1 ... 18 ... and more ... 19 20 Support of toml and yaml is implemented by converting them to json, 21 both merge and load. So we take json as example here. 22 23 Suppose we have 2 JSON files, 24 25 The 1st one: 26 27 { 28 "log": {"access": "some_value", "loglevel": "debug"}, 29 "inbounds": [{"tag": "in-1"}], 30 "outbounds": [{"_priority": 100, "tag": "out-1"}], 31 "routing": {"rules": [ 32 {"_tag":"default_route","inboundTag":["in-1"],"outboundTag":"out-1"} 33 ]} 34 } 35 36 The 2nd one: 37 38 { 39 "log": {"loglevel": "error"}, 40 "inbounds": [{"tag": "in-2"}], 41 "outbounds": [{"_priority": -100, "tag": "out-2"}], 42 "routing": {"rules": [ 43 {"inboundTag":["in-2"],"outboundTag":"out-2"}, 44 {"_tag":"default_route","inboundTag":["in-1.1"],"outboundTag":"out-1.1"} 45 ]} 46 } 47 48 Output: 49 50 { 51 // loglevel is overwritten 52 "log": {"access": "some_value", "loglevel": "error"}, 53 "inbounds": [{"tag": "in-1"}, {"tag": "in-2"}], 54 "outbounds": [ 55 {"tag": "out-2"}, // note the order is affected by priority 56 {"tag": "out-1"} 57 ], 58 "routing": {"rules": [ 59 // note 3 rules are merged into 2, and outboundTag is overwritten, 60 // because 2 of them has same tag 61 {"inboundTag":["in-1","in-1.1"],"outboundTag":"out-1.1"} 62 {"inboundTag":["in-2"],"outboundTag":"out-2"} 63 ]} 64 } 65 66 Explained: 67 68 - Simple values (string, number, boolean) are overwritten, others are merged 69 - Elements with same "tag" (or "_tag") in an array will be merged 70 - Add "_priority" property to array elements will help sort the array 71 `, 72 }