go-scopes/examples/demo/etc/etc.go

62 lines
1.6 KiB
Go

package etc
import (
lib "git.sr.ht/~cco/go-scopes"
"git.sr.ht/~cco/go-scopes/app"
"git.sr.ht/~cco/go-scopes/config"
"git.sr.ht/~cco/go-scopes/core/action"
"git.sr.ht/~cco/go-scopes/logging"
"git.sr.ht/~cco/go-scopes/server"
sql "git.sr.ht/~cco/go-scopes/storage"
msgstore "git.sr.ht/~cco/go-scopes/storage/message"
)
func Config() lib.Config {
ovr := Overrides().Use
b := config.Base
app_c := &app.Cfg{
BaseCfg: b("dummy", app.Start),
Home: ovr(".", HOME),
Logging: &logging.Cfg{
Logfile: ovr("log/scopes.log", LOGFILE),
Level: ovr("info", LOGLEVEL),
},
}
server_c := b("server", server.Start(
(&server.Cfg{Port: ovr("8123", SERVER_PORT)}).
AddRoute("/docs", server.FileServer(ovr("html", DOCROOT))).
AddRoute("/api", server.MsgHandler().
AddActionProc("scopes|data", server.Async, "msgstore"))))
msgstore_c := b("msgstore", sql.Start(
&sql.Cfg{
Driver: "postgres",
Connstr: ovr("user=cco password=dummy dbname=scps", PGSQL_CONNSTR),
}))
msgstore_c.AddAction("scopes|data", action.Base(msgstore.Store))
app_c.Add(server_c, msgstore_c)
return app_c
}
// collect here the names of fields that may be overridden via
// explicit Override() or SCOPES_* environment settings.
const (
HOME = "home"
LOGFILE = "logfile"
LOGLEVEL = "loglevel"
SERVER_PORT = "server_port"
DOCROOT = "docroot"
PGSQL_CONNSTR = "pgsql_connstr"
)
// put something like this (without comment markup)
// in separate (non-versioned) settings.go file:
/*func Overrides() config.Settings {
return config.Settings{
SERVER_PORT: "8126",
}
}*/