This commit is contained in:
Jacob Gunther
2023-04-23 21:05:09 -05:00
parent 91ca9fb11e
commit 70419c178e
5 changed files with 27 additions and 21 deletions

View File

@@ -10,8 +10,9 @@ import (
var (
// DefaultConfig is the default configuration values used by the application.
DefaultConfig *Config = &Config{
Host: "127.0.0.1",
Port: 3001,
Environment: "development",
Host: "127.0.0.1",
Port: 3001,
Redis: RedisConfig{
Host: "127.0.0.1",
Port: 6379,
@@ -91,11 +92,12 @@ var (
// Config is the root configuration object for the application.
type Config struct {
Host string `yaml:"host"`
Port uint16 `yaml:"port"`
Redis RedisConfig `yaml:"redis"`
Routes RoutesConfig `yaml:"routes"`
Cache CacheConfig `yaml:"cache"`
Environment string `yaml:"environment"`
Host string `yaml:"host"`
Port uint16 `yaml:"port"`
Redis RedisConfig `yaml:"redis"`
Routes RoutesConfig `yaml:"routes"`
Cache CacheConfig `yaml:"cache"`
}
// RoutesConfig is the configuration data of all API routes.

View File

@@ -7,8 +7,8 @@ import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/gofiber/fiber/v2/middleware/logger"
"github.com/gofiber/fiber/v2/middleware/recover"
"github.com/joho/godotenv"
)
var (
@@ -27,8 +27,6 @@ var (
func init() {
var err error
godotenv.Load()
if err = conf.ReadFile("config.yml"); err != nil {
log.Fatal(err)
}
@@ -40,11 +38,19 @@ func init() {
log.Println("Successfully connected to Redis")
app.Use(recover.New())
app.Use(cors.New(cors.Config{
AllowOrigins: "*",
AllowMethods: "HEAD,OPTIONS,GET",
ExposeHeaders: "Content-Type,Content-Disposition,X-Cache-Hit",
}))
if conf.Environment == "development" {
app.Use(cors.New(cors.Config{
AllowOrigins: "*",
AllowMethods: "HEAD,OPTIONS,GET",
ExposeHeaders: "X-Cache-Hit,X-Cache-Time-Remaining",
}))
app.Use(logger.New(logger.Config{
Format: "${time} ${ip}:${port} -> ${status}: ${method} ${path} (${latency})\n",
TimeFormat: "2006/01/02 15:04:05",
}))
}
}
func main() {