Use env for config instead of flags
parent
84d9ed7c06
commit
413015945a
|
@ -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/heartbeat /heartbeat
|
COPY --from=build /src/heartbeat /heartbeat
|
||||||
|
COPY --from=build /src/.env /.env
|
||||||
|
|
||||||
ENTRYPOINT ["/heartbeat"]
|
ENTRYPOINT ["/heartbeat"]
|
||||||
|
|
10
README.md
10
README.md
|
@ -2,14 +2,14 @@
|
||||||
|
|
||||||
Beep backend records and makes available the last seen times of users.
|
Beep backend records and makes available the last seen times of users.
|
||||||
|
|
||||||
## Flags
|
## Environment variables
|
||||||
|
|
||||||
Flags are supplied to the compiled go program in the form ```-flag=stuff```.
|
Supply environment variables by either exporting them or editing ```.env```.
|
||||||
|
|
||||||
| Flag | Description | Default |
|
| ENV | Description | Default |
|
||||||
| ---- | ----------- | ------- |
|
| ---- | ----------- | ------- |
|
||||||
| listen | Port number to listen on | 8080 |
|
| LISTEN | Host and port number to listen on | :8080 |
|
||||||
| redis | Host and port of redis | :6379 |
|
| REDIS | Host and port of redis | :6379 |
|
||||||
|
|
||||||
## API
|
## API
|
||||||
|
|
||||||
|
|
1
go.mod
1
go.mod
|
@ -2,6 +2,7 @@ module heartbeat
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/go-redis/redis v6.15.1+incompatible
|
github.com/go-redis/redis v6.15.1+incompatible
|
||||||
|
github.com/joho/godotenv v1.3.0
|
||||||
github.com/julienschmidt/httprouter v1.2.0
|
github.com/julienschmidt/httprouter v1.2.0
|
||||||
github.com/onsi/ginkgo v1.7.0 // indirect
|
github.com/onsi/ginkgo v1.7.0 // indirect
|
||||||
github.com/onsi/gomega v1.4.3 // indirect
|
github.com/onsi/gomega v1.4.3 // indirect
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -6,6 +6,8 @@ github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM
|
||||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||||
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
|
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
|
||||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||||
|
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=
|
||||||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||||
|
|
14
main.go
14
main.go
|
@ -1,13 +1,14 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/joho/godotenv"
|
||||||
"github.com/julienschmidt/httprouter"
|
"github.com/julienschmidt/httprouter"
|
||||||
"github.com/go-redis/redis"
|
"github.com/go-redis/redis"
|
||||||
)
|
)
|
||||||
|
@ -24,10 +25,13 @@ var connections map[RawClient][]chan []byte
|
||||||
var redisClient *redis.Client
|
var redisClient *redis.Client
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// Parse flags
|
// Load .env
|
||||||
flag.StringVar(&listen, "listen", ":8080", "host and port to listen on")
|
err := godotenv.Load()
|
||||||
flag.StringVar(&redisHost, "redis", ":6379", "host and port of redis")
|
if err != nil {
|
||||||
flag.Parse()
|
log.Fatal("Error loading .env file")
|
||||||
|
}
|
||||||
|
listen = os.Getenv("LISTEN")
|
||||||
|
redisHost = os.Getenv("REDIS")
|
||||||
|
|
||||||
connections = make(map[RawClient][]chan []byte)
|
connections = make(map[RawClient][]chan []byte)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue