z_mirror/pesticide
git clone https://git.raiguard.me/z_mirror/pesticide
9c1a93d
trunk
1package config 2 3import ( 4"encoding/json" 5"errors" 6"os" 7) 8 9type Config struct { 10Adapters map [string ]AdapterConfig 11} 12 13type AdapterConfig struct { 14Cmd * string 15Args json.RawMessage 16Addr * string 17ID string `json:",omitempty"` 18} 19 20func New (path string )Config { 21file ,err := os .ReadFile (path ) 22if err != nil { 23panic (err ) 24 } 25var config Config 26if err = json .Unmarshal (file ,& config );err != nil { 27panic (err ) 28 } 29 30if len (config .Adapters )== 0 { 31panic (errors .New ("No adapters were specified" )) 32 } 33for id ,adapter := range config .Adapters { 34if adapter .Addr == nil && adapter .Cmd == nil { 35panic (errors .New ("Adapters must have an address or command to run" )) 36 } 37if adapter .Cmd != nil { 38expanded := os .ExpandEnv (* adapter .Cmd ) 39adapter .Cmd = & expanded 40 } 41adapter .ID = id 42config .Adapters [id ]= adapter 43 } 44return config 45}