new config package
This commit is contained in:
parent
3a3adb35c3
commit
825fc379e0
|
@ -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
|
||||
}
|
6
main.go
6
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))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue