linstrom/main.go
2024-08-28 17:20:38 +02:00

51 lines
1.3 KiB
Go

package main
import (
"os"
"strings"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"gitlab.com/mstarongitlab/linstrom/ap"
"gitlab.com/mstarongitlab/linstrom/config"
)
func main() {
if *flagPrettyPrint {
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
log.Info().Msg("Pretty logging enabled")
}
setLogLevel()
if err := config.ReadAndWriteToGlobal(*flagConfigFile); err != nil {
log.Fatal().
Err(err).
Str("config-file", *flagConfigFile).
Msg("Failed to read config and couldn't write default")
}
// "@aufricus_athudath@activitypub.academy"
res, err := ap.GetAccountWebfinger("@aufricus_athudath@activitypub.academy")
log.Info().
Err(err).
Any("webfinger", res).
Msg("Webfinger request result for @aufricus_athudath@activitypub.academy")
}
func setLogLevel() {
log.Info().Str("new-level", *flagLogLevel).Msg("Attempting to set log level")
switch strings.ToLower(*flagLogLevel) {
case "trace":
zerolog.SetGlobalLevel(zerolog.TraceLevel)
case "debug":
zerolog.SetGlobalLevel(zerolog.DebugLevel)
case "info":
zerolog.SetGlobalLevel(zerolog.InfoLevel)
case "warn":
zerolog.SetGlobalLevel(zerolog.WarnLevel)
case "error":
zerolog.SetGlobalLevel(zerolog.ErrorLevel)
case "fatal":
zerolog.SetGlobalLevel(zerolog.FatalLevel)
default:
zerolog.SetGlobalLevel(zerolog.InfoLevel)
}
}