Added simple gopherd cmd (server) and Dockerfile (image)

This commit is contained in:
James Mills 2017-06-09 01:15:21 -07:00
parent 48590e76b1
commit 91ba32dc29
No known key found for this signature in database
GPG Key ID: AC4C014F1440EBD6
3 changed files with 54 additions and 1 deletions

18
Dockerfile Normal file
View File

@ -0,0 +1,18 @@
FROM golang:alpine
EXPOSE 70/tcp
ENTRYPOINT ["gopherd"]
CMD []
RUN \
apk add --update git && \
rm -rf /var/cache/apk/*
RUN mkdir -p /go/src/github.com/prologic/gopherproxy
WORKDIR /go/src/github.com/prologic/go-gopher
COPY . /go/src/github.com/prologic/go-gopher
RUN go get -v -d
RUN go install -v github.com/prologic/go-gopher/...

View File

@ -9,7 +9,7 @@ server handling and examples of each.
## Installation ## Installation
```#!bash ```#!bash
$ go get github.com/prologic/go-gopher $ go get github.com/prologic/go-gopher/...
``` ```
## Usage ## Usage
@ -18,6 +18,11 @@ $ go get github.com/prologic/go-gopher
import "github.com/prologic/go-gopher" import "github.com/prologic/go-gopher"
``` ```
Or run the builtin (*very simple*) server:
```#!bash
$ gopherd
```
## Example ## Example
### Client ### Client

30
cmd/gopherd/main.go Normal file
View File

@ -0,0 +1,30 @@
package main
import (
"flag"
"log"
"os"
"github.com/prologic/go-gopher"
)
func cwd() string {
dir, err := os.Getwd()
if err != nil {
log.Fatal(err)
}
return dir
}
func main() {
var (
bind = flag.String("bind", ":70", "port to listen on")
root = flag.String("root", cwd(), "root directory to serve")
)
flag.Parse()
gopher.Handle("/", gopher.FileServer(gopher.Dir(*root)))
log.Fatal(gopher.ListenAndServe(*bind, nil))
}