File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -34,6 +34,18 @@ API_BASE_URL=https://your-unraid-server:port/graphql
3434API_SKIP_TLS_VERIFY=true
3535```
3636
37+ It also supports a config file located at ` ~/.config/unraidctl/config.json ` with the following format:
38+
39+ ``` json
40+ {
41+ "api" : {
42+ "api_key" : " <apikey>" ,
43+ "base_url" : " https://<unraid>:<port>/graphql" ,
44+ "skip_tls_verify" : true
45+ }
46+ }
47+ ```
48+
3749Once installed, you can run commands like:
3850
3951``` bash
Original file line number Diff line number Diff line change 11package internal
22
33import (
4+ "encoding/json"
5+ "os"
6+ "path/filepath"
7+
48 "github.com/caarlos0/env/v11"
59 "github.com/joho/godotenv"
610)
711
812type Config struct {
913 Api struct {
10- BaseUrl string `env:"BASE_URL,required"`
11- ApiKey string `env:"KEY,required"`
12- SkipTlsVerify bool `env:"SKIP_TLS_VERIFY" envDefault:"true"`
13- } `envPrefix:"API_"`
14+ BaseUrl string `env:"BASE_URL,required" json:"base_url" `
15+ ApiKey string `env:"KEY,required" json:"api_key" `
16+ SkipTlsVerify bool `env:"SKIP_TLS_VERIFY" envDefault:"true" json:"skip_tls_verify" `
17+ } `envPrefix:"API_" json:"api" `
1418}
1519
1620func GetConfig () (* Config , error ) {
1721 _ = godotenv .Load ()
18- config , err := env .ParseAs [Config ]()
19- return & config , err
22+
23+ cfg := & Config {}
24+
25+ home , err := os .UserHomeDir ()
26+ if err != nil {
27+ return nil , err
28+ }
29+
30+ jsonPath := filepath .Join (home , ".config" , "unraidctl" , "config.json" )
31+ if b , err := os .ReadFile (jsonPath ); err == nil {
32+ err = json .Unmarshal (b , cfg )
33+ if err != nil {
34+ return nil , err
35+ }
36+
37+ return cfg , nil
38+ }
39+
40+ if err := env .Parse (cfg ); err != nil {
41+ return nil , err
42+ }
43+ return cfg , nil
2044}
You can’t perform that action at this time.
0 commit comments