forked from fabric8-services/fabric8-wit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
99 lines (79 loc) · 2.52 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package main
import (
"flag"
"fmt"
"net/http"
"os"
"github.com/jinzhu/gorm"
_ "github.com/lib/pq"
"github.com/almighty/almighty-core/app"
"github.com/almighty/almighty-core/migration"
"github.com/almighty/almighty-core/models"
token "github.com/dgrijalva/jwt-go"
"github.com/goadesign/goa"
"github.com/goadesign/goa/middleware"
"github.com/goadesign/goa/middleware/security/jwt"
)
var (
// Commit current build commit set by build script
Commit = "0"
// BuildTime set by build script
BuildTime = "0"
// Development enables certain dev only features, like auto token generation
Development = false
)
func main() {
var dbHost string
flag.BoolVar(&Development, "dev", false, "Enable development related features, e.g. token generation endpoint")
flag.StringVar(&dbHost, "dbhost", "", "The hostname of the db server")
flag.Parse()
if len(dbHost) == 0 {
dbHost = os.Getenv("DBHOST")
}
if len(dbHost) == 0 {
dbHost = "localhost"
}
db, err := gorm.Open("postgres", fmt.Sprintf("host=%s user=postgres password=mysecretpassword sslmode=disable", dbHost))
if err != nil {
panic("failed to connect database: " + err.Error())
}
defer db.Close()
// Migrate the schema
migration.Perform(db)
// Create service
service := goa.New("alm")
// Mount middleware
service.Use(middleware.RequestID())
service.Use(middleware.LogRequest(true))
service.Use(middleware.ErrorHandler(service, true))
service.Use(middleware.Recover())
publicKey, err := token.ParseRSAPublicKeyFromPEM([]byte(RSAPublicKey))
if err != nil {
panic(err)
}
app.UseJWTMiddleware(service, jwt.New(publicKey, nil, app.NewJWTSecurity()))
// Mount "login" controller
c := NewLoginController(service)
app.MountLoginController(service, c)
// Mount "version" controller
c2 := NewVersionController(service)
app.MountVersionController(service, c2)
// Mount "workitem" controller
ts := models.NewGormTransactionSupport(db)
repo := models.NewWorkItemRepository(ts)
c3 := NewWorkitemController(service, repo, ts)
app.MountWorkitemController(service, c3)
// Mount "workitemtype" controller
c4 := NewWorkitemtypeController(service)
app.MountWorkitemtypeController(service, c4)
fmt.Println("Git Commit SHA: ", Commit)
fmt.Println("UTC Build Time: ", BuildTime)
fmt.Println("Dev mode: ", Development)
http.Handle("/api/", service.Mux)
http.Handle("/", http.FileServer(assetFS()))
http.Handle("/favicon.ico", http.NotFoundHandler())
// Start http
if err := http.ListenAndServe(":8080", nil); err != nil {
service.LogError("startup", "err", err)
}
}