|
| @@ -73,34 +73,36 @@ func readAndUnmarshalConfig(filePath string, config *Config) error { |
| 73 | | return yaml.Unmarshal(configData, config) | 73 | | return yaml.Unmarshal(configData, config) |
| 74 | | } | 74 | | } |
| 75 | | | 75 | | |
| 76 | - | // LoadClientConfig loads the client configuration. | | | |
| 77 | | func (config *Config) LoadClientConfig() (*Config, error) { | 76 | | func (config *Config) LoadClientConfig() (*Config, error) { |
| 78 | | configDir, configFilePath := configPath() | 77 | | configDir, configFilePath := configPath() |
| 79 | | | 78 | | |
| 80 | - | if err := os.MkdirAll(configDir, 0755); err != nil { | 79 | + | err := os.MkdirAll(configDir, 0755) |
| | | 80 | + | if err != nil { |
| 81 | | return nil, fmt.Errorf("error creating configuration directory: %w", err) | 81 | | return nil, fmt.Errorf("error creating configuration directory: %w", err) |
| 82 | | } | 82 | | } |
| 83 | | | 83 | | |
| 84 | - | // Check if the file exists | 84 | + | _, err = os.Stat(configFilePath) |
| 85 | - | if _, err := os.Stat(configFilePath); os.IsNotExist(err) { | 85 | + | if os.IsNotExist(err) { |
| 86 | | fmt.Printf("Config file not found, creating it at %s\n", configFilePath) | 86 | | fmt.Printf("Config file not found, creating it at %s\n", configFilePath) |
| 87 | | | 87 | | |
| 88 | - | // Prompt user for initial settings | 88 | + | config.Http.BackendURL = readUserInput("Enter the backend URL (e.g. https://gordon.mydomain.com):") |
| 89 | - | config.Http.BackendURL = readUserInput("Enter the backend URL:") | 89 | + | config.General.GordonToken = readUserInput("Enter the token (check your backend config.yml):") |
| 90 | - | config.General.GordonToken = readUserInput("Enter the Gordon token:") | | | |
| 91 | | | 90 | | |
| 92 | - | // Save the new configuration | 91 | + | err = config.SaveConfig() |
| 93 | - | if err := config.SaveConfig(); err != nil { | 92 | + | if err != nil { |
| 94 | | return nil, fmt.Errorf("error saving new configuration: %w", err) | 93 | | return nil, fmt.Errorf("error saving new configuration: %w", err) |
| 95 | | } | 94 | | } |
| 96 | - | } else if err != nil { | 95 | + | |
| 97 | - | // Some other error occurred while checking the file | 96 | + | return config, nil |
| | | 97 | + | } |
| | | 98 | + | |
| | | 99 | + | if err != nil { |
| 98 | | return nil, fmt.Errorf("error checking configuration file: %w", err) | 100 | | return nil, fmt.Errorf("error checking configuration file: %w", err) |
| 99 | - | } else { | 101 | + | } |
| 100 | - | // File exists, read and unmarshal it | 102 | + | |
| 101 | - | if err := readAndUnmarshalConfig(configFilePath, config); err != nil { | 103 | + | err = readAndUnmarshalConfig(configFilePath, config) |
| 102 | - | return nil, err | 104 | + | if err != nil { |
| 103 | - | } | 105 | + | return nil, err |
| 104 | | } | 106 | | } |
| 105 | | | 107 | | |
| 106 | | return config, nil | 108 | | return config, nil |