config

package
v1.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const CONFIG = "./twitchgo.config.json"

Variables

This section is empty.

Functions

func Address

func Address() string

Address returns the configured server address.

func AllowedOrigins

func AllowedOrigins() []string

AllowedOrigins returns the list of allowed CORS origins.

func ClientID

func ClientID() string

ClientID returns the client id for the bot

func Create

func Create(override *Config) error

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 EnableCORS

func EnableCORS() bool

EnableCORS returns true if CORS support is enabled.

func EnableRequestLogging

func EnableRequestLogging() bool

EnableRequestLogging indicates if request logging is enabled.

func EnableTLS

func EnableTLS() bool

EnableTLS indicates if TLS 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 LogLevel

func LogLevel() string

LogLevel returns the configured logging level.

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 Port

func Port() string

Port returns the configured server port.

func ReadTimeout

func ReadTimeout() int

ReadTimeout returns the server read timeout duration in seconds.

func RedirectUri

func RedirectUri() string

RedirectUri returns the URL to redirect to for OAuth

func Scopes

func Scopes() []string

Scopes returns a list of scopes to use for the client

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 TLSKeyFile

func TLSKeyFile() string

TLSKeyFile returns the path to the TLS key 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL