Skip to content

Commit f919f15

Browse files
committed
update
1 parent b291800 commit f919f15

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

README.md

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ It has built-in CORS and Method based routing.
1919

2020
#### [REST Service Example](https://github.com/GolangToolKits/grrtRouterRestExample)
2121

22+
#### [Web Example](https://github.com/GolangToolKits/grrtRouterWebSiteExample)
23+
2224
Package `GolangToolKits/grrt` implements a request router and dispatcher for handling incoming requests to their associated handler.
2325

2426
The name mux stands for "HTTP request multiplexer". Like the standard `http.ServeMux`, `grrt.Router` matches incoming requests against a list of registered routes and calls a handler for the route that matches the URL. The main features are:
@@ -103,7 +105,50 @@ func main() {
103105

104106
## WebExample
105107

108+
#### [Web Full Example](https://github.com/GolangToolKits/grrtRouterWebSiteExample)
109+
106110
```go
107-
//Comming soon
111+
112+
import (
113+
"fmt"
114+
"html/template"
115+
"net/http"
116+
"os"
117+
"strconv"
118+
119+
mux "github.com/GolangToolKits/grrt"
120+
hd "github.com/GolangToolKits/grrtRouterWebSiteExample/handlers"
121+
)
122+
123+
func main() {
124+
125+
var sh hd.SiteHandler
126+
127+
sh.Templates = template.Must(template.ParseFiles("./static/index.html",
128+
"./static/product.html", "./static/addProduct.html"))
129+
130+
router := mux.NewRouter()
131+
132+
h := sh.New()
133+
134+
router.HandleFunc("/", h.Index).Methods("GET")
135+
router.HandleFunc("/product/{id}/{sku}", h.ViewProduct).Methods("GET")
136+
router.HandleFunc("/addProduct", h.AddProduct).Methods("POST")
137+
138+
port := "8080"
139+
envPort := os.Getenv("PORT")
140+
if envPort != "" {
141+
portInt, _ := strconv.Atoi(envPort)
142+
if portInt != 0 {
143+
port = envPort
144+
}
145+
}
146+
147+
router.PathPrefix("/").Handler(http.FileServer(http.Dir("./static/")))
148+
149+
fmt.Println("Web UI is running on port 8080!")
150+
151+
http.ListenAndServe(":"+port, (router))
152+
}
108153

109154
```

0 commit comments

Comments
 (0)