|
2 | 2 |
|
3 | 3 | web.go is the simplest way to write web applications in the Go programming language.
|
4 | 4 |
|
| 5 | +See [www.getwebgo.com](http://www.getwebgo.com) for complete documentation. |
| 6 | + |
5 | 7 | ## Overview
|
6 | 8 |
|
7 | 9 | web.go should be familiar to people who've developed websites with higher-level web frameworks like sinatra, pylons, or web.py. It is designed to be a lightweight web framework that doesn't impose any scaffolding on the user. Some features include:
|
8 | 10 |
|
9 |
| -* routing to url handlers based on regular expressions |
10 |
| -* helper methods for rendering templates |
11 |
| -* web applications are compiled to native code, which means very fast page render times (order-of-magnitude improvement over python or ruby frameworks) |
| 11 | +* Routing to url handlers based on regular expressions |
| 12 | +* Support for user sessions |
| 13 | +* Web applications are compiled to native code. This means very fast execution and page render speed ( benchmarks coming soon :) |
12 | 14 |
|
13 | 15 | To use web.go, simply install it and import the "web" package. You then need to map url routes to function handlers using web.Get, web.Post, etc.. Finally, you need to call web.Run with the address of the host. (see the example below)
|
14 | 16 |
|
15 | 17 | ## Installation
|
16 | 18 |
|
17 |
| -1. Make sure you have the latest Go sources (hg sync in the go tree), and your environment is set up correctly: $GOROOT, $GOARCH, $GOBIN, etc. |
18 |
| -2. Checkout the code |
| 19 | +1. Make sure you have the a working Go environment. See the [install instructions](http://golang.org/doc/install.html) |
| 20 | +2. git clone git://github.com/hoisie/web.go.git |
19 | 21 | 3. cd web.go && make install
|
20 | 22 |
|
21 | 23 | ## Example
|
22 | 24 |
|
23 | 25 | package main
|
24 | 26 |
|
25 | 27 | import (
|
26 |
| - "fmt" |
27 | 28 | "web"
|
28 | 29 | )
|
29 | 30 |
|
30 |
| - func hello(val string) string { |
31 |
| - return fmt.Sprintf("hello %s", val) |
32 |
| - } |
| 31 | + func hello(val string) string { return "hello " + val } |
33 | 32 |
|
34 | 33 | func main() {
|
35 | 34 | web.Get("/(.*)", hello)
|
36 | 35 | web.Run("0.0.0.0:9999")
|
37 | 36 | }
|
38 | 37 |
|
39 | 38 |
|
40 |
| -### Adding route handlers |
41 |
| - |
42 |
| -We add a handler that matches the url path "/today". This will return the current url path. |
43 |
| - |
44 |
| - package main |
45 |
| - |
46 |
| - import ( |
47 |
| - "fmt" |
48 |
| - "time" |
49 |
| - "web" |
50 |
| - ) |
51 |
| - |
52 |
| - func index() string { |
53 |
| - return "Welcome!" |
54 |
| - } |
| 39 | +To run the application, put the code in a file called hello.go and run: |
55 | 40 |
|
56 |
| - func today() string { |
57 |
| - return fmt.Sprintf("The time is currently %s", time.LocalTime().Asctime()) |
58 |
| - } |
59 |
| - |
60 |
| - func main() { |
61 |
| - web.Get("/today", today) |
62 |
| - web.Get("/", index) |
63 |
| - web.Run("0.0.0.0:9999") |
64 |
| - } |
65 |
| - |
66 |
| -Then stop the application and recompile it . You can point your browser to http://localhost:9999/today to see the new route. |
| 41 | + 8g hello.go && 8l -o hello hello.8 && ./hello |
67 | 42 |
|
68 |
| -## Roadmap |
| 43 | +You can point your browser to http://localhost:9999/world . |
69 | 44 |
|
70 |
| -Future releases will support: |
| 45 | +## Documentation |
71 | 46 |
|
72 |
| -* fastcgi and proxying support |
73 |
| -* an interface to write real-time applications (for long-polling) |
74 |
| -* a better template system |
75 |
| -* cookie-based sessions with storage |
| 47 | +More documentation, including a tutorial and API docs, is available on [web.go's home page][http://www.getwebgo.com] |
76 | 48 |
|
77 | 49 | ## About
|
78 | 50 |
|
79 |
| -web.go was written by Michael Hoisie. Follow me on [Twitter](http://www.twitter.com/hoisie)! |
| 51 | +web.go was written by [Michael Hoisie](http://hoisie.com). |
| 52 | + |
| 53 | +Follow me on [Twitter](http://www.twitter.com/hoisie)! |
80 | 54 |
|
0 commit comments