CreateDefaultConfigFileAt writes the default configuration template to the provided path. Parameters: - path: Full path where the config file should be created. This function is safe to call multiple times; if the file already exists it returns the existing path without modifying it. Example usag
(path string)
| 51 | // log.Fatalf("create config: %v", err) |
| 52 | // } |
| 53 | func CreateDefaultConfigFileAt(path string) (string, error) { |
| 54 | if path == "" { |
| 55 | return "", fmt.Errorf("config path cannot be empty") |
| 56 | } |
| 57 | |
| 58 | if _, err := os.Stat(path); err == nil { |
| 59 | return path, nil // File already exists |
| 60 | } |
| 61 | |
| 62 | if err := os.MkdirAll(filepath.Dir(path), 0o750); err != nil { |
| 63 | return "", fmt.Errorf("create config directory: %w", err) |
| 64 | } |
| 65 | |
| 66 | templateData, err := templateFS.ReadFile("config.tpl.yml") |
| 67 | if err != nil { |
| 68 | return "", fmt.Errorf("read template: %w", err) |
| 69 | } |
| 70 | |
| 71 | if err := os.WriteFile(path, templateData, 0o600); err != nil { |
| 72 | return "", fmt.Errorf("write config file: %w", err) |
| 73 | } |
| 74 | |
| 75 | return path, nil |
| 76 | } |
| 77 | |
| 78 | // FindDefaultConfigPath finds the default configuration file path. |
| 79 | func FindDefaultConfigPath() (string, bool) { |
no outgoing calls
no test coverage detected