mirror of
https://github.com/valyala/fasthttp.git
synced 2026-06-14 15:56:44 +03:00
Issue #10: Added initial examples
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
# Code examples
|
||||
|
||||
* [Static file server](fileserver)
|
||||
@@ -0,0 +1,5 @@
|
||||
fileserver: clean
|
||||
go build -o fileserver
|
||||
|
||||
clean:
|
||||
rm -f fileserver
|
||||
@@ -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
|
||||
```
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user