Skip to content
This repository was archived by the owner on Oct 16, 2024. It is now read-only.

Commit cec063b

Browse files
committed
fix env var handling
1 parent 9974ad1 commit cec063b

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ Passage provides an SDK to easily authenticate HTTP requests. Example source cod
44

55
### Setup
66

7-
For this example app, we'll need to provide our application with a Passage App ID and API Key. Your App ID and API Key can be found in the [Passage Console](https://console.passage.id) in your App Settings. You'll need to change the following environment variables with your respective credentials (note that the default port for this application is 5000):
7+
For this example app, we'll need to provide our application with a Passage App ID and API Key. Your App ID and API Key can be found in the [Passage Console](https://console.passage.id) in your App Settings. You'll need to set the following environment variables with your respective credentials:
88

9-
```go
10-
os.Setenv("PASSAGE_APP_ID", "[YOUR_APP_ID_HERE]")
11-
os.Setenv("PASSAGE_API_KEY", "[YOUR_PASSAGE_API_KEY_HERE]")
12-
os.Setenv("PORT", "5000")
9+
```bash
10+
PASSAGE_APP_ID=
11+
PASSAGE_API_KEY=
12+
PORT=5000
1313
```
1414

1515
### Run With Go

main.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"fmt"
5+
"log"
56
"net/http"
67
"os"
78
"text/template"
@@ -10,15 +11,16 @@ import (
1011
)
1112

1213
func main() {
13-
os.Setenv("PASSAGE_APP_ID", "[YOUR_APP_ID_HERE]")
14-
os.Setenv("PASSAGE_API_KEY", "[YOUR_PASSAGE_API_KEY_HERE]")
15-
os.Setenv("PORT", "5000")
14+
port := os.Getenv("PORT")
15+
if port == "" {
16+
log.Fatal("PORT environment variable required")
17+
}
1618

1719
http.HandleFunc("/", indexHandler)
1820
http.HandleFunc("/dashboard", dashboardHandler)
1921
http.Handle("/assets/", http.FileServer(http.Dir("./templates")))
2022

21-
http.ListenAndServe(":"+os.Getenv("PORT"), nil)
23+
http.ListenAndServe(":"+port, nil)
2224
}
2325

2426
func indexHandler(w http.ResponseWriter, r *http.Request) {

0 commit comments

Comments
 (0)