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 +}