-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
42 lines (34 loc) · 992 Bytes
/
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
package main
import (
"log"
"net/http"
"os"
"github.com/gorilla/mux"
)
// URL contains the Slack API url for sending invitations
const (
URL = "https://golangbg.slack.com/api/users.admin.invite"
)
// Token is a global variable containing the Slack API token
var token string
func main() {
// Get the Slack token, end execution if there isn't one
token = os.Getenv("SI_TOKEN")
if token == "" {
log.Fatal("SI_TOKEN is empty")
}
// Get the Port.
// The code is optimized for deployment on Heroku, therefore the env name needs to be PORT
port := os.Getenv("PORT")
if port == "" {
port = "80"
}
// Setup a router
r := mux.NewRouter()
r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("./static"))))
r.HandleFunc("/slack", SlackGetHandler).Methods(http.MethodGet)
r.HandleFunc("/slack", SlackPostHandler).Methods(http.MethodPost)
r.HandleFunc("/", HomeHandler)
// Start the server
log.Fatal(http.ListenAndServe(":"+port, r))
}