config

package
v0.0.0-...-3f9575c Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2019 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

config is the package that is doing the parsing of config.json into a Config object to be used for the application. It also include the creation of a new logfile.

Index

Constants

View Source
const (
	EnvProd = `Prod`
	EnvDev  = `Dev`
)

EnvProd , EnvDev point to the json attribute that is defined in config.json It is highly recommended not to change this but if you know what you are doing, feel free to change it.

Variables

View Source
var ConfigFileName = `config\config.json`

ConfigFileName is the filename where all configuration are stored. Change this to another filename if you want.

View Source
var LogFileName = `tiger.log`

LogFileName is the filename of the log. Change this to another filename if you want.

Functions

func NewLogFileName

func NewLogFileName() (*os.File, error)

NewLogFileName is to get a file that is created based on the LogFileName variable.

Types

type Config

type Config struct {
	Env  string
	Site struct {
		Name                 string
		Url                  string
		Port                 int
		LogToFile            bool
		LogLevel             string
		GracefulShutdownSec  int
		CheckAliveTimeoutSec int
		ReadTimeoutSec       int
		ReadHeaderTimeoutSec int
		WriteTimeoutSec      int
		IdleTimeoutSec       int
		MaxHeaderBytes       int
		StaticFilePath       string
		UrlRewrite           bool
	}
	Database struct {
		Name     string
		Host     string
		Port     int
		Username string
		Password string
	}
	TemplateConfig struct {
		Enable  bool
		Path    string
		FileExt string
	}
}

Config is the struct that contain all the configuration that is from config.json

func NewConfig

func NewConfig(env string) (*Config, error)

NewConfig is to get a singleton Config object from the package.

env parameter is passed in from caller. caller will attempt to get env based on below steps.

Step 1 attempt to read the value from environment variable called env
Step 2 if Step 1 fail, attempt to read from command-line option called env
Step 3 if step 2 fail, the env parameter will be ""
Step 4 if step 3 return as "", default to read from the json attribute called Env in config.json

the valid values for env is Dev , Prod
any other environment please amend config.json and config.go accordingly
to make adding new environment more flexible, please send suggestion to sohguanh@gmail.com

Jump to

Keyboard shortcuts

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