-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
52 lines (43 loc) · 1.2 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
package main
import (
"fmt"
"log"
"net/http"
"os"
"github.com/gorilla/mux"
)
func main() {
//we want to import mux
r := mux.NewRouter()
//decalre out port
port := getPort()
//we want to call the function to set all these the things we are setting --get started button payload, etc
setGetStartedPayload("GET_STARTED")
//declare the VERB OUR route takes
r.HandleFunc("/", indexHandler).Methods("GET")
r.HandleFunc("/webhook", webhookGetHandler).Methods("GET")
r.HandleFunc("/webhook", webhookPostHandler).Methods("POST")
fmt.Printf("Server up and running. Running on PORT: %s\n", port)
//pass to our good ol http
err := http.ListenAndServe(port, r)
//if there is an error starting our server
if err != nil {
log.Fatal("Error listening and server:", err)
}
}
func indexHandler(w http.ResponseWriter, r *http.Request) {
fmt.Println(r)
fmt.Fprint(w, "Got my server up and running in Go. Yay!!")
}
//a function to get our port incase we deploy to heroku
func getPort() string {
port := os.Getenv("PORT")
if port == "" {
/**
*TODO: get the port declared in the yml config.
*/
port = ":3500"
fmt.Printf("PORT NOT DEFINED. USING THE PORT %s as the running port\n", port)
}
return port
}