Use env for config instead of flags
parent
f54300aaea
commit
e82b4b400e
|
@ -3,12 +3,13 @@ FROM golang:1.11-rc-alpine as build
|
||||||
RUN apk add --no-cache git=2.18.1-r0
|
RUN apk add --no-cache git=2.18.1-r0
|
||||||
|
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
COPY go.mod go.sum *.go ./
|
COPY go.mod go.sum .env *.go ./
|
||||||
RUN go get -d -v ./...
|
RUN go get -d -v ./...
|
||||||
RUN CGO_ENABLED=0 go build -ldflags "-s -w"
|
RUN CGO_ENABLED=0 go build -ldflags "-s -w"
|
||||||
|
|
||||||
FROM scratch
|
FROM scratch
|
||||||
|
|
||||||
COPY --from=build /src/login /login
|
COPY --from=build /src/login /login
|
||||||
|
COPY --from=build /src/.env /.env
|
||||||
|
|
||||||
ENTRYPOINT ["/login"]
|
ENTRYPOINT ["/login"]
|
||||||
|
|
|
@ -2,6 +2,15 @@
|
||||||
|
|
||||||
Beep backend handling login. For now, just a POST endpoint returning a JWT. In the furture, SMS-based perpetual login.
|
Beep backend handling login. For now, just a POST endpoint returning a JWT. In the furture, SMS-based perpetual login.
|
||||||
|
|
||||||
|
## Environment variables
|
||||||
|
|
||||||
|
Supply environment variables by either exporting them or editing ```.env```.
|
||||||
|
|
||||||
|
| ENV | Description | Default |
|
||||||
|
| ---- | ----------- | ------- |
|
||||||
|
| LISTEN | Host and port number to listen on | :8080 |
|
||||||
|
| SECRET | JWT secret | secret |
|
||||||
|
|
||||||
## API (temporary)
|
## API (temporary)
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
1
go.mod
1
go.mod
|
@ -2,5 +2,6 @@ module login
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible
|
github.com/dgrijalva/jwt-go v3.2.0+incompatible
|
||||||
|
github.com/joho/godotenv v1.3.0
|
||||||
github.com/julienschmidt/httprouter v1.2.0
|
github.com/julienschmidt/httprouter v1.2.0
|
||||||
)
|
)
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -1,4 +1,6 @@
|
||||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
|
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
|
||||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
||||||
|
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
|
||||||
|
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
|
||||||
github.com/julienschmidt/httprouter v1.2.0 h1:TDTW5Yz1mjftljbcKqRcrYhd4XeOoI98t+9HbQbYf7g=
|
github.com/julienschmidt/httprouter v1.2.0 h1:TDTW5Yz1mjftljbcKqRcrYhd4XeOoI98t+9HbQbYf7g=
|
||||||
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
|
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
|
||||||
|
|
15
main.go
15
main.go
|
@ -2,10 +2,11 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"flag"
|
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/joho/godotenv"
|
||||||
"github.com/julienschmidt/httprouter"
|
"github.com/julienschmidt/httprouter"
|
||||||
"github.com/dgrijalva/jwt-go"
|
"github.com/dgrijalva/jwt-go"
|
||||||
)
|
)
|
||||||
|
@ -14,11 +15,13 @@ var listen string
|
||||||
var secret []byte
|
var secret []byte
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var s string
|
// Load .env
|
||||||
// Parse flags
|
err := godotenv.Load()
|
||||||
flag.StringVar(&listen, "listen", ":8080", "host and port to listen on")
|
if err != nil {
|
||||||
flag.StringVar(&s, "secret", "secret", "JWT secret")
|
log.Fatal("Error loading .env file")
|
||||||
flag.Parse()
|
}
|
||||||
|
listen = os.Getenv("LISTEN")
|
||||||
|
s := os.Getenv("SECRET")
|
||||||
|
|
||||||
secret = []byte(s)
|
secret = []byte(s)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue