mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2025-12-08 01:06:34 +00:00
chore: fix typo
This commit is contained in:
@@ -49,7 +49,7 @@ func NewBootstrapApp(config config.Config) *BootstrapApp {
|
||||
|
||||
func (app *BootstrapApp) Setup() error {
|
||||
// Log json
|
||||
shoudLogJson := utils.ShoudLogJSON(os.Environ(), os.Args)
|
||||
shouldLogJson := utils.ShouldLogJSON(os.Environ(), os.Args)
|
||||
|
||||
// Parse users
|
||||
users, err := utils.GetUsers(app.config.Users, app.config.UsersFile)
|
||||
@@ -147,7 +147,7 @@ func (app *BootstrapApp) Setup() error {
|
||||
oauthBrokerService := service.NewOAuthBrokerService(oauthProviders)
|
||||
accessLogService := service.NewAccessLogService(&service.AccessLogServiceConfig{
|
||||
LogFile: app.config.AccessLogFile,
|
||||
LogJson: shoudLogJson,
|
||||
LogJson: shouldLogJson,
|
||||
})
|
||||
|
||||
// Initialize services (order matters)
|
||||
|
||||
@@ -89,7 +89,7 @@ func (als *AccessLogService) Log(log AccessLog) {
|
||||
Str("provider", log.Provider).
|
||||
Str("username", log.Username).
|
||||
Str("client_ip", log.ClientIP).
|
||||
Int64("time", time.Now().UnixMilli()).
|
||||
Int64("time", time.Now().Unix()).
|
||||
Bool("success", log.Success)
|
||||
|
||||
event.Msg(log.Message)
|
||||
|
||||
@@ -201,7 +201,7 @@ func GetOAuthProvidersConfig(env []string, args []string, appUrl string) (map[st
|
||||
return providers, nil
|
||||
}
|
||||
|
||||
func ShoudLogJSON(environ []string, args []string) bool {
|
||||
func ShouldLogJSON(environ []string, args []string) bool {
|
||||
for _, e := range environ {
|
||||
pair := strings.SplitN(e, "=", 2)
|
||||
if len(pair) == 2 && pair[0] == "LOG_JSON" && strings.ToLower(pair[1]) == "true" {
|
||||
|
||||
@@ -279,20 +279,20 @@ func TestGetOAuthProvidersConfig(t *testing.T) {
|
||||
assert.DeepEqual(t, expected, result)
|
||||
}
|
||||
|
||||
func TestShoudLogJSON(t *testing.T) {
|
||||
func TestShouldLogJSON(t *testing.T) {
|
||||
// Test with no env or args
|
||||
result := utils.ShoudLogJSON([]string{"FOO=bar"}, []string{"tinyauth", "--foo-bar=baz"})
|
||||
result := utils.ShouldLogJSON([]string{"FOO=bar"}, []string{"tinyauth", "--foo-bar=baz"})
|
||||
assert.Equal(t, false, result)
|
||||
|
||||
// Test with env variable set
|
||||
result = utils.ShoudLogJSON([]string{"LOG_JSON=true"}, []string{"tinyauth", "--foo-bar=baz"})
|
||||
result = utils.ShouldLogJSON([]string{"LOG_JSON=true"}, []string{"tinyauth", "--foo-bar=baz"})
|
||||
assert.Equal(t, true, result)
|
||||
|
||||
// Test with flag set
|
||||
result = utils.ShoudLogJSON([]string{"FOO=bar"}, []string{"tinyauth", "--log-json=true"})
|
||||
result = utils.ShouldLogJSON([]string{"FOO=bar"}, []string{"tinyauth", "--log-json=true"})
|
||||
assert.Equal(t, true, result)
|
||||
|
||||
// Test with both env and flag set to false
|
||||
result = utils.ShoudLogJSON([]string{"LOG_JSON=false"}, []string{"tinyauth", "--log-json=false"})
|
||||
result = utils.ShouldLogJSON([]string{"LOG_JSON=false"}, []string{"tinyauth", "--log-json=false"})
|
||||
assert.Equal(t, false, result)
|
||||
}
|
||||
|
||||
2
main.go
2
main.go
@@ -12,7 +12,7 @@ import (
|
||||
|
||||
func main() {
|
||||
log.Logger = log.Logger.With().Caller().Logger()
|
||||
if !utils.ShoudLogJSON(os.Environ(), os.Args) {
|
||||
if !utils.ShouldLogJSON(os.Environ(), os.Args) {
|
||||
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.RFC3339})
|
||||
}
|
||||
cmd.Run()
|
||||
|
||||
Reference in New Issue
Block a user