I just wanted to announce the first 'official' release of web.go. I've
been meaning to do it for some time, but I kept pushing it back for
some reason.
Web.go is a simple web framework for Go. It has some nice features
including (among other things) regex url handling, fcgi/scgi support,
cookies and secure cookies, and multipart file encoding.
I've used it to build a couple public web apps (and a few more
personal ones).
* a facebook app with ~200 active users (
http://www.facebook.com/apps/application.php?id=135488932982 )
* the doc site: http://getwebgo.com
Used in conjunction with a template library (such as mustache.go), and
a data storage library (I'd recommend Go-Redis), you have a pretty
efficient system for building web applications.
Next iteration I'd like to add a system for crash-recovery, and test
building real-time apps.
Let me know if you find this useful, or if you're building anything
with it :)
Mike
http://github.com/hoisie/web.go
As you can see it's a work in progress :)
Mike
Hi Mike, do you have any plan to combine template module(like
mustache.go) in it as default? Or you wanna leave the choice to users?
Originally the mustache template code was just part of web.go, but I
figured that it could be useful in other places, so I just refactored
it into a separate project.
Then I tried making it a git submodule of web.go, but that made
installation more confusing.
So yes, for now I'll just let the user decide whatever template module
they want, and recommend mustache as the default. This isn't a really
tough decision right now, though, because the pkg/template module
really is not suitable for web sites. However if Go gets an eval
module down the line, there could be some more interesting options.
- Mike
why not?
1. The default delimiter '{' and '}' is not appropriate for html
because of embedded css and javascript. You can change it , of
course, but you have to do it programatically. It would be a lot more
convenient to have a directive in the template to change the
delimiter.
2. There isn't way to embed templates within each other. Most web
sites have a pretty standard header, footer, and content container
sections. So you should be able to define these in a separate template
files and nest them within each other.
Mustache addresses these two issues : http://github.com/defunkt/mustache
( see the partial and set delimiter sections ). However, it's still
considered a 'primitive' template library for ruby :)
- Mike
> It's mostly two reasons:
>
> 1. The default delimiter '{' and '}' is not appropriate for html
> because of embedded css and javascript. You can change it , of
> course, but you have to do it programatically. It would be a lot more
> convenient to have a directive in the template to change the
> delimiter.
Easy to add to the template library but also easy to avoid needing to add. Template parses a string. How about putting whatever directive you want on the first line and passing the rest to Parse?
> 2. There isn't way to embed templates within each other. Most web
> sites have a pretty standard header, footer, and content container
> sections. So you should be able to define these in a separate template
> files and nest them within each other.
It's trivial to embed. Just put a template inside the data you execute.
////
package main
import (
"bytes"
"os"
"template"
)
var T1 = "body of web page\n"
var T2 = "header\n{embed}footer\n"
type D struct {
embedding *template.Template
}
func (d *D) embed() string {
var b bytes.Buffer
d.embedding.Execute(0, &b)
return b.String()
}
func main() {
t1 := template.MustParse(T1, nil)
d := &D{t1}
t2 := template.MustParse(T2, nil)
t2.Execute(d, os.Stdout)
}
////
prints
header
body of web page
footer
Set the "embedding" field to any template you want. You can do stuff like execute something in the inner one to extract a field to expand, and so on.
-rob
You can use {.meta-right} and {.meta-left} in your embedded js/css. Annoying
probably, but works.
This is a sample go template that will be parsed fine
/*
{projname}
Replace this: This is your projects main file.
Copyright 2010, {author} <{email}>, website: http://{website}
*/
package main
import (
)
func main() {.meta-left}
{.meta-right}
Mike
--
They sentenced me to twenty years of boredom for trying to change the
system from within. I'm coming now I'm coming to reward them. First
we take Manhattan, then we take Berlin.
I'm guided by a signal in the heavens. I'm guided by this birthmark on
my skin. I'm guided by the beauty of our weapons. First we take Manhattan,
then we take Berlin.
I'd really like to live beside you, baby. I love your body and your spirit
and your clothes. But you see that line there moving through the station?
I told you I told you I told you I was one of those.
-- Leonard Cohen, "First We Take Manhattan"
Some people prefer the opposite . They like to build the template with
code and some embedded HTML. Just take a look at erector:
http://github.com/pivotal/erector . I personally think that's weird,
but it seems to be fairly popular.
I'm not saying that pkg/template can't get the job done. It clearly
can (just take a look at the golang.org), it's just a matter of
taste.
> signature.asc
> < 1KViewDownload
This works only if the embedded part is "small" enough. Imagine the
embedded part is a long run of something you need to have the whole
thing in the memory before it can finally be output.
-Ivan.
--
Ivan Wong <iva...@gmail.com>
GPG: 1024D/40510AB7: 88BF A832 50D7 30F0 3850 DE17 049D A727 4051 0AB7