mirror of
https://github.com/mgerb/mywebsite
synced 2026-01-10 09:52:51 +00:00
merging back into one repo - not going to host on app engine - google won't allow me to connect to external database
This commit is contained in:
45
server/utils/config.go
Normal file
45
server/utils/config.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"mywebsite/server/controller/api"
|
||||
"mywebsite/server/db"
|
||||
)
|
||||
|
||||
//structure for application configurations
|
||||
type Config struct {
|
||||
Database db.DatabaseInfo `json:"database"`
|
||||
Api api.ApiInfo `json:"api"`
|
||||
Port int `json:"port"`
|
||||
}
|
||||
|
||||
//read the config file and return JsonObject struct
|
||||
func ReadConfig() Config {
|
||||
|
||||
log.Println("Reading config file...")
|
||||
|
||||
file, e := ioutil.ReadFile("./config.json")
|
||||
|
||||
if e != nil {
|
||||
log.Printf("File error: %v\n", e)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
log.Printf("%s\n", string(file))
|
||||
|
||||
//m := new(Dispatch)
|
||||
//var m interface{}
|
||||
var result Config
|
||||
|
||||
err := json.Unmarshal(file, &result)
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user