Add more config options.
Add an option to suppress HTTP-related logs and to disable HTTP keep-alives.
This commit is contained in:
parent
45abac7a2d
commit
717802d4f1
|
@ -50,3 +50,10 @@ redirects:
|
|||
|
||||
# The minimum API version to enable.
|
||||
# min_api_version: 2
|
||||
|
||||
# Suppresses any HTTP-related logs such as TLS handshake errors. This does not
|
||||
# suppress any logs generated by lurkcoin.
|
||||
# suppress_http_logs: false
|
||||
|
||||
# Disables HTTP keep-alive support.
|
||||
# disable_http_keepalives: false
|
||||
|
|
|
@ -21,6 +21,7 @@ package api
|
|||
import (
|
||||
"fmt"
|
||||
"gopkg.in/yaml.v2"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"lurkcoin"
|
||||
"lurkcoin/databases"
|
||||
|
@ -65,6 +66,12 @@ type Config struct {
|
|||
|
||||
// The minimum HTTPS API version to support.
|
||||
MinAPIVersion uint8 `yaml:"min_api_version"`
|
||||
|
||||
// Suppresses any HTTP-related logs such as TLS handshake errors.
|
||||
SuppressHTTPLogs bool `yaml:"suppress_http_logs"`
|
||||
|
||||
// Disables HTTP keep-alives.
|
||||
DisableHTTPKeepAlives bool `yaml:"disable_http_keepalives"`
|
||||
}
|
||||
|
||||
func LoadConfig(filename string) (*Config, error) {
|
||||
|
@ -133,10 +140,16 @@ func StartServer(config *Config) {
|
|||
log.SetOutput(f)
|
||||
}
|
||||
|
||||
// Suppress HTTP logs.
|
||||
server := &http.Server{Addr: address, Handler: router}
|
||||
if config.SuppressHTTPLogs {
|
||||
server.ErrorLog = log.New(ioutil.Discard, "", 0)
|
||||
}
|
||||
|
||||
// My laptop doesn't work nicely with Keep-Alive.
|
||||
if config.DisableHTTPKeepAlives {
|
||||
server.SetKeepAlivesEnabled(false)
|
||||
}
|
||||
|
||||
if config.TLS.Enable {
|
||||
err = server.ListenAndServeTLS(config.TLS.CertFile, config.TLS.KeyFile)
|
||||
|
|
Loading…
Reference in New Issue