Configuration File

This file include all config required by project for successful running

database:
  drivers:
    mysql: &mysql
      driver: mysql
      host: localhost
      username: root
      password: root
      db_name: casbin
      port: 3306
    postgres: &postgres
      driver: postgres
      host: localhost
      username: postgres
      password: postgres
      port: 5432
      db_name: casbin
  default: *postgres

server: &server
  name: "Server Name"
  host: localhost
  port: 8080

profiler:
  enabled: false
  server: "http://localhost:4040"

paypal: &paypal
  client_id:
  secret:
  mode: live
  account:

redis:
  instances:
    redis: &redis
      driver: redis
      name: redis
      host: "localhost"
      port: 6379
      db: 0
  default: *redis

cache: *redis
session: *redis
storage: *redis
queue: *redis

mail:
  host:
  port:
  username:
  password:
  encryption: tls
  from_address: "itsursujit@gmail.com"
  from_name: "Sujit Baniya"

token:
  app_jwt_secret: SECRET_APP
  api_jwt_secret: SECRET_API
  expires_in: 3600
jwt:
  app:
    secret: SECRET_APP
    expire: 3600
  api:
    secret: SECRET_API
    expire: 3600

template:
  path: "resources/view"
  extension: ".html"

log:
  timefield: "timestamp"
  timeformat: "2006-01-02 15:04:05"
  graylog: &graylog
    host: localhost
    port: 12201
  file: &file
    path: "storage/logs"
    timeformat: "2006-01-02"
  console: &console
    level: "error"
    show: false
  info: *file
  warn: *file
  error: *file
  monitor: *graylog

auth:
  type: "casbin"

To make configuring the project quite easy, I've introduced both .env and yaml config. Any variables that are defined on .env overrides the value defined on config.yaml.

Config file includes configuration for different services

config/config.go

type AppConfig struct {
   Auth       AuthConfig `yaml:"auth"`
   Mail       Mail       `yaml:"mail"`
   Hash       Hash
   View       ViewConfig     `yaml:"view"`
   Cache      CacheConfig    `yaml:"cache"`
   Database   DatabaseConfig `yaml:"database"`
   Session    SessionConfig  `yaml:"session"`
   Queue      QueueConfig    `yaml:"queue"`
   PayPal     PayPalConfig   `yaml:"paypal"`
   JwtSecrets JwtSecrets     `yaml:"jwt"`
   Storage    StorageConfig  `yaml:"storage"`
   Server     ServerConfig   `yaml:"server"`
   Log        LogConfig      `yaml:"log"`
   Token      Token          `yaml:"token"`
   Profiler   ProfilerConfig `yaml:"profiler"`
   Flash      *flash.Flash
   GeoIP      *ip.GeoIpDB
   ConfigFile string
}

Here you can change values inside those keys in 3 different ways

  • Changing env-default in above code [NOTE RECOMMENDED]

  • Providing Variables in .env with respective values [RECOMMENDED]

  • Providing Values in config.yml

Last updated