Clean up
This commit is contained in:
@@ -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.
|
||||
|
||||
22
src/main.go
22
src/main.go
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user