| package main | |
| import ( | |
| "encoding/json" | |
| "os" | |
| "path/filepath" | |
| ) | |
| type Config struct { | |
| Token string `json:"token"` | |
| Host string `json:"host"` | |
| Username string `json:"username"` | |
| LoggedInAt string `json:"loggedInAt"` | |
| LastDeployedID string `json:"lastDeployedId,omitempty"` | |
| OpenAIKey string `json:"openai_key,omitempty"` | |
| } | |
| func getConfigPath() string { | |
| home, _ := os.UserHomeDir() | |
| profile := parsedArgs.Get("--profile", "-pr") | |
| if profile != "" { | |
| return filepath.Join(home, ".ie-research-cli-"+profile+".json") | |
| } | |
| return filepath.Join(home, ".ie-research-cli.json") | |
| } | |
| func loadConfig() (*Config, error) { | |
| envToken := os.Getenv("IE_TOKEN") | |
| if envToken != "" { | |
| host := os.Getenv("IE_HOST") | |
| if host == "" { | |
| host = DefaultHost | |
| } | |
| return &Config{ | |
| Token: envToken, | |
| Host: host, | |
| Username: "env_user", | |
| }, nil | |
| } | |
| path := getConfigPath() | |
| if _, err := os.Stat(path); os.IsNotExist(err) { | |
| return nil, err | |
| } | |
| data, err := os.ReadFile(path) | |
| if err != nil { | |
| return nil, err | |
| } | |
| var cfg Config | |
| if err := json.Unmarshal(data, &cfg); err != nil { | |
| return nil, err | |
| } | |
| return &cfg, nil | |
| } | |
| func saveConfig(cfg *Config) error { | |
| path := getConfigPath() | |
| data, err := json.MarshalIndent(cfg, "", " ") | |
| if err != nil { | |
| return err | |
| } | |
| return os.WriteFile(path, data, 0600) | |
| } | |
Xet Storage Details
- Size:
- 1.34 kB
- Xet hash:
- 10992a44fbc5bee51146c92741cb1ede64f5a3c6c80bfae524e3b597069ac0f9
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.