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
|
|
|
}
|