Codevault initial commit
This commit is contained in:
59
internal/runcmd/config_example.go
Normal file
59
internal/runcmd/config_example.go
Normal file
@@ -0,0 +1,59 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user