package main import ( "fmt" "git.myrkvi.com/myrkvi/bin/controllers" "git.myrkvi.com/myrkvi/bin/global" "git.myrkvi.com/myrkvi/bin/models" "github.com/glebarez/sqlite" "github.com/labstack/echo/v4" "github.com/labstack/echo/v4/middleware" "github.com/sirupsen/logrus" "github.com/spf13/viper" prefixed "github.com/x-cray/logrus-prefixed-formatter" "gorm.io/gorm" ) func main() { logrus.SetLevel(logrus.DebugLevel) logrus.SetFormatter(&prefixed.TextFormatter{ FullTimestamp: true, }) logrus.Infoln("Application started.") initConfig() db_string := "bin.db" var err error global.DB, err = gorm.Open(sqlite.Open(db_string), &gorm.Config{}) if err != nil { logrus.WithError(err).Fatalln("Could not open database connection.") } logrus.WithFields(logrus.Fields{ "db connection": db_string, }).Infoln("Connected to database.") models.DatabaseMigrations(global.DB) e := echo.New() e.Debug = false e.Use(middleware.RequestLoggerWithConfig(middleware.RequestLoggerConfig{ LogURI: true, LogStatus: true, LogRemoteIP: true, LogValuesFunc: func(c echo.Context, values middleware.RequestLoggerValues) error { logrus.WithFields(logrus.Fields{ "URI": values.URI, "status": values.Status, "remote": values.RemoteIP, }).Info("request") return nil }, })) e.Static("/static", "static") e.GET("/", controllers.IndexHandler) e.GET("/new", controllers.GetNewHandler) e.POST("/new", controllers.PostNewHandler) e.GET("/b/:id", controllers.GetBinHandler) e.POST("/b/:id/delete", controllers.DeleteBinHandler) partial := e.Group("/partial") new := partial.Group("/new") new.GET("/upload", controllers.GetPartialUploadHandler) new.GET("/text", controllers.GetPartialTextHandler) listenAt := fmt.Sprintf( "%s:%d", viper.GetString("host"), viper.GetUint16("port"), ) e.Logger.Fatal(e.Start(listenAt)) }