-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
68 lines (51 loc) · 2.6 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 (
//"fmt"
"log"
// swagger stuff
"github.com/go-openapi/loads"
"librarian/swagger/restapi"
"librarian/swagger/restapi/operations"
"librarian/library"
"librarian/handlers"
)
func main() {
mongoDb := &library.MongoDB{
Timeout: 3,
URI: "mongodb://root:example@localhost:27017",
Database: "library",
}
// do the server stuff
var swaggerSpec *loads.Document
var err error
if swaggerSpec, err = loads.Analyzed(restapi.SwaggerJSON, ""); err != nil {
log.Fatalln(err)
}
// create a new API which can be used to create a server
api := operations.NewLibraryAPI(swaggerSpec)
server := restapi.NewServer(api)
defer server.Shutdown()
server.Port = 8080
bookHandler := handlers.BookHandler{Persister: mongoDb}
// /book handlers
//api.PostBookHandler = operations.PostBookHandlerFunc(bookHandler.HandlePostBook)
//api.GetBookHandler = operations.GetBookHandlerFunc(bookHandler.HandleGetBook)
//api.GetBookTitleHandler = operations.GetBookTitleHandlerFunc(bookHandler.HandleGetBookTitle)
//api.PutBookTitleHandler = operations.PutBookTitleHandlerFunc(bookHandler.HandlePutBookTitle)
api.DeleteBookTitleHandler = operations.DeleteBookTitleHandlerFunc(bookHandler.HandleDeleteBookTitle) // keep for acceptance tests
// /librarian/{username}/book handlers
seniorLibrarianHandler := handlers.SeniorLibrarianHandler{Persister: mongoDb}
librarianHandler := handlers.LibrarianHandler{Persister: mongoDb}
api.PostLibrarianUsernameBookHandler = operations.PostLibrarianUsernameBookHandlerFunc(seniorLibrarianHandler.HandlePostBook)
api.DeleteLibrarianUsernameBookTitleAuthorCopiesHandler = operations.DeleteLibrarianUsernameBookTitleAuthorCopiesHandlerFunc(seniorLibrarianHandler.HandleDeleteBook)
api.GetLibrarianUsernameBookTitleAuthorHandler = operations.GetLibrarianUsernameBookTitleAuthorHandlerFunc(librarianHandler.HandleGetBook)
// /librarian/{username}/user handlers
api.PostLibrarianUsernameUserHandler = operations.PostLibrarianUsernameUserHandlerFunc(librarianHandler.HandlePostUser)
api.DeleteLibrarianUsernameUserUserHandler = operations.DeleteLibrarianUsernameUserUserHandlerFunc(librarianHandler.HandleDeleteUser)
api.GetLibrarianUsernameUserUserHandler = operations.GetLibrarianUsernameUserUserHandlerFunc(librarianHandler.HandleGetUser)
api.PutLibrarianUsernameUserUserCheckoutHandler = operations.PutLibrarianUsernameUserUserCheckoutHandlerFunc(librarianHandler.HandlePutCheckOut)
api.PutLibrarianUsernameUserUserCheckinHandler = operations.PutLibrarianUsernameUserUserCheckinHandlerFunc(librarianHandler.HandlePutCheckIn)
if err = server.Serve(); err != nil {
log.Fatalln(err)
}
}