From 25bbfaa9dc7a56e7df27bfe8e42a772286ffff74 Mon Sep 17 00:00:00 2001 From: Emile Date: Thu, 30 Apr 2020 20:05:27 +0200 Subject: super simple minimal setup --- Dockerfile | 17 +++++++++++++++++ README.md | 25 ++++++++++++++++++++++++- faila2 | Bin 0 -> 8091659 bytes go.mod | 8 ++++++++ go.sum | 10 ++++++++++ main.go | 28 ++++++++++++++++++++++++++++ 6 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 Dockerfile create mode 100755 faila2 create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a66e4fc --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM golang:1.14 as build-env + +WORKDIR /go/src/app +ADD . /go/src/app + +ENV PATH="$GOPATH/bin:$PATH" +ENV GOBIN="$GOPATH/bin" +RUN go env + + +RUN go get -d -v ./... +RUN go build -o /go/bin/faila2 ./... + +FROM gcr.io/distroless/base +COPY --from=build-env /go/bin/faila2 / + +ENTRYPOINT ["/faila2"] \ No newline at end of file diff --git a/README.md b/README.md index 4ef9637..4706872 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,26 @@ # faila2 -faila, but simpler. Throw this binary in a folder and it'll be hosted \ No newline at end of file +faila, but simpler. Throw this binary in a folder and it'll be hosted + +## Flags + +```bash +$ ./faila2 -h +Usage of faila2: + -dir string + path to host (default "./") + -ip string + ip to listen on (default "0.0.0.0") + -p string + port to listen on (default "8087") +``` + +## Redirects + +If you want to redirect to another page, create an `index.html` in the folder that should redirect with the following content: + +```html + +``` + +replacing `/testb` with the place where you'd like to be redirected to diff --git a/faila2 b/faila2 new file mode 100755 index 0000000..8d801cf Binary files /dev/null and b/faila2 differ diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..92f9e1f --- /dev/null +++ b/go.mod @@ -0,0 +1,8 @@ +module git.darknebu.la/emile/faila2 + +go 1.13 + +require ( + github.com/gorilla/mux v1.7.4 + github.com/sirupsen/logrus v1.5.0 +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..7ea0499 --- /dev/null +++ b/go.sum @@ -0,0 +1,10 @@ +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/gorilla/mux v1.7.4 h1:VuZ8uybHlWmqV03+zRzdwKL4tUnIp1MAQtp1mIFE1bc= +github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/sirupsen/logrus v1.5.0 h1:1N5EYkVAPEywqZRJd7cwnRtCb6xJx7NH3T3WUTF980Q= +github.com/sirupsen/logrus v1.5.0/go.mod h1:+F7Ogzej0PZc/94MaYx/nvG9jOFMD2osvC3s+Squfpo= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc= +golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/main.go b/main.go new file mode 100644 index 0000000..de5d97f --- /dev/null +++ b/main.go @@ -0,0 +1,28 @@ +package main + +import ( + "flag" + "fmt" + "log" + "net/http" + + "github.com/gorilla/mux" +) + +func main() { + + // define the flags + ip := flag.String("ip", "0.0.0.0", "ip to listen on") + port := flag.String("p", "8087", "port to listen on") + dir := flag.String("dir", "./", "path to host") + flag.Parse() + + // define the http server + r := mux.NewRouter() + r.Handle("/", http.FileServer(http.Dir(*dir))) + httpServer := http.Server{ + Addr: fmt.Sprintf("%s:%s", *ip, *port), + Handler: r, + } + log.Fatal(httpServer.ListenAndServe()) +} -- cgit 1.4.1