-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
65 lines (53 loc) · 1.45 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"database/sql"
"fmt"
"log"
"net/http"
"os"
"github.com/keighl/postmark"
_ "github.com/lib/pq"
)
var adminToken string
var paddleToken string
var db *sql.DB
var postmarkClient *postmark.Client
func index(w http.ResponseWriter, r *http.Request) {
sendErrorMessage(w, http.StatusNotFound, "Nothing to see here, move along.")
}
func main() {
var err error
port := os.Getenv("PORT")
if port == "" {
port = "3000"
}
adminToken = os.Getenv("ADMIN_TOKEN")
if adminToken == "" {
log.Fatal("Missing required ADMIN_TOKEN.")
}
paddleToken = os.Getenv("PADDLE_TOKEN")
if paddleToken == "" {
log.Fatal("Missing required PADDLE_TOKEN.")
}
connStr := os.Getenv("DATABASE_URL")
if connStr == "" {
log.Fatal("Missing required DATABASE_URL.")
}
db, err = sql.Open("postgres", connStr)
if err != nil {
log.Fatal(err)
}
db.SetMaxOpenConns(4)
postmarkEmailAPIKey := os.Getenv("POSTMARK_API_KEY")
if postmarkEmailAPIKey == "" {
log.Fatal("Missing required POSTMARK_API_KEY.")
}
postmarkClient = postmark.NewClient(postmarkEmailAPIKey, "")
http.HandleFunc("/licensing/admin/import/", importLicenses)
http.HandleFunc("/licensing/admin/stats/", showLicensingStats)
http.HandleFunc("/licensing/callback/paddle", claimLicenseForPaddle)
http.HandleFunc("/licensing/callback/paddle/", claimLicenseForPaddle)
http.HandleFunc("/", index)
log.Printf("Listening on port %s.", port)
http.ListenAndServe(fmt.Sprintf(":%s", port), nil)
}