- Notifications
You must be signed in to change notification settings - Fork0
A repo on how to use Plush outside Buffalo
License
NotificationsYou must be signed in to change notification settings
paganotoni/plgo
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Plgo is a sample repo for how to usePlush without Buffalo. While this is not a complete application it is a good starting point for your own projects.
To run this app you need Go 1.16+. The app can be run within the root folder invoking the following command:
go run cmd/plgo
Which should start the app on port 8080.
Main plush usage is in thelanding.go file. In there we set some variables on the http handlerFunc that then we execute with plush.
funcLanding(w http.ResponseWriter,r*http.Request) {c:=plush.NewContextWithContext(r.Context())// Setup a plush context from the request contextc.Set("title","This is a plush template")// Setting some variables to be used by plushc.Set("items", []string{"one","two","three"})s,err:=plush.Render(landingHTML,c)// rendering the templateiferr!=nil {http.Error(w,err.Error(),http.StatusInternalServerError)return}w.Write([]byte(s))// Writing the template to the response writer}
And the html file is:
...<body><h2><%= title %></h2><p>This is a sample of using plush in Go</p><ul><%= for (k) in items { %><li><%= k %></li><% } %></ul></body>...