Skip to content

Commit

Permalink
add default config
Browse files Browse the repository at this point in the history
  • Loading branch information
Babatunde50 committed Jun 9, 2024
1 parent e246a32 commit 6306a78
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,28 @@ import (
"github.com/spf13/viper"
)

// Token represents token-related configuration.
type Token struct {
FileName string `mapstructure:"FileName"`
AppName string `mapstructure:"AppName"`
FolderName string `mapstructure:"FolderName"`
}

// Service represents a service configuration.
type Service struct {
Host string `mapstructure:"host"`
}

// Config holds the entire configuration structure.
type Config struct {
Token Token `mapstructure:"token"`
Services map[string]Service `mapstructure:"services"`
}

// C is the global configuration variable.
var C Config

// LoadConfig loads the configuration from config.yaml.
func LoadConfig() {
exePath, err := os.Executable()
if err != nil {
Expand All @@ -38,19 +43,18 @@ func LoadConfig() {
// Check if the config file exists
if _, err := os.Stat(configPath); os.IsNotExist(err) {
// If the file does not exist, create it with default values
defaultConfig := []byte(`
token:
FileName: "token"
AppName: "gitversity"
FolderName: ".config"
defaultConfig := []byte(`token:
FileName: "token"
AppName: "gitversity"
FolderName: ".config"
services:
user_grpc:
host: "grpc.dev.user.api.gitversity.com:443"
assignment_grpc:
host: "grpc.dev.assignment.api.gitversity.com:443"
git_grpc:
host: "grpc.dev.git.api.gitversity.com:443"
services:
user_grpc:
host: "grpc.dev.user.api.gitversity.com:443"
assignment_grpc:
host: "grpc.dev.assignment.api.gitversity.com:443"
git_grpc:
host: "grpc.dev.git.api.gitversity.com:443"
`)

err = os.WriteFile(configPath, defaultConfig, 0644)
Expand Down

0 comments on commit 6306a78

Please sign in to comment.