Documentation ¶
Overview ¶
Package config provides configuration structures and utilities for the application.
This package includes configurations for:
- Application settings (AppConfig)
The configurations are typically loaded from a TOML file using the github.com/pelletier/go-toml package. The NewAppConfig function is responsible for reading and parsing the configuration file.
Usage:
config, err := config.NewAppConfig() if err != nil { log.Fatalf("Failed to load configuration: %v", err) }
The loaded configuration can then be used to set up various parts of the application, such as the server, database connection, and JWT authentication.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AppConfig ¶
type AppConfig struct { ServerAddress string `toml:"ServerAddress"` StaticPaths map[string]string `toml:"StaticPaths"` UseLogger bool `toml:"UseLogger"` LogOutput string `toml:"LogOutput"` LogFile string `toml:"LogFile"` ColorizeLogger bool `toml:"ColorizeLogger"` UseTLS bool `toml:"UseTLS"` UseAutoTLS bool `toml:"UseAutoTLS"` CertFile string `toml:"CertFile"` KeyFile string `toml:"KeyFile"` Domain string `toml:"Domain"` CacheDir string `toml:"CacheDir"` EnableCORS bool `toml:"EnableCORS"` CORSAllowOrigins []string `toml:"CORSAllowOrigins"` CORSAllowMethods []string `toml:"CORSAllowMethods"` RateLimit float64 `toml:"RateLimit"` RateBurst int `toml:"RateBurst"` }
AppConfig represents the application configuration. It contains various settings for server, logging, TLS, CORS, and rate limiting. These are mapped with toml tags from which the config is read in NewAppConfig.
func NewAppConfig ¶
NewAppConfig creates a new instance of AppConfig by reading from the config.toml file. It reads the config.toml file from the root directory and unmarshals the TOML data into an AppConfig instance. If the file is not found or cannot be read, it returns an error.
Returns:
- *AppConfig: A pointer to the loaded configuration
- error: An error if the configuration file cannot be read or parsed
func (*AppConfig) SetupMiddleware ¶
func (config *AppConfig) SetupMiddleware(echo *echo.Echo)
SetupMiddleware configures and sets up the middleware for the echo.Echo instance. This is where the middleware is set up, such as logging, CORS, and rate limiting. It takes a pointer to an AppConfig instance and an echo.Echo instance as arguments.
func (*AppConfig) SetupRenderer ¶
func (config *AppConfig) SetupRenderer(echo *echo.Echo)
SetupRenderer sets up the renderer for the application. It takes an echo.Echo instance as an argument and sets its Renderer field.
func (*AppConfig) SetupStaticFiles ¶
func (config *AppConfig) SetupStaticFiles(echo *echo.Echo)
SetupStaticFiles configures static file serving for the echo.Echo instance. It takes a pointer to an AppConfig instance and an echo.Echo instance as arguments. It sets up static file serving for each route specified in the AppConfig's [StaticPaths] map.
func (*AppConfig) StartServer ¶
func (config *AppConfig) StartServer(echo *echo.Echo)
StartServer starts the server based on the configuration. It handles different scenarios like AutoTLS, TLS, and standard HTTP. It takes an echo.Echo instance as an argument.