mirror of
https://github.com/mgerb/mywebsite
synced 2026-01-11 10:22:53 +00:00
setting up folder structures
This commit is contained in:
18
controller/index.go
Normal file
18
controller/index.go
Normal file
@@ -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)
|
||||
|
||||
}
|
||||
16
main.go
Normal file
16
main.go
Normal file
@@ -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()))
|
||||
|
||||
}
|
||||
1
public/test.html
Normal file
1
public/test.html
Normal file
@@ -0,0 +1 @@
|
||||
test
|
||||
22
route/route.go
Normal file
22
route/route.go
Normal file
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user