2016-02-01 22:34:19 +08:00
|
|
|
/*
|
|
|
|
Configuration package is used to read the configuration file
|
|
|
|
config.json which stores the server port for current implementation
|
|
|
|
{
|
|
|
|
"ServerPort": ":8081"
|
|
|
|
}
|
|
|
|
*/
|
2016-01-23 18:33:10 +08:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"io/ioutil"
|
|
|
|
"log"
|
|
|
|
)
|
|
|
|
|
|
|
|
//Stores the main configuration for the application
|
|
|
|
type Configuration struct {
|
2016-01-23 18:34:33 +08:00
|
|
|
ServerPort string
|
2016-01-23 18:33:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var err error
|
|
|
|
var config Configuration
|
|
|
|
|
|
|
|
//ReadConfig will read the configuration json file to read the parameters
|
|
|
|
//which will be passed in the config file
|
|
|
|
func ReadConfig(fileName string) Configuration {
|
|
|
|
configFile, err := ioutil.ReadFile(fileName)
|
|
|
|
if err != nil {
|
2016-02-16 17:39:57 +08:00
|
|
|
log.Fatalf("Unable to read config file '%s'", fileName)
|
2016-01-23 18:33:10 +08:00
|
|
|
}
|
|
|
|
//log.Print(configFile)
|
|
|
|
err = json.Unmarshal(configFile, &config)
|
|
|
|
if err != nil {
|
|
|
|
log.Print(err)
|
|
|
|
}
|
|
|
|
return config
|
|
|
|
}
|