sum7/warehost
sum7
/
warehost
Archived
1
0
Fork 0
This repository has been archived on 2020-09-27. You can view files and clone it, but cannot push or open issues or pull requests.
warehost/cmd/warehost-web/main.go

56 lines
1.5 KiB
Go
Raw Normal View History

2016-08-27 02:18:41 +02:00
package main
import (
"flag"
"net"
"net/http"
"github.com/NYTimes/gziphandler"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/postgres"
2016-10-11 20:16:24 +02:00
liblog "dev.sum7.eu/sum7/warehost/lib/log"
web "dev.sum7.eu/sum7/warehost/modul/web"
system "dev.sum7.eu/sum7/warehost/system"
2016-08-27 02:18:41 +02:00
)
var (
configFile string
config *Config
dbconnection *gorm.DB
)
func main() {
var err error
flag.StringVar(&configFile, "c", "config.yml", "path of configuration file")
flag.Parse()
config = ReadConfigFile(configFile)
2016-10-11 20:16:24 +02:00
liblog.NewLogger(config.Log.Path)
2016-08-27 02:18:41 +02:00
// Main Databaseconnection
dbconnection, err = gorm.Open("postgres", config.Database)
if err != nil {
2016-10-11 20:16:24 +02:00
liblog.Log.Fatal("database connection: ", err)
2016-08-27 02:18:41 +02:00
}
defer dbconnection.Close()
dbconnection.Callback().Create().Remove("gorm:update_time_stamp")
dbconnection.Callback().Update().Remove("gorm:update_time_stamp")
dbconnection.SingularTable(true)
dbconnection.LogMode(config.DatabaseDebug)
//load system Models to database
system.SyncModels(dbconnection)
2016-10-11 20:16:24 +02:00
web.SyncModels(dbconnection)
2016-08-27 02:18:41 +02:00
// http handler
http.Handle("/static/", gziphandler.GzipHandler(http.StripPrefix("/static/", http.HandlerFunc(handlerstatic))))
2016-09-01 22:19:39 +02:00
http.Handle("/files/", gziphandler.GzipHandler(http.StripPrefix("/files/", http.HandlerFunc(handlerfiles))))
2016-08-27 02:18:41 +02:00
http.Handle("/", gziphandler.GzipHandler(http.HandlerFunc(handlerfunc)))
// Start server
address := net.JoinHostPort(config.Address, config.Port)
2016-10-11 20:16:24 +02:00
liblog.Log.Info("starting warehost web on ", address)
2016-08-27 02:18:41 +02:00
// TODO bad
2016-10-11 20:16:24 +02:00
liblog.Log.Fatal(http.ListenAndServe(address, nil))
2016-08-27 02:18:41 +02:00
}