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

72 lines
2 KiB
Go
Raw Normal View History

2016-05-02 21:36:49 -04:00
package main
import (
log "github.com/cihub/seelog"
"flag"
2016-05-02 21:36:49 -04:00
"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")
dbAddr = flag.String("db-addr", "localhost:5432", "IP address of the database")
dbUser = flag.String("db-user", "", "User name to access the database")
dbPassword = flag.String("db-password", "", "Password to access 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")
2017-05-21 10:16:16 +00:00
ro = flag.Bool("ro", false, "read only mode")
)
flag.Parse()
2016-05-02 21:36:49 -04:00
defer log.Flush()
err := trantor.UpdateLogger(*loggerConfig)
2016-05-02 21:36:49 -04:00
if err != nil {
log.Error("Error loading the logger xml: ", err)
}
log.Info("Start the imperial library of trantor")
db, err := database.Init(database.Options{
Addr: *dbAddr,
User: *dbUser,
Password: *dbPassword,
Name: *dbName,
})
if err != nil {
log.Critical("Problem initializing database: ", err)
os.Exit(1)
}
2016-05-02 21:36:49 -04:00
defer db.Close()
store, err := storage.Init(*storePath)
2016-05-02 21:36:49 -04:00
if err != nil {
log.Critical("Problem initializing store: ", err)
os.Exit(1)
}
2017-05-21 10:16:16 +00:00
if *ro {
store = storage.RO(store)
db = database.RO(db)
}
template := trantor.InitTemplate(*assetsPath)
2017-05-21 10:16:16 +00:00
sg := trantor.InitStats(db, store, *hostname, template, *ro)
2016-05-02 21:36:49 -04:00
trantor.InitUpload(db, store)
trantor.InitTasks(db, *loggerConfig)
2016-05-02 21:36:49 -04:00
2017-06-05 16:17:14 +00:00
router := trantor.InitRouter(db, sg, *assetsPath)
server := http.Server{
Addr: *httpAddr,
Handler: router,
}
log.Error(server.ListenAndServe())
2016-05-02 21:36:49 -04:00
}