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 d32eb8a commit 71ba2c9
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// config/config.go
package config

import (
Expand Down Expand Up @@ -27,14 +26,39 @@ type Config struct {
var C Config

func LoadConfig() {

exePath, err := os.Executable()
if err != nil {
fmt.Println("Error:", err)
return
}

rootDir := filepath.Dir(exePath)
configPath := filepath.Join(rootDir, "config.yaml")

// 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"
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)
if err != nil {
fmt.Println("Error creating default config file:", err)
return
}
}

viper.AddConfigPath(rootDir)
viper.SetConfigName("config")
Expand Down

0 comments on commit 71ba2c9

Please sign in to comment.