From 91ba32dc292027250d5aec52e0d29b499106e563 Mon Sep 17 00:00:00 2001 From: James Mills Date: Fri, 9 Jun 2017 01:15:21 -0700 Subject: [PATCH] Added simple gopherd cmd (server) and Dockerfile (image) --- Dockerfile | 18 ++++++++++++++++++ README.md | 7 ++++++- cmd/gopherd/main.go | 30 ++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 Dockerfile create mode 100644 cmd/gopherd/main.go diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..dbff18e --- /dev/null +++ b/Dockerfile @@ -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/... diff --git a/README.md b/README.md index bc202a7..f509094 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ server handling and examples of each. ## Installation ```#!bash -$ go get github.com/prologic/go-gopher +$ go get github.com/prologic/go-gopher/... ``` ## Usage @@ -18,6 +18,11 @@ $ go get github.com/prologic/go-gopher import "github.com/prologic/go-gopher" ``` +Or run the builtin (*very simple*) server: +```#!bash +$ gopherd +``` + ## Example ### Client diff --git a/cmd/gopherd/main.go b/cmd/gopherd/main.go new file mode 100644 index 0000000..6d6a5ac --- /dev/null +++ b/cmd/gopherd/main.go @@ -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)) +}