From 92cbe02e2e69b6eda55ebbef5a35822f70991682 Mon Sep 17 00:00:00 2001 From: Mitchell Date: Wed, 11 May 2016 23:44:15 -0500 Subject: [PATCH] setting up folder structures --- controller/index.go | 18 ++++++++++++++++++ main.go | 16 ++++++++++++++++ public/test.html | 1 + route/route.go | 22 ++++++++++++++++++++++ 4 files changed, 57 insertions(+) create mode 100644 controller/index.go create mode 100644 main.go create mode 100644 public/test.html create mode 100644 route/route.go diff --git a/controller/index.go b/controller/index.go new file mode 100644 index 0000000..a10dced --- /dev/null +++ b/controller/index.go @@ -0,0 +1,18 @@ +package controller + +import ( + //"encoding/json" + "fmt" + "github.com/julienschmidt/httprouter" + "net/http" +) + +// IndexGET displays the home page +func IndexGet(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { + + w.Header().Set("Content-Type", "application/json") + response := "{\"test\" : 123}" + + fmt.Fprint(w, response) + +} diff --git a/main.go b/main.go new file mode 100644 index 0000000..58ffbe8 --- /dev/null +++ b/main.go @@ -0,0 +1,16 @@ +package main + +import ( + //"fmt" + //"github.com/julienschmidt/httprouter" + "log" + "net/http" + + "github.com/mgerb42/mywebsite/route" +) + +func main() { + + log.Fatal(http.ListenAndServe(":8080", route.Routes())) + +} diff --git a/public/test.html b/public/test.html new file mode 100644 index 0000000..30d74d2 --- /dev/null +++ b/public/test.html @@ -0,0 +1 @@ +test \ No newline at end of file diff --git a/route/route.go b/route/route.go new file mode 100644 index 0000000..cad3613 --- /dev/null +++ b/route/route.go @@ -0,0 +1,22 @@ +package route + +import ( + //"encoding/json" + //"fmt" + "github.com/julienschmidt/httprouter" + "net/http" + + "github.com/mgerb42/mywebsite/controller" +) + +func Routes() *httprouter.Router { + + r := httprouter.New() + + r.GET("/", controller.IndexGet) + + //set up public folder path + r.ServeFiles("/public/*filepath", http.Dir("./public")) + + return r +}