Documentation
¶
Index ¶
- Constants
- func Address() string
- func AllowedOrigins() []string
- func ClientID() string
- func Create(override *Config) error
- func EnableCORS() bool
- func EnableRequestLogging() bool
- func EnableTLS() bool
- func Experimental() bool
- func IdleTimeout() int
- func Load() error
- func LogLevel() string
- func MaxHeaderBytes() int
- func New() error
- func Port() string
- func ReadTimeout() int
- func RedirectUri() string
- func Scopes() []string
- func ShutdownTimeout() int
- func TLSCertFile() string
- func TLSKeyFile() string
- func WriteTimeout() int
- type Config
Constants ¶
const CONFIG = "./twitchgo.config.json"
Variables ¶
This section is empty.
Functions ¶
func AllowedOrigins ¶
func AllowedOrigins() []string
AllowedOrigins returns the list of allowed CORS origins.
func Create ¶
Create writes a configuration file with either default values or overrides provided by the user.
The file is written in JSON format with indentation for readability.
Returns an error if marshaling or writing to the file fails.
Example usage:
err := config.Create(&config.Config{Port: "8080"})
func EnableRequestLogging ¶
func EnableRequestLogging() bool
EnableRequestLogging indicates if request logging is enabled.
func Experimental ¶
func Experimental() bool
Experimental returns whether experimental features are enabled.
func IdleTimeout ¶
func IdleTimeout() int
IdleTimeout returns the server idle timeout duration in seconds.
func Load ¶
func Load() error
Load reads the configuration file from disk, parses the JSON content, and loads it into the package-level Config variable `c`.
If the config file does not exist, it will attempt to create one with default values.
Returns an error if reading or unmarshalling the file fails.
Example usage:
err := config.Load()
if err != nil {
// handle error
}
func MaxHeaderBytes ¶
func MaxHeaderBytes() int
MaxHeaderBytes returns the maximum size of request headers in bytes.
func New ¶
func New() error
New initializes the package configuration by loading the config file, if it hasn't already been loaded.
Returns an error if loading the configuration fails.
Example usage:
err := config.New()
if err != nil {
// handle error
}
func ReadTimeout ¶
func ReadTimeout() int
ReadTimeout returns the server read timeout duration in seconds.
func ShutdownTimeout ¶
func ShutdownTimeout() int
ShutdownTimeout returns the graceful shutdown timeout duration in seconds.
func TLSCertFile ¶
func TLSCertFile() string
TLSCertFile returns the path to the TLS certificate file.
func WriteTimeout ¶
func WriteTimeout() int
WriteTimeout returns the server write timeout duration in seconds.
Types ¶
type Config ¶
type Config struct {
Port string `json:"port"` // the port to use
Address string `json:"address"` // the address to use
Experimental bool `json:"experimental"` // whether or not to enable experimental middleware/endpoints
ReadTimeout int `json:"readTimeout"` // seconds
WriteTimeout int `json:"writeTimeout"` // seconds
IdleTimeout int `json:"idleTimeout"` // seconds
LogLevel string `json:"logLevel"` // e.g. "debug", "info", "disabled"
MaxHeaderBytes int `json:"maxHeaderBytes"` // the maximum number of bytes in a request header
EnableTLS bool `json:"enableTLS"` // whether or not TLS should be enabled
TLSCertFile string `json:"tlsCertFile"` // if TLS is in use, the file path for the certificate
TLSKeyFile string `json:"tlsKeyFile"` // if TLS is in use, the file path for the key
ShutdownTimeout int `json:"shutdownTimeout"` // graceful shutdown timeout seconds
EnableCORS bool `json:"enableCORS"` // whether the CORS middleware should be enabled
AllowedOrigins []string `json:"allowedOrigins"` // the allowed origins for CORS
EnableRequestLogging bool `json:"enableRequestLogging"` // whether request logging middleware should be enabled
Scopes []string `json:"scopes"` // the scopes to use for the client
RedirectUri string `json:"redirectUri"` // the url to redirect to from OAuth
ClientID string `json:"clientId"` // the client id for the bot
}
Config holds all the configurable parameters for the application. It is serialized/deserialized from JSON config file.