Skip to content
This repository has been archived by the owner on Jul 20, 2024. It is now read-only.

Commit

Permalink
Use PORT environment variable (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
int128 committed Aug 16, 2019
1 parent 6892276 commit 738013c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.11.1-alpine AS builder
FROM golang:1.12-alpine AS builder
RUN apk update && apk add --no-cache git gcc musl-dev
WORKDIR /build
COPY . .
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ Download the latest release and run the command:
./jira-to-slack
```

It binds port 3000 by default.
You can set the port by `PORT` environment variable.

```sh
PORT=8080 ./jira-to-slack
```

### Docker

Run the Docker image as follows:
Expand Down
10 changes: 9 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (

var version string

const defaultPort = "3000"

func router() http.Handler {
r := mux.NewRouter()
r.Handle("/", &handlers.Index{}).Methods("GET")
Expand All @@ -25,7 +27,13 @@ func router() http.Handler {

func main() {
log.Printf("jira-to-slack %s", version)
addr := ":3000"

port := os.Getenv("PORT")
if port == "" {
port = defaultPort
}
addr := ":" + port

log.Printf("Listening on %s", addr)
if err := http.ListenAndServe(addr, router()); err != nil {
log.Fatalf("Error while listening on %s: %s", addr, err)
Expand Down

0 comments on commit 738013c

Please sign in to comment.