Skip to content

Commit

Permalink
Move config init to config
Browse files Browse the repository at this point in the history
  • Loading branch information
bahner committed Jan 23, 2024
1 parent 2f18456 commit 288737f
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 63 deletions.
49 changes: 49 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package config

import (
"fmt"
"os"

log "github.com/sirupsen/logrus"
"github.com/spf13/pflag"
"github.com/spf13/viper"
)

const (
NAME = "go-ma-actor"
VERSION = "v0.0.4"
)

func init() {

viper.SetConfigName(NAME)
viper.SetConfigType("yaml")
viper.AddConfigPath(".")

viper.SetEnvPrefix(NAME)
viper.AutomaticEnv()

// Read the configuration file
err := viper.ReadInConfig()
if err != nil {
// Handle the error, e.g., file not found
log.Fatalf("Error reading config file: %s\n", err)
}

pflag.BoolP("version", "v", false, "Print version and exit.")
viper.BindPFlag("version", pflag.Lookup("version"))

}

// This should be done after flag.Parse() in main.
func Init() {

if viper.GetBool("version") {
fmt.Println(VERSION)
os.Exit(0)
}

InitLogging()
InitNodeIdentity()
InitIdentity()
}
24 changes: 0 additions & 24 deletions config/general.go

This file was deleted.

21 changes: 0 additions & 21 deletions config/init.go

This file was deleted.

18 changes: 0 additions & 18 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,10 @@ import (
"github.com/bahner/go-ma-actor/p2p"
"github.com/bahner/go-ma-actor/ui"
"github.com/spf13/pflag"
"github.com/spf13/viper"

log "github.com/sirupsen/logrus"
)

func init() {

viper.SetConfigName(config.NAME)
viper.SetConfigType("yaml")
viper.AddConfigPath(".")

viper.SetEnvPrefix(config.NAME)
viper.AutomaticEnv()

// Read the configuration file
err := viper.ReadInConfig()
if err != nil {
// Handle the error, e.g., file not found
log.Fatalf("Error reading config file: %s\n", err)
}
}

func main() {

pflag.Parse()
Expand Down

0 comments on commit 288737f

Please sign in to comment.