package main import ( "context" "git.dragse.it/anthrove/e621-sdk-go/pkg/e621" "git.dragse.it/anthrove/e621-to-graph/internal/api" "git.dragse.it/anthrove/e621-to-graph/internal/config" "git.dragse.it/anthrove/e621-to-graph/internal/database/neo4j" "git.dragse.it/anthrove/e621-to-graph/pkg/logic" log "github.com/sirupsen/logrus" "net/http" "strings" "time" ) func main() { // Loads Config appConfig, err := config.LoadConfig() if err != nil { log.Fatal(err) } log.Debug("main: config loaded") loggingSetup(appConfig) var graphConnection logic.GraphConnection ctx := context.Background() switch strings.ToLower(appConfig.DBType) { case "neo4j": graphConnection = neo4j.NewNeo4JConnection(appConfig.Neo4jDebug) err = graphConnection.Connect(ctx, appConfig.DBEndpoint, appConfig.DBUsername, appConfig.DBPassword) if err != nil { log.Panicf("main: %s", err) } default: log.Panic("main: no database was selected!") } log.WithFields(log.Fields{ "database_type": strings.ToLower(appConfig.DBType), }).Info("main: database connection successful") // Initialize the e621API client := e621.NewClient(appConfig.E621Username, appConfig.E621APIKey) // Register the ScapeUserFavourites with the "/user" route http.HandleFunc("/user", api.ScapeUserFavourites(ctx, graphConnection, &client)) // Start the HTTP server err = http.ListenAndServe(":8080", nil) if err != nil { log.Panicf("main: %s", err) } } func loggingSetup(appConfig *config.Config) { switch strings.ToUpper(appConfig.LogLevel) { case "FATAL": log.SetLevel(log.FatalLevel) case "ERROR": log.SetLevel(log.ErrorLevel) case "WARN": log.SetLevel(log.WarnLevel) case "INFO": log.SetLevel(log.InfoLevel) case "DEBUG": log.SetLevel(log.DebugLevel) case "TRACE": log.SetLevel(log.TraceLevel) default: log.Panic("main: no log level was set") } switch strings.ToUpper(appConfig.LogFormat) { case "PLAIN": log.SetFormatter(&log.TextFormatter{ ForceColors: true, ForceQuote: true, DisableLevelTruncation: true, PadLevelText: true, FullTimestamp: true, TimestampFormat: time.DateTime, // 2006-01-02 15:04:05 }) case "JSON": log.SetFormatter(&log.JSONFormatter{ TimestampFormat: time.DateTime, // 2006-01-02 15:04:05, }) default: log.Panic("main: no formatter was set") } log.WithFields(log.Fields{ "log_level": log.GetLevel(), "formatter": appConfig.LogFormat, }).Info("main: setting logging info") }