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/main.go

54 lines
1.3 KiB
Go
Raw Normal View History

2016-08-13 11:03:03 +02:00
package main
import (
"flag"
"log"
"net"
"net/http"
"github.com/NYTimes/gziphandler"
"github.com/astaxie/session"
_ "github.com/astaxie/session/providers/memory"
"github.com/go-xorm/xorm"
"github.com/julienschmidt/httprouter"
_ "github.com/lib/pq"
libconfig "dev.sum7.de/sum7/warehost/config"
"dev.sum7.de/sum7/warehost/system"
)
var (
configFile string
config *libconfig.Config
dbconnection *xorm.Engine
sessions *session.Manager
)
func main() {
var err error
flag.StringVar(&configFile, "c", "config.yml", "path of configuration file")
flag.Parse()
config = libconfig.ReadConfigFile(configFile)
sessions, _ = session.NewManager("memory", "session", 3600)
go sessions.GC()
dbconnection, err = xorm.NewEngine("postgres", config.Database)
if err != nil {
log.Fatal("[system] Error database connection: ", err)
}
defer dbconnection.Close()
system.SyncModels(dbconnection)
router := httprouter.New()
system.NewAPI(config, sessions, dbconnection, router, "")
if config.Webroot != "" {
router.NotFound = gziphandler.GzipHandler(http.FileServer(http.Dir(config.Webroot)))
}
address := net.JoinHostPort(config.API.Address, config.API.Port)
log.Println("starting webserver on", address)
// TODO bad
log.Fatal(http.ListenAndServe(address, router))
}