Skip to content

Commit 53db1b3

Browse files
committed
fix: fmt
1 parent 98da583 commit 53db1b3

File tree

22 files changed

+316
-114
lines changed

22 files changed

+316
-114
lines changed

cmd/code.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ func runCode(cmd *cobra.Command, args []string) error {
4848

4949
// Track reference count
5050
procMgr.IncrementRef()
51+
5152
defer func() {
5253
procMgr.DecrementRef()
5354
// Only stop service if we started it and no more references
@@ -69,12 +70,14 @@ func runCode(cmd *cobra.Command, args []string) error {
6970

7071
func filterEnv(env []string, key string) []string {
7172
var filtered []string
73+
7274
prefix := key + "="
7375
for _, e := range env {
7476
if !startsWith(e, prefix) {
7577
filtered = append(filtered, e)
7678
}
7779
}
80+
7881
return filtered
7982
}
8083

cmd/config.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,23 +64,28 @@ func runConfigInit(cmd *cobra.Command, _ []string) error {
6464

6565
// Get provider details
6666
fmt.Print("\nProvider Name (e.g., openrouter, openai): ")
67+
6768
providerName, _ := reader.ReadString('\n')
6869
providerName = strings.TrimSpace(providerName)
6970

7071
fmt.Print("API Key: ")
72+
7173
apiKey, _ := reader.ReadString('\n')
7274
apiKey = strings.TrimSpace(apiKey)
7375

7476
fmt.Print("API Base URL: ")
77+
7578
baseURL, _ := reader.ReadString('\n')
7679
baseURL = strings.TrimSpace(baseURL)
7780

7881
fmt.Print("Default Model: ")
82+
7983
model, _ := reader.ReadString('\n')
8084
model = strings.TrimSpace(model)
8185

8286
// Optional router API key
8387
fmt.Print("Router API Key (optional, for authentication): ")
88+
8489
routerAPIKey, _ := reader.ReadString('\n')
8590
routerAPIKey = strings.TrimSpace(routerAPIKey)
8691

@@ -135,9 +140,11 @@ func runConfigShow(cmd *cobra.Command, _ []string) error {
135140
if cfgMgr.HasYAML() {
136141
configType = "YAML"
137142
}
143+
138144
fmt.Printf(" %-15s: %s\n", "Format", configType)
139145

140146
fmt.Println("\nProviders:")
147+
141148
for _, provider := range cfg.Providers {
142149
fmt.Printf(" - Name: %s\n", provider.Name)
143150
fmt.Printf(" URL: %s\n", provider.APIBase)
@@ -146,26 +153,33 @@ func runConfigShow(cmd *cobra.Command, _ []string) error {
146153
if len(provider.DefaultModels) > 0 {
147154
fmt.Printf(" Default Models: %v\n", provider.DefaultModels)
148155
}
156+
149157
if len(provider.ModelWhitelist) > 0 {
150158
fmt.Printf(" Model Whitelist: %v\n", provider.ModelWhitelist)
151159
}
160+
152161
if len(provider.Models) > 0 {
153162
fmt.Printf(" Models: %v\n", provider.Models)
154163
}
164+
155165
fmt.Println()
156166
}
157167

158168
fmt.Println("Router Configuration:")
159169
fmt.Printf(" %-15s: %s\n", "Default", cfg.Router.Default)
170+
160171
if cfg.Router.Think != "" {
161172
fmt.Printf(" %-15s: %s\n", "Think", cfg.Router.Think)
162173
}
174+
163175
if cfg.Router.Background != "" {
164176
fmt.Printf(" %-15s: %s\n", "Background", cfg.Router.Background)
165177
}
178+
166179
if cfg.Router.LongContext != "" {
167180
fmt.Printf(" %-15s: %s\n", "Long Context", cfg.Router.LongContext)
168181
}
182+
169183
if cfg.Router.WebSearch != "" {
170184
fmt.Printf(" %-15s: %s\n", "Web Search", cfg.Router.WebSearch)
171185
}
@@ -175,7 +189,7 @@ func runConfigShow(cmd *cobra.Command, _ []string) error {
175189

176190
func runConfigValidate(cmd *cobra.Command, _ []string) error {
177191
if !cfgMgr.Exists() {
178-
return fmt.Errorf("no configuration found")
192+
return errors.New("no configuration found")
179193
}
180194

181195
cfg, err := cfgMgr.Load()
@@ -194,9 +208,11 @@ func runConfigValidate(cmd *cobra.Command, _ []string) error {
194208
if provider.Name == "" {
195209
errors = append(errors, fmt.Sprintf("provider %d: name is required", i))
196210
}
211+
197212
if provider.APIBase == "" {
198213
errors = append(errors, fmt.Sprintf("provider %d: API base URL is required", i))
199214
}
215+
200216
if provider.APIKey == "" {
201217
errors = append(errors, fmt.Sprintf("provider %d: API key is required", i))
202218
}
@@ -208,13 +224,16 @@ func runConfigValidate(cmd *cobra.Command, _ []string) error {
208224

209225
if len(errors) > 0 {
210226
color.Red("Configuration validation failed:")
227+
211228
for _, err := range errors {
212229
fmt.Printf(" - %s\n", err)
213230
}
214-
return fmt.Errorf("configuration validation failed")
231+
232+
return errors.New("configuration validation failed")
215233
}
216234

217235
color.Green("Configuration is valid!")
236+
218237
return nil
219238
}
220239

@@ -230,6 +249,7 @@ func runConfigGenerate(cmd *cobra.Command, _ []string) error {
230249

231250
color.Yellow("Configuration file already exists (%s format): %s", configType, cfgMgr.GetPath())
232251
color.Cyan("Use --force to overwrite, or 'cco config show' to view current config")
252+
233253
return nil
234254
}
235255

@@ -259,8 +279,10 @@ func maskString(s string) string {
259279
if s == "" {
260280
return "(not set)"
261281
}
282+
262283
if len(s) <= 8 {
263284
return strings.Repeat("*", len(s))
264285
}
286+
265287
return s[:4] + strings.Repeat("*", len(s)-8) + s[len(s)-4:]
266288
}

cmd/root.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func init() {
3434

3535
// Setup directories with backward compatibility
3636
var err error
37+
3738
homeDir, err = os.UserHomeDir()
3839
if err != nil {
3940
logger.Error("Failed to get home directory", "error", err)
@@ -77,6 +78,7 @@ func getConfigDirectory(homeDir string) string {
7778
color.Yellow("Using existing configuration directory: %s", oldDir)
7879
color.Cyan("Consider migrating to the new directory: %s", newDir)
7980
color.Cyan("You can do this by running: mv %s %s", oldDir, newDir)
81+
8082
return oldDir
8183
}
8284

@@ -97,6 +99,7 @@ func directoryHasConfig(dir string) bool {
9799
if _, err := os.Stat(yamlConfig); err == nil {
98100
return true
99101
}
102+
100103
if _, err := os.Stat(jsonConfig); err == nil {
101104
return true
102105
}
@@ -140,14 +143,17 @@ func ensureConfigExists() error {
140143
color.Green("No configuration file found, but CCO_API_KEY is set - using minimal configuration")
141144
return nil
142145
}
146+
143147
color.Yellow("Configuration not found, starting setup...")
148+
144149
return promptForConfig()
145150
}
151+
146152
return nil
147153
}
148154

149155
func promptForConfig() error {
150156
// This will be implemented in the config command
151157
fmt.Println("Please run 'cco config init' to set up your configuration")
152-
return fmt.Errorf("configuration required")
158+
return errors.New("configuration required")
153159
}

cmd/start.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,6 @@ func runStart(cmd *cobra.Command, _ []string) error {
4848

4949
// Create and start server
5050
srv := server.New(cfgMgr, logger)
51+
5152
return srv.Start()
5253
}

cmd/stop.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,6 @@ func runStop(cmd *cobra.Command, _ []string) error {
3232
procMgr.CleanupRef()
3333

3434
color.Green("Service stopped successfully")
35+
3536
return nil
3637
}

internal/config/config.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,14 @@ func (m *Manager) createMinimalConfig() Config {
122122
}
123123

124124
func (m *Manager) Load() (*Config, error) {
125-
var cfg Config
126-
var err error
125+
var (
126+
cfg Config
127+
err error
128+
)
127129

128130
// Check if CCO_API_KEY is set - if so, we can run without a config file
129131
ccoAPIKey := os.Getenv("CCO_API_KEY")
130-
132+
131133
// Try YAML first (takes precedence)
132134
if _, yamlErr := os.Stat(m.yamlPath); yamlErr == nil {
133135
cfg, err = m.loadYAML()
@@ -152,6 +154,7 @@ func (m *Manager) Load() (*Config, error) {
152154
}
153155

154156
m.configValue.Store(&cfg)
157+
155158
return &cfg, nil
156159
}
157160

@@ -190,6 +193,7 @@ func (m *Manager) applyDefaults(cfg *Config) error {
190193
if cfg.Port == 0 {
191194
cfg.Port = DefaultPort
192195
}
196+
193197
if cfg.Host == "" {
194198
cfg.Host = DefaultHost
195199
}
@@ -217,6 +221,7 @@ func (m *Manager) applyDefaults(cfg *Config) error {
217221
if len(provider.ModelWhitelist) > 0 && len(provider.DefaultModels) > 0 {
218222
// Filter default models based on whitelist
219223
var filteredDefaults []string
224+
220225
for _, model := range provider.DefaultModels {
221226
for _, whitelisted := range provider.ModelWhitelist {
222227
if strings.Contains(model, whitelisted) || model == whitelisted {
@@ -225,6 +230,7 @@ func (m *Manager) applyDefaults(cfg *Config) error {
225230
}
226231
}
227232
}
233+
228234
provider.DefaultModels = filteredDefaults
229235
}
230236
}
@@ -245,6 +251,7 @@ func (m *Manager) Get() *Config {
245251
Port: DefaultPort,
246252
}
247253
}
254+
248255
return cfg
249256
}
250257

@@ -264,6 +271,7 @@ func (m *Manager) Save(cfg *Config) error {
264271
}
265272

266273
m.configValue.Store(cfg)
274+
267275
return nil
268276
}
269277

@@ -282,6 +290,7 @@ func (m *Manager) SaveAsYAML(cfg *Config) error {
282290
}
283291

284292
m.configValue.Store(cfg)
293+
285294
return nil
286295
}
287296

@@ -300,6 +309,7 @@ func (m *Manager) SaveAsJSON(cfg *Config) error {
300309
}
301310

302311
m.configValue.Store(cfg)
312+
303313
return nil
304314
}
305315

@@ -308,6 +318,7 @@ func (m *Manager) GetPath() string {
308318
if _, err := os.Stat(m.yamlPath); err == nil {
309319
return m.yamlPath
310320
}
321+
311322
return m.jsonPath
312323
}
313324

@@ -322,6 +333,7 @@ func (m *Manager) GetJSONPath() string {
322333
func (m *Manager) Exists() bool {
323334
_, yamlErr := os.Stat(m.yamlPath)
324335
_, jsonErr := os.Stat(m.jsonPath)
336+
325337
return yamlErr == nil || jsonErr == nil
326338
}
327339

@@ -396,6 +408,7 @@ func (p *Provider) IsModelAllowed(model string) bool {
396408
return true
397409
}
398410
}
411+
399412
return false
400413
}
401414

@@ -406,10 +419,12 @@ func (p *Provider) GetAllowedModels() []string {
406419
}
407420

408421
var allowed []string
422+
409423
for _, model := range p.DefaultModels {
410424
if p.IsModelAllowed(model) {
411425
allowed = append(allowed, model)
412426
}
413427
}
428+
414429
return allowed
415430
}

0 commit comments

Comments
 (0)