Take the hostname from the request
This commit is contained in:
parent
3e3ba1bd7e
commit
3bb3cf9489
3 changed files with 8 additions and 9 deletions
|
@ -24,7 +24,6 @@ type handler struct {
|
||||||
db database.DB
|
db database.DB
|
||||||
store storage.Store
|
store storage.Store
|
||||||
template *Template
|
template *Template
|
||||||
hostname string
|
|
||||||
ro bool
|
ro bool
|
||||||
t1 time.Time
|
t1 time.Time
|
||||||
}
|
}
|
||||||
|
@ -79,12 +78,11 @@ type StatsGatherer struct {
|
||||||
store storage.Store
|
store storage.Store
|
||||||
template *Template
|
template *Template
|
||||||
instrument instrument.Instrument
|
instrument instrument.Instrument
|
||||||
hostname string
|
|
||||||
channel chan statsRequest
|
channel chan statsRequest
|
||||||
ro bool
|
ro bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitStats(database database.DB, store storage.Store, hostname string, template *Template, ro bool) *StatsGatherer {
|
func InitStats(database database.DB, store storage.Store, template *Template, ro bool) *StatsGatherer {
|
||||||
in := instrument.Init()
|
in := instrument.Init()
|
||||||
|
|
||||||
sg := StatsGatherer{
|
sg := StatsGatherer{
|
||||||
|
@ -93,7 +91,6 @@ func InitStats(database database.DB, store storage.Store, hostname string, templ
|
||||||
store: store,
|
store: store,
|
||||||
instrument: in,
|
instrument: in,
|
||||||
template: template,
|
template: template,
|
||||||
hostname: hostname,
|
|
||||||
ro: ro,
|
ro: ro,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,7 +106,6 @@ func (sg StatsGatherer) Gather(function func(handler)) func(http.ResponseWriter,
|
||||||
store: sg.store,
|
store: sg.store,
|
||||||
db: sg.db,
|
db: sg.db,
|
||||||
template: sg.template,
|
template: sg.template,
|
||||||
hostname: sg.hostname,
|
|
||||||
w: w,
|
w: w,
|
||||||
r: r,
|
r: r,
|
||||||
sess: GetSession(r, sg.db),
|
sess: GetSession(r, sg.db),
|
||||||
|
|
|
@ -36,7 +36,11 @@ type Status struct {
|
||||||
|
|
||||||
func GetStatus(h handler) Status {
|
func GetStatus(h handler) Status {
|
||||||
var s Status
|
var s Status
|
||||||
s.BaseURL = "http://" + h.hostname
|
host := h.r.Host
|
||||||
|
s.BaseURL = "https://" + host
|
||||||
|
if strings.HasSuffix(host, ".onion") || strings.Contains(host, "localhost") {
|
||||||
|
s.BaseURL = "http://" + host
|
||||||
|
}
|
||||||
s.FullURL = s.BaseURL + h.r.RequestURI
|
s.FullURL = s.BaseURL + h.r.RequestURI
|
||||||
s.Title = "Imperial Library of Trantor"
|
s.Title = "Imperial Library of Trantor"
|
||||||
s.User = h.sess.User
|
s.User = h.sess.User
|
||||||
|
|
5
main.go
5
main.go
|
@ -7,7 +7,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"gitlab.com/trantor/trantor/lib"
|
trantor "gitlab.com/trantor/trantor/lib"
|
||||||
"gitlab.com/trantor/trantor/lib/database"
|
"gitlab.com/trantor/trantor/lib/database"
|
||||||
"gitlab.com/trantor/trantor/lib/storage"
|
"gitlab.com/trantor/trantor/lib/storage"
|
||||||
)
|
)
|
||||||
|
@ -21,7 +21,6 @@ func main() {
|
||||||
dbName = flag.String("db-name", "trantor", "Name of the database")
|
dbName = flag.String("db-name", "trantor", "Name of the database")
|
||||||
storePath = flag.String("store", "store", "Path of the books storage")
|
storePath = flag.String("store", "store", "Path of the books storage")
|
||||||
assetsPath = flag.String("assets", ".", "Path of the assets (templates, css, js, img)")
|
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")
|
loggerConfig = flag.String("logger-conf", "logger.xml", "xml configuration of the logger")
|
||||||
setAdminUser = flag.String("set-admin-user", "", "create/update this user to be admin if set-admin-pass is also specified")
|
setAdminUser = flag.String("set-admin-user", "", "create/update this user to be admin if set-admin-pass is also specified")
|
||||||
setAdminPass = flag.String("set-admin-pass", "", "create/update admin user password if set-admin-user is also specified")
|
setAdminPass = flag.String("set-admin-pass", "", "create/update admin user password if set-admin-user is also specified")
|
||||||
|
@ -65,7 +64,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
template := trantor.InitTemplate(*assetsPath)
|
template := trantor.InitTemplate(*assetsPath)
|
||||||
sg := trantor.InitStats(db, store, *hostname, template, *ro)
|
sg := trantor.InitStats(db, store, template, *ro)
|
||||||
trantor.InitUpload(db, store)
|
trantor.InitUpload(db, store)
|
||||||
trantor.InitTasks(db, *loggerConfig)
|
trantor.InitTasks(db, *loggerConfig)
|
||||||
|
|
||||||
|
|
Reference in a new issue