Created
November 22, 2013 04:37
-
-
Save technosophos/7594919 to your computer and use it in GitHub Desktop.
Code to accompany http://technosophos.com/2013/11/22/creating-a-cookoo-web-app.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "github.com/Masterminds/cookoo" | |
| "github.com/Masterminds/cookoo/web" | |
| "html/template" | |
| ) | |
| func main() { | |
| registry, router, context := cookoo.Cookoo() | |
| tpl := template.Must(template.New("main").ParseGlob("*.html")) | |
| context.Add("tpl", tpl) | |
| registry.Route("GET /", "The default home page"). | |
| Does(cookoo.AddToContext, "_"). | |
| Using("Title").WithDefault("Hello"). | |
| Using("Content").WithDefault("Hi there!"). | |
| Does(web.RenderHTML, "html"). | |
| Using("template").From("cxt:tpl"). | |
| Using("templateName").WithDefault("index.html"). | |
| Does(web.Flush, "out"). | |
| Using("content").From("cxt:html"). | |
| Using("contentType").WithDefault("text/html") | |
| web.Serve(registry, router, context) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment