Skip to content

Commit

Permalink
Delay flag-Parse() for merge later
Browse files Browse the repository at this point in the history
  • Loading branch information
bahner committed Nov 27, 2023
1 parent 177969e commit 2d989f7
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 25 deletions.
25 changes: 1 addition & 24 deletions config/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ package config
import (
"context"
"flag"
"os"
"time"

"github.com/bahner/go-ma/key/set"
log "github.com/sirupsen/logrus"
)

var (
Expand All @@ -21,7 +19,7 @@ var (
forcePublish *bool
)

func init() {
func InitFlags() {

// Booleans with control flow
generate = flag.Bool("generate", false, "Generates one-time keyset and uses it")
Expand All @@ -47,27 +45,6 @@ func init() {
flag.StringVar(&logLevel, "loglevel", logLevel, "Loglevel to use for application. You can use environment variable "+GO_MA_ACTOR_LOGLEVEL_VAR+" to set this.")
flag.StringVar(&logfile, "logfile", logfile, "Logfile to use for application. You can use environment variable "+GO_MA_ACTOR_LOGFILE_VAR+" to set this.")

flag.Parse()

// Init logger
level, err := log.ParseLevel(logLevel)
if err != nil {
log.Error(err)
os.Exit(64) // EX_USAGE
}
log.SetLevel(level)
file, err := os.OpenFile(name+".log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
if err != nil {
log.Errorf("Failed to open log file: %v", err)
os.Exit(73) // EX_CANTCREAT
}
log.SetOutput(file)

log.Info("Logger initialized")

// Init keyset
initKeyset(keyset_string)

}

func GetNick() string {
Expand Down
4 changes: 3 additions & 1 deletion config/keyset.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import (
log "github.com/sirupsen/logrus"
)

func initKeyset(keyset_string string) {
func InitKeyset() {

keyset = GetKeyset()

var err error

Expand Down
27 changes: 27 additions & 0 deletions config/logger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package config

import (
"os"

log "github.com/sirupsen/logrus"
)

func InitLogging() {

// Init logger
level, err := log.ParseLevel(logLevel)
if err != nil {
log.Error(err)
os.Exit(64) // EX_USAGE
}
log.SetLevel(level)
file, err := os.OpenFile(name+".log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
if err != nil {
log.Errorf("Failed to open log file: %v", err)
os.Exit(73) // EX_CANTCREAT
}
log.SetOutput(file)

log.Info("Logger initialized")

}
6 changes: 6 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"flag"
"os"

"github.com/bahner/go-ma-actor/actor"
Expand All @@ -13,6 +14,11 @@ import (

func main() {

config.InitFlags()
flag.Parse()
config.InitLogging()
config.InitKeyset()

p, err := p2p.Init(nil)
if err != nil {
log.Errorf("failed to initialize p2p: %v", err)
Expand Down

0 comments on commit 2d989f7

Please sign in to comment.