Issue #10: Added initial examples

This commit is contained in:
Aliaksandr Valialkin
2015-12-04 15:09:12 +02:00
parent 5099573946
commit e80eda19e9
5 changed files with 49 additions and 1 deletions
+3
View File
@@ -0,0 +1,3 @@
# Code examples
* [Static file server](fileserver)
+5
View File
@@ -0,0 +1,5 @@
fileserver: clean
go build -o fileserver
clean:
rm -f fileserver
+15
View File
@@ -0,0 +1,15 @@
# Static file server example
Serves files from the given directory.
# How to build
```
make
```
# How to run
```
./fileserver -addr=tcp.addr.to.listen:to -dir=/path/to/directory/to/serve
```
+23
View File
@@ -0,0 +1,23 @@
// Example static file server. Serves static files from the given directory.
package main
import (
"flag"
"log"
"github.com/valyala/fasthttp"
)
var (
addr = flag.String("addr", ":8080", "TCP address to listen to")
dir = flag.String("dir", "/usr/share/nginx/html", "Directory to serve static files from")
)
func main() {
flag.Parse()
h := fasthttp.FSHandler(*dir, 0)
if err := fasthttp.ListenAndServe(*addr, h); err != nil {
log.Fatalf("error in ListenAndServe: %s", err)
}
}