You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: tutorial.md
+26-2Lines changed: 26 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -50,8 +50,12 @@ In that example, everything after the `/` is passed to the argument _val_ in the
50
50
51
51
Although handlers usually return a string, web.go also accepts route handlers that have no return value. These methods are responsible for writing data to the client:
Writing to the context variable is explained in a later section.
56
60
57
61
## The web.Context
@@ -79,6 +83,14 @@ Here is a brief summary of web.Context:
79
83
80
84
Web.go doesn't include a templating library. However, there are several good ones available, such as [mustache.go](http://github.com/hoisie/mustache). The template package in Go is not recommended for web.go because it doesn't allow templates to be embedded within each other, which causes a lot of duplicated text.
81
85
86
+
## Static Files
87
+
88
+
Web.go has the ability to serve static files in a very efficient way. If you place files in the `static` directory of your web application, web.go will serve them if a request matches the name of the file.
89
+
90
+
For example, if you have a web app in `$HOME/app` being served from `myapp.com`, and there's a file `$HOME/app/static/image.jpg`, requesting `myapp.com/image.jpg` will serve the static file. A common practice is to have `static/images`, `static/stylesheets`, and `static/javascripts` that contain static files.
91
+
92
+
You can also change web.ServerConfig.StaticDir to specify a directory.
93
+
82
94
## Shared hosts
83
95
84
96
Web.go provides methods to run web applications using the SCGI or FastCGI protocols. This
@@ -100,3 +112,15 @@ func main() {
100
112
{% endhighlight %}
101
113
102
114
Next you need to configure your web server to pass requests along to port 6580.
115
+
116
+
## Developing web.go
117
+
118
+
If you have an issue you'd like to debug in web.go, you'll want to modify the source code of the project.
119
+
120
+
By default, when you run `go get package`, the installer will fetch the source code and install the package in the directory specified by `$GOPATH`. If `$GOPATH` is not set, the library is installed in the `$GOROOT/pkg` folder, which defaults to where Go is built. As a developer of Go libraries, it is much more convenient to set a `$GOPATH` variable to a location like `$HOME/golibs` or `$HOME/projects/golibs`. See [how to write Go code](http://golang.org/doc/code.html) for more details. The first step to developing web.go is to ensure that you have an appropriate `$GOPATH` with two sub-directories: `src` and `pkg`.
121
+
122
+
Next, you should run `cd $GOPATH/src && git clone github.com/hoisie/web`. This creates a clone of the web.go repo in `$GOPATH/src/web`. Next, run `cd GOPATH/src/web && go install`. This will install the `web` package into `$GOPATH/pkg`.
123
+
124
+
From now on, if you include web.go, you should use `import web`, and this will link to the files that are in `$GOPATH/pkg`. You can now modify the web.go source code in `$GOPATH/src/web`, rebuild with `go install`, and then rebuild your target appication.
0 commit comments