60 lines
1.5 KiB
Go
60 lines
1.5 KiB
Go
package runcmd
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"os"
|
|
"time"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
|
|
"github.com/kanootoko/codevault/internal/config"
|
|
)
|
|
|
|
func ConfigExample(configPath string) error {
|
|
configExample := config.Config{
|
|
Environment: config.DevelopmentEnvironment,
|
|
Server: config.ServerConfig{
|
|
Address: ":8080",
|
|
// Example: a Docker-network CIDR in front of a reverse proxy nginx.
|
|
// Replace with the actual proxy's IP/CIDR, or leave empty to trust
|
|
// no forwarded-for headers.
|
|
TrustedProxies: []string{"172.16.0.0/12"},
|
|
},
|
|
Database: config.DatabaseConfig{
|
|
Path: "./codevault.db",
|
|
},
|
|
RateLimit: config.RateLimitConfig{
|
|
MaxFailures: 10,
|
|
Window: time.Minute,
|
|
},
|
|
Observability: config.ObservabilityConfig{
|
|
Logging: config.LoggingConfig{
|
|
Stderr: config.InfoLoggingLevel,
|
|
Files: map[config.LoggingLevel]string{config.InfoLoggingLevel: "./info.log"},
|
|
Exporter: config.LogsExporterConfig{
|
|
Level: config.InfoLoggingLevel,
|
|
Endpoint: "http://127.0.0.1:4317/v1/logs",
|
|
Transport: "grpc",
|
|
},
|
|
},
|
|
Metrics: config.MetricsConfig{
|
|
Host: "127.0.0.1",
|
|
Port: 9092,
|
|
},
|
|
},
|
|
}
|
|
configBytesBuffer := bytes.NewBuffer(nil)
|
|
encoder := yaml.NewEncoder(configBytesBuffer)
|
|
encoder.SetIndent(2)
|
|
err := encoder.Encode(configExample)
|
|
if err != nil {
|
|
return fmt.Errorf("cannot marshal example config: %w", err)
|
|
}
|
|
err = os.WriteFile(configPath, configBytesBuffer.Bytes(), os.ModePerm)
|
|
if err != nil {
|
|
return fmt.Errorf("cannot write config file: %w", err)
|
|
}
|
|
return nil
|
|
}
|