Use env for config instead of flags
parent
8bcce30578
commit
0cd88a4392
|
@ -0,0 +1,3 @@
|
|||
LISTEN=:8080
|
||||
NATS=nats://localhost:4222
|
||||
API_KEY=AIzaSyDxSXDefzw9gXCQaVzOCYlRn_vcC9Da9Q0
|
|
@ -3,12 +3,13 @@ FROM golang:1.11-rc-alpine as build
|
|||
RUN apk add --no-cache git=2.18.1-r0
|
||||
|
||||
WORKDIR /src
|
||||
COPY go.mod go.sum *.go ./
|
||||
COPY go.mod go.sum .env *.go ./
|
||||
RUN go get -d -v ./...
|
||||
RUN CGO_ENABLED=0 go build -ldflags "-s -w"
|
||||
|
||||
FROM scratch
|
||||
|
||||
COPY --from=build /src/transcription /transcription
|
||||
COPY --from=build /src/.env /.env
|
||||
|
||||
ENTRYPOINT ["/transcription"]
|
||||
|
|
12
README.md
12
README.md
|
@ -8,15 +8,15 @@ Beep backend handling transcription of bites to text via Google Cloud.
|
|||
go build && ./backend-transcription
|
||||
```
|
||||
|
||||
## 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 |
|
||||
| nats | URL of NATS | nats://localhost:4222 |
|
||||
| api-key | Google Cloud API key | Something that works. Probably |
|
||||
| LISTEN | Host and port number to listen on | :8080 |
|
||||
| NATS | Host and port of nats | nats://localhost:4222 |
|
||||
| API_KEY | Google Cloud API key | Something that works. Probably |
|
||||
|
||||
## API
|
||||
|
||||
|
|
1
go.mod
1
go.mod
|
@ -2,6 +2,7 @@ module transcription
|
|||
|
||||
require (
|
||||
github.com/golang/protobuf v1.2.1-0.20190205222052-c823c79ea157
|
||||
github.com/joho/godotenv v1.3.0
|
||||
github.com/julienschmidt/httprouter v1.2.0
|
||||
github.com/nats-io/gnatsd v1.4.1 // indirect
|
||||
github.com/nats-io/go-nats v1.7.0
|
||||
|
|
9
go.sum
9
go.sum
|
@ -1,5 +1,7 @@
|
|||
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.1-0.20190205222052-c823c79ea157 h1:SdQMHsZ18/XZCHuwt3IF+dvHgYTO2XMWZjv3XBKQqAI=
|
||||
github.com/golang/protobuf v1.2.1-0.20190205222052-c823c79ea157/go.mod h1:Qd/q+1AKNOZr9uGQzbzCmRO6sUih6GTPZv6a1/R87v0=
|
||||
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/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
|
||||
github.com/nats-io/gnatsd v1.4.1 h1:RconcfDeWpKCD6QIIwiVFcvForlXpWeJP7i5/lDLy44=
|
||||
|
@ -12,7 +14,10 @@ github.com/nats-io/nuid v1.0.0 h1:44QGdhbiANq8ZCbUkdn6W5bqtg+mHuDE4wOUuxxndFs=
|
|||
github.com/nats-io/nuid v1.0.0/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
|
||||
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9 h1:mKdxBk7AujPs8kU4m80U72y/zjbZ3UcXC7dClwKbUI0=
|
||||
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 h1:YUO/7uOKsKeq9UokNS62b8FYywz3ker1l1vDZRCRefw=
|
||||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
google.golang.org/genproto v0.0.0-20180831171423-11092d34479b/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
|
|
16
main.go
16
main.go
|
@ -4,13 +4,14 @@ import (
|
|||
"bytes"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/julienschmidt/httprouter"
|
||||
"github.com/nats-io/go-nats"
|
||||
|
@ -49,11 +50,14 @@ type AudioResults struct {
|
|||
}
|
||||
|
||||
func main() {
|
||||
// Parse flags
|
||||
flag.StringVar(&listen, "listen", ":8080", "host and port to listen on")
|
||||
flag.StringVar(&apiKey, "api-key", "AIzaSyDxSXDefzw9gXCQaVzOCYlRn_vcC9Da9Q0", "Google Cloud API key")
|
||||
flag.StringVar(&natsHost, "nats", "nats://localhost:4222", "host and port of NATS")
|
||||
flag.Parse()
|
||||
// Load .env
|
||||
err := godotenv.Load()
|
||||
if err != nil {
|
||||
log.Fatal("Error loading .env file")
|
||||
}
|
||||
listen = os.Getenv("LISTEN")
|
||||
natsHost = os.Getenv("NATS")
|
||||
apiKey = os.Getenv("API_KEY")
|
||||
|
||||
//NATS
|
||||
nc, err := nats.Connect(natsHost)
|
||||
|
|
Loading…
Reference in New Issue