Announcing web.go 0.1.0

35 views
Skip to first unread message

Michael Hoisie

unread,
Jan 24, 2010, 10:44:27 PM1/24/10
to golang-nuts
Hey Go users,

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

Michael Hoisie

unread,
Jan 24, 2010, 10:45:29 PM1/24/10
to golang-nuts
Oops, forgot to include the link :)

http://github.com/hoisie/web.go

yunhui song

unread,
Jan 24, 2010, 11:23:16 PM1/24/10
to Michael Hoisie, golang-nuts
Cool project. I'm trying to implement REST API on a apache server. 

On my virtual web hosting, it is a apache which support fastcgi and cgi.  I'd like use GWT to write the pages and use fastcgi+go apps to implement the rest service. Json will be used as data format between gwt and go code.

You mentioned web.go support fastcgi, I haven't found the doc or sample code in your github site, could you help me out?

Thanks,
Sammi

Michael Hoisie

unread,
Jan 25, 2010, 12:05:30 AM1/25/10
to golang-nuts
Thanks, I added a section in the tutorial about running web.go in
shared hosts:

http://getwebgo.com/tutorial

As you can see it's a work in progress :)
Mike

Mad Go

unread,
Jan 25, 2010, 12:45:19 AM1/25/10
to golang-nuts
Great,I'm using it now.

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?

Michael Hoisie

unread,
Jan 25, 2010, 3:25:56 AM1/25/10
to golang-nuts
Hi Mad,

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

Russ Cox

unread,
Jan 25, 2010, 3:31:45 AM1/25/10
to Michael Hoisie, golang-nuts
> tough decision right now, though, because the pkg/template module
> really is not suitable for web sites.

why not?

Michael Hoisie

unread,
Jan 25, 2010, 3:50:37 AM1/25/10
to golang-nuts
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.

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

Rob 'Commander' Pike

unread,
Jan 25, 2010, 4:55:25 AM1/25/10
to Michael Hoisie, golang-nuts

On 25/01/2010, at 7:50 PM, Michael Hoisie wrote:

> 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

Mad Go

unread,
Jan 25, 2010, 11:23:51 AM1/25/10
to golang-nuts
Go is a great language, so it would/must have lots of third party
libraries, anyway, I really appreciate Mike, thanks for your libraries.

Mike Ramirez

unread,
Jan 25, 2010, 10:50:56 AM1/25/10
to golan...@googlegroups.com
On Monday 25 January 2010 00:50:37 Michael Hoisie wrote:
> 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.
>

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"

signature.asc

Michael Hoisie

unread,
Jan 25, 2010, 12:16:40 PM1/25/10
to golang-nuts
I think template systems are a matter of taste. I like to keep my
templates as separate as possible my code. I don't want to set the
delimiters in my code, or build up the final text in my code. This is
possible with mustache.

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

Ivan Wong

unread,
Feb 14, 2010, 2:14:51 PM2/14/10
to golang-nuts
Rob 'Commander' Pike wrote:
> On 25/01/2010, at 7:50 PM, Michael Hoisie wrote:
>
>> 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.

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

Reply all
Reply to author
Forward
0 new messages