-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
68 lines (53 loc) · 1.73 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
66
67
68
package main
import (
"log"
"net/http"
"github.com/dcondomitti/fulcrum/middleware"
"github.com/dcondomitti/go-pivotaltracker/v5/pivotal"
"github.com/julienschmidt/httprouter"
)
var config Config
func main() {
log.Print("Starting fulcrum")
config = parseFlags()
if config.PivotalAPIKey == "" {
log.Fatal("Pivotal Tracker API key not present")
}
pivotalClient := pivotal.NewClient(config.PivotalAPIKey)
s := StoryHandler{
client: *pivotalClient,
}
router := httprouter.New()
router.GET("/projects/:project_id/stories/:story_id", s.Show)
router.GET("/n/projects/:project_id/stories/:story_id", s.Show)
router.GET("/stories/:story_id", s.Show)
router.GET("/story/show/:story_id", s.Show)
router.POST("/projects/:project_id/stories/:story_id", s.Show)
router.POST("/n/projects/:project_id/stories/:story_id", s.Show)
router.POST("/stories/:story_id", s.Show)
router.POST("/story/show/:story_id", s.Show)
httpTarget := middleware.Authentication(config.AuthenticationToken, middleware.JsonContentType(router))
if config.UseTLS {
listenTLS(config, httpTarget)
} else {
listen(config, httpTarget)
}
}
func listenTLS(c Config, h http.Handler) {
if c.TLSCertificatePath == "" || c.TLSKeyPath == "" {
log.Fatal("TLS_CERTIFICATE_PATH and TLS_KEY_PATH are required if USE_TLS is enabled")
}
log.Printf("Using certificate %s (%s)", c.TLSCertificatePath, c.TLSKeyPath)
log.Printf("Starting TLS listener on %s", c.ListenString())
err := http.ListenAndServeTLS(c.ListenString(), c.TLSCertificatePath, c.TLSKeyPath, h)
if err != nil {
panic(err)
}
}
func listen(c Config, h http.Handler) {
log.Printf("Starting listener on %s", c.ListenString())
err := http.ListenAndServe(c.ListenString(), h)
if err != nil {
panic(err)
}
}