mirror of
https://github.com/documize/community.git
synced 2025-07-19 05:09:42 +02:00
Look for implicit documize.conf
@harveykandola Now looks for implicit documize.conf, then specified .conf, then fallback to flags and envars.
This commit is contained in:
parent
1fefdaec9f
commit
34d1639899
5 changed files with 1173 additions and 1153 deletions
1
core/env/flags.go
vendored
1
core/env/flags.go
vendored
|
@ -23,6 +23,7 @@ type Flags struct {
|
||||||
SSLKeyFile string // (optional) name of SSL key PEM file
|
SSLKeyFile string // (optional) name of SSL key PEM file
|
||||||
SiteMode string // (optional) if 1 then serve offline web page
|
SiteMode string // (optional) if 1 then serve offline web page
|
||||||
Location string // reserved
|
Location string // reserved
|
||||||
|
ConfigSource string // tells us if configuration info was obtained from command line or config file
|
||||||
}
|
}
|
||||||
|
|
||||||
// SSLEnabled returns true if both cert and key were provided at runtime.
|
// SSLEnabled returns true if both cert and key were provided at runtime.
|
||||||
|
|
42
core/env/parser.go
vendored
42
core/env/parser.go
vendored
|
@ -21,10 +21,10 @@ import (
|
||||||
"github.com/BurntSushi/toml"
|
"github.com/BurntSushi/toml"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ParseFlags loads runtime parameters like port numbers and DB connections.
|
// LoadConfig loads runtime parameters like port numbers and DB connections.
|
||||||
// We first check for -config switch that would point us towards a .CONF file.
|
// We first check for -config switch that would point us towards a .CONF file.
|
||||||
// If not found, we then read parameters from command line and environment vars.
|
// If not found, we then read parameters from command line and environment vars.
|
||||||
func ParseFlags() (f Flags, ok bool) {
|
func LoadConfig() (f Flags, ok bool) {
|
||||||
// Check and process config file
|
// Check and process config file
|
||||||
f, ok = configFile()
|
f, ok = configFile()
|
||||||
|
|
||||||
|
@ -33,24 +33,45 @@ func ParseFlags() (f Flags, ok bool) {
|
||||||
f, ok = commandLineEnv()
|
f, ok = commandLineEnv()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// reserved
|
||||||
|
if len(f.Location) == 0 {
|
||||||
|
f.Location = "selfhost"
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// configFile checks for the presence of exactly one command argument
|
// configFile checks for the presence of zero or one command argument.
|
||||||
|
// If no arguments are provided then we look for and load documize.conf file.
|
||||||
|
// If one argument is provided then we load the specified config file.
|
||||||
|
// If more than one argument is provided then we exit as flags as have passed.
|
||||||
// checks to see if it is a TOML format config file.
|
// checks to see if it is a TOML format config file.
|
||||||
func configFile() (f Flags, ok bool) {
|
func configFile() (f Flags, ok bool) {
|
||||||
ok = false
|
ok = false
|
||||||
|
|
||||||
// We are expecting: ./documize sample.conf
|
|
||||||
var configFile string
|
var configFile string
|
||||||
if len(os.Args) != 2 {
|
|
||||||
|
// First argument is always program being executed.
|
||||||
|
|
||||||
|
// No additional arguments means check for documize.conf file.
|
||||||
|
if len(os.Args) == 1 {
|
||||||
|
// No arguments, so we default to default config filename.
|
||||||
|
configFile = "documize.conf"
|
||||||
|
} else if len(os.Args) == 2 {
|
||||||
|
// Config filename passed in, so we use it.
|
||||||
|
configFile = os.Args[1]
|
||||||
|
} else {
|
||||||
|
// Too many arguments means flags passed in so we return.
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
configFile = os.Args[1]
|
|
||||||
|
// Does file exist?
|
||||||
if len(configFile) == 0 || !configFileExists(configFile) {
|
if len(configFile) == 0 || !configFileExists(configFile) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tell caller where the config came from.
|
||||||
|
f.ConfigSource = configFile
|
||||||
|
|
||||||
// So now we have file and we parse the TOML format.
|
// So now we have file and we parse the TOML format.
|
||||||
var ct ConfigToml
|
var ct ConfigToml
|
||||||
if _, err := toml.DecodeFile(configFile, &ct); err != nil {
|
if _, err := toml.DecodeFile(configFile, &ct); err != nil {
|
||||||
|
@ -66,6 +87,7 @@ func configFile() (f Flags, ok bool) {
|
||||||
f.ForceHTTPPort2SSL = strconv.Itoa(ct.HTTP.ForceSSLPort)
|
f.ForceHTTPPort2SSL = strconv.Itoa(ct.HTTP.ForceSSLPort)
|
||||||
f.SSLCertFile = ct.HTTP.Cert
|
f.SSLCertFile = ct.HTTP.Cert
|
||||||
f.SSLKeyFile = ct.HTTP.Key
|
f.SSLKeyFile = ct.HTTP.Key
|
||||||
|
f.Location = strings.ToLower(ct.Install.Location)
|
||||||
|
|
||||||
ok = true
|
ok = true
|
||||||
return
|
return
|
||||||
|
@ -99,12 +121,8 @@ func commandLineEnv() (f Flags, ok bool) {
|
||||||
f.SiteMode = siteMode
|
f.SiteMode = siteMode
|
||||||
f.SSLCertFile = certFile
|
f.SSLCertFile = certFile
|
||||||
f.SSLKeyFile = keyFile
|
f.SSLKeyFile = keyFile
|
||||||
|
|
||||||
// reserved
|
|
||||||
if len(location) == 0 {
|
|
||||||
location = "selfhost"
|
|
||||||
}
|
|
||||||
f.Location = strings.ToLower(location)
|
f.Location = strings.ToLower(location)
|
||||||
|
f.ConfigSource = "flags/environment"
|
||||||
|
|
||||||
return f, ok
|
return f, ok
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,16 +28,16 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// runtime stores server/application level information
|
// Runtime stores server/application information.
|
||||||
rt := env.Runtime{}
|
rt := env.Runtime{}
|
||||||
|
|
||||||
// wire up logging implementation
|
// Wire up logging implementation.
|
||||||
rt.Log = logging.NewLogger(false)
|
rt.Log = logging.NewLogger(false)
|
||||||
|
|
||||||
// wire up embedded web assets handler
|
// Wire up embedded web assets handler.
|
||||||
web.Embed = embed.NewEmbedder()
|
web.Embed = embed.NewEmbedder()
|
||||||
|
|
||||||
// product details
|
// Specify the product edition.
|
||||||
rt.Product = domain.Product{}
|
rt.Product = domain.Product{}
|
||||||
rt.Product.Major = "2"
|
rt.Product.Major = "2"
|
||||||
rt.Product.Minor = "4"
|
rt.Product.Minor = "4"
|
||||||
|
@ -50,21 +50,24 @@ func main() {
|
||||||
// Setup data store.
|
// Setup data store.
|
||||||
s := store.Store{}
|
s := store.Store{}
|
||||||
|
|
||||||
// Parse flags/envars.
|
// Parse configuration information.
|
||||||
flagsOK := false
|
flagsOK := false
|
||||||
rt.Flags, flagsOK = env.ParseFlags()
|
rt.Flags, flagsOK = env.LoadConfig()
|
||||||
if !flagsOK {
|
if !flagsOK {
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
rt.Log.Info("Configuration source: " + rt.Flags.ConfigSource)
|
||||||
|
|
||||||
|
// Start database init.
|
||||||
bootOK := boot.InitRuntime(&rt, &s)
|
bootOK := boot.InitRuntime(&rt, &s)
|
||||||
if bootOK {
|
if bootOK {
|
||||||
// runtime.Log = runtime.Log.SetDB(runtime.Db)
|
// runtime.Log = runtime.Log.SetDB(runtime.Db)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register smart sections
|
// Register document sections.
|
||||||
section.Register(&rt, &s)
|
section.Register(&rt, &s)
|
||||||
|
|
||||||
|
// Start web server.
|
||||||
ready := make(chan struct{}, 1) // channel signals router ready
|
ready := make(chan struct{}, 1) // channel signals router ready
|
||||||
server.Start(&rt, &s, ready)
|
server.Start(&rt, &s, ready)
|
||||||
}
|
}
|
||||||
|
|
2264
embed/bindata.go
2264
embed/bindata.go
File diff suppressed because one or more lines are too long
|
@ -124,8 +124,6 @@ func Start(rt *env.Runtime, s *store.Store, ready chan struct{}) {
|
||||||
|
|
||||||
rt.Log.Info("Web Server: starting SSL server on " + rt.Flags.HTTPPort + " with " + rt.Flags.SSLCertFile + " " + rt.Flags.SSLKeyFile)
|
rt.Log.Info("Web Server: starting SSL server on " + rt.Flags.HTTPPort + " with " + rt.Flags.SSLCertFile + " " + rt.Flags.SSLKeyFile)
|
||||||
|
|
||||||
// TODO: https://blog.gopheracademy.com/advent-2016/exposing-go-on-the-internet/
|
|
||||||
|
|
||||||
server := &http.Server{Addr: ":" + rt.Flags.HTTPPort, Handler: n /*, TLSConfig: myTLSConfig*/}
|
server := &http.Server{Addr: ":" + rt.Flags.HTTPPort, Handler: n /*, TLSConfig: myTLSConfig*/}
|
||||||
server.SetKeepAlivesEnabled(true)
|
server.SetKeepAlivesEnabled(true)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue