diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..43dc3a7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM golang:1.14-buster AS builder + +WORKDIR ${GOPATH}/src/git.bjphoster.com/bryanpedini/go-totp +COPY . . + +RUN go get -d -v +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix gco -ldflags="-w -s" -o /go/bin/go-totp + +FROM scratch +LABEL maintainer="Bryan Joshua Pedini " + +COPY --from=builder /go/bin/go-totp /app/go-totp +COPY ./static /app/static +COPY ./templates /app/templates + +EXPOSE 8080 + +ENTRYPOINT ["/app/go-totp"] diff --git a/go.mod b/go.mod index e6de95f..fd87131 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module git.bjphoster.com/bryanpedini/go-totp go 1.14 + +require github.com/xlzd/gotp v0.0.0-20181030022105-c8557ba2c119 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..84b03bc --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/xlzd/gotp v0.0.0-20181030022105-c8557ba2c119 h1:YyPWX3jLOtYKulBR6AScGIs74lLrJcgeKRwcbAuQOG4= +github.com/xlzd/gotp v0.0.0-20181030022105-c8557ba2c119/go.mod h1:/nuTSlK+okRfR/vnIPqR89fFKonnWPiZymN5ydRJkX8= diff --git a/main.go b/main.go index 32ab54f..fa2ff9d 100644 --- a/main.go +++ b/main.go @@ -1,8 +1,8 @@ package main import ( - "fmt" "encoding/json" + "fmt" "net/http" "strings" "text/template" @@ -11,6 +11,8 @@ import ( "github.com/xlzd/gotp" ) +var addr = "0.0.0.0:8080" + type secret struct { S string `json:"secret"` } @@ -42,6 +44,6 @@ func main() { http.HandleFunc("/", index) http.HandleFunc("/calculate", calculate) http.Handle("/static/", http.StripPrefix(strings.TrimRight("/static/", "/"), staticFolder)) - fmt.Println("Listening on 127.0.0.1:8000") - http.ListenAndServe("127.0.0.1:8000", nil) + fmt.Println("Listening on ", addr) + http.ListenAndServe(addr, nil) }