summaryrefslogtreecommitdiffstats
path: root/internal/config/config.go
blob: e1da2c25b80b51efcccb195ee4cea3a188a1199a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package config

import (
	"os"
	"time"
)

type Config struct {
	APIKey     string
	BaseURL    string
	Timeout    time.Duration
	MaxRetries int
	UserAgent  string
}

func New() *Config {
	return &Config{
		APIKey:     os.Getenv("DBORG_API_KEY"),
		BaseURL:    "https://db.org.ai",
		Timeout:    30 * time.Second,
		MaxRetries: 3,
		UserAgent:  "dborg-cli/1.0",
	}
}

func (c *Config) WithAPIKey(key string) *Config {
	if key != "" {
		c.APIKey = key
	}
	return c
}

func (c *Config) Validate() error {
	if c.APIKey == "" {
		return ErrMissingAPIKey
	}
	return nil
}