topology-map/internal/config/config.go

37 lines
736 B
Go
Raw Normal View History

2024-09-23 11:45:30 +00:00
package config
import (
"encoding/json"
"fmt"
"os"
)
type NetboxConfig struct {
BaseURL string `json:"baseURL"`
APIKey string `json:"apiKey"`
}
type MikrotikConfig struct {
IPAddress string `json:"ipAddress"`
User string `json:"user"`
Password string `json:"password"`
}
type AppConfig struct {
Netbox NetboxConfig `json:"netbox"`
Mikrotik []MikrotikConfig `json:"mikrotik"`
}
func New(configPath string) (*AppConfig, error) {
content, err := os.ReadFile(configPath)
if err != nil {
return nil, fmt.Errorf("failed to read config: %w", err)
}
var conf AppConfig
if err := json.Unmarshal(content, &conf); err != nil {
return nil, fmt.Errorf("invalid config content: %w", err)
}
return &conf, nil
}