This repository has been archived on 2025-03-01. You can view files and clone it, but cannot push or open issues or pull requests.
trantor/main.go
2017-05-21 10:16:51 +00:00

56 lines
1.5 KiB
Go

package main
import (
log "github.com/cihub/seelog"
"flag"
"net/http"
"os"
"gitlab.com/trantor/trantor/lib"
"gitlab.com/trantor/trantor/lib/database"
"gitlab.com/trantor/trantor/lib/storage"
)
func main() {
var (
httpAddr = flag.String("addr", ":8080", "HTTP service address")
dbIP = flag.String("db-ip", "127.0.0.1", "IP address of the database")
dbName = flag.String("db-name", "trantor", "Name of the database")
storePath = flag.String("store", "store", "Path of the books storage")
assetsPath = flag.String("assets", ".", "Path of the assets (templates, css, js, img)")
hostname = flag.String("hostname", "xfmro77i3lixucja.onion", "Hostname of the website")
loggerConfig = flag.String("logger-conf", "logger.xml", "xml configuration of the logger")
ro = flag.Bool("ro", false, "read only mode")
)
flag.Parse()
defer log.Flush()
err := trantor.UpdateLogger(*loggerConfig)
if err != nil {
log.Error("Error loading the logger xml: ", err)
}
log.Info("Start the imperial library of trantor")
db := database.Init(*dbIP, *dbName)
defer db.Close()
store, err := storage.Init(*storePath)
if err != nil {
log.Critical("Problem initializing store: ", err)
os.Exit(1)
}
if *ro {
store = storage.RO(store)
db = database.RO(db)
}
template := trantor.InitTemplate(*assetsPath)
sg := trantor.InitStats(db, store, *hostname, template, *ro)
trantor.InitUpload(db, store)
trantor.InitTasks(db, *loggerConfig)
trantor.InitRouter(db, sg, *assetsPath)
log.Error(http.ListenAndServe(*httpAddr, nil))
}