diff --git a/config/config.go b/config/config.go new file mode 100644 index 0000000..7baa905 --- /dev/null +++ b/config/config.go @@ -0,0 +1,30 @@ +package config + +import ( + "encoding/json" + "io/ioutil" + "log" +) + +//Stores the main configuration for the application +type Configuration struct { + ServerPort string +} + +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 { + log.Fatal("Unable to read log file") + } + //log.Print(configFile) + err = json.Unmarshal(configFile, &config) + if err != nil { + log.Print(err) + } + return config +} diff --git a/main.go b/main.go index 61ab231..06248e8 100644 --- a/main.go +++ b/main.go @@ -6,11 +6,13 @@ package main **/ import ( "github.com/thewhitetulip/Tasks/views" + "github.com/thewhitetulip/Tasks/config" "log" "net/http" ) func main() { + values := config.ReadConfig("config.json") views.PopulateTemplates() http.HandleFunc("/", views.ShowAllTasksFunc) http.HandleFunc("/complete/", views.CompleteTaskFunc) @@ -26,6 +28,6 @@ func main() { http.HandleFunc("/search/", views.SearchTaskFunc) //http.HandleFunc("/static/", ServeStaticFunc) http.Handle("/static/", http.FileServer(http.Dir("public"))) - log.Println("running server on 8080") - log.Fatal(http.ListenAndServe(":8080", nil)) + log.Println("running server on ", values.ServerPort) + log.Fatal(http.ListenAndServe(values.ServerPort, nil)) }