-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
146 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,5 @@ | |
*.out | ||
go.work | ||
go.work.sum | ||
.env | ||
.key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package main | ||
|
||
import ( | ||
"io" | ||
"log/slog" | ||
"os" | ||
"strings" | ||
|
||
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" | ||
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/names" | ||
) | ||
|
||
// App is the main structure carrying the command line options, loggers, and application state | ||
type App struct { | ||
logger *slog.Logger | ||
database names.DatabaseType | ||
action Action | ||
} | ||
|
||
// NewApp returns a new application ready to be used. | ||
func NewApp() *App { | ||
logger.SetLoggerWriter(io.Discard) // we never want core to log anything | ||
logLevel := slog.LevelInfo | ||
if ll, ok := os.LookupEnv("TB_LOGLEVEL"); ok { | ||
switch strings.ToLower(ll) { | ||
case "debug": | ||
logLevel = slog.LevelDebug | ||
case "info": | ||
logLevel = slog.LevelInfo | ||
case "warn": | ||
logLevel = slog.LevelWarn | ||
case "error": | ||
logLevel = slog.LevelError | ||
} | ||
} | ||
opts := slog.HandlerOptions{ | ||
Level: logLevel, | ||
ReplaceAttr: func(groups []string, a slog.Attr) slog.Attr { | ||
if a.Key == slog.TimeKey { | ||
a.Value = slog.StringValue(a.Value.Time().Format("15:04:05")) | ||
} | ||
return a | ||
}, | ||
} | ||
|
||
app := App{ | ||
logger: slog.New(slog.NewTextHandler(os.Stderr, &opts)), | ||
database: names.DatabaseCustom, | ||
} | ||
|
||
if os.Getenv("TB_NAMEMANAGER_REGULAR") == "true" { | ||
app.database = names.DatabaseRegular | ||
} | ||
|
||
return &app | ||
} | ||
|
||
func (a *App) IsRegular() bool { | ||
return a.database == names.DatabaseRegular | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters