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

package main
import (
"flag"
"net"
"net/http"
"github.com/NYTimes/gziphandler"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/postgres"
log "dev.sum7.de/sum7/warehost/lib/log"
modul "dev.sum7.de/sum7/warehost/modul/web"
system "dev.sum7.de/sum7/warehost/system"
)
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)
log.NewLogger(config.Log.Path)
// Main Databaseconnection
dbconnection, err = gorm.Open("postgres", config.Database)
if err != nil {
log.Log.Fatal("database connection: ", err)
}
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)
modul.SyncModels(dbconnection)
// http handler
http.Handle("/static/", gziphandler.GzipHandler(http.StripPrefix("/static/", http.HandlerFunc(handlerstatic))))
http.Handle("/files/", gziphandler.GzipHandler(http.StripPrefix("/files/", http.HandlerFunc(handlerfiles))))
http.Handle("/", gziphandler.GzipHandler(http.HandlerFunc(handlerfunc)))
// Start server
address := net.JoinHostPort(config.Address, config.Port)
log.Log.Info("starting warehost web on ", address)
// TODO bad
log.Log.Fatal(http.ListenAndServe(address, nil))
}