Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A repo on how to use Plush outside Buffalo

License

NotificationsYou must be signed in to change notification settings

paganotoni/plgo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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.

Running this app

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.

Plush usage

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>...

About

A repo on how to use Plush outside Buffalo

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp