-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
37 lines (26 loc) · 838 Bytes
/
main.go
File metadata and controls
37 lines (26 loc) · 838 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//This is the name of the package
package main
import (
"fmt" //Library for I/O
"net/http" //for the creation of a web server
"github.com/gorilla/mux"
)
func NewRouter() *mux.Router {
//This is a constructor function It creates a router object using gorilla
r := mux.NewRouter()
r.HandleFunc("/hello", handler).Methods("GET")
//This is the file directory in html
staticFileDirectory := http.Dir("./assets/")
staticfileHandler := http.StripPrefix("/assets/", http.FileServer(staticFileDirectory))
r.PathPrefix("/assets/").Handler(staticfileHandler).Methods("GET")
return r
}
func main() {
//This just creates a router function and
//listens and serve in the 8080 port.
r := NewRouter()
http.ListenAndServe(":8080", r)
}
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello World")
}