From 752d190fbc27b2fddbca2577b4d5bd4ea7dad28c Mon Sep 17 00:00:00 2001 From: Jannis Mattheis Date: Sun, 11 Feb 2018 17:30:07 +0100 Subject: [PATCH] Add main app --- config/config.go | 2 +- main/app.go | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 main/app.go diff --git a/config/config.go b/config/config.go index d1ef6fd..2ea9b99 100644 --- a/config/config.go +++ b/config/config.go @@ -2,7 +2,7 @@ package config import "github.com/jinzhu/configor" -// Configuration the application config can be set per env variables or config file (config.yml). +// Configuration is stuff that can be configured externally per env variables or config file (config.yml). type Configuration struct { Port int `default:"8080"` Database struct { diff --git a/main/app.go b/main/app.go new file mode 100644 index 0000000..7372c9f --- /dev/null +++ b/main/app.go @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "math/rand" + "time" + + "github.com/gin-gonic/gin" + "github.com/jmattheis/memo/config" + "github.com/jmattheis/memo/database" + "github.com/jmattheis/memo/router" +) + +func main() { + rand.Seed(time.Now().UnixNano()) + conf := config.Get() + db, err := database.New(conf.Database.Dialect, conf.Database.Connection, conf.DefaultUser.Name, conf.DefaultUser.Pass) + if err != nil { + panic(err) + } + defer db.Close() + + gin.SetMode(gin.ReleaseMode) + engine, closeable := router.Create(db) + defer closeable() + engine.Run(fmt.Sprintf(":%d", conf.Port)) +}