Controller crud for Watch type

Controller and client crud, API routes, and a unit test for the Watch
type.
This commit is contained in:
Soam Vasani
2016-12-09 23:42:03 -08:00
parent 3a6d5bb070
commit a69834157f
5 changed files with 341 additions and 5 deletions
+17
View File
@@ -33,6 +33,17 @@ type API struct {
FunctionStore
HTTPTriggerStore
EnvironmentStore
WatchStore
}
func MakeAPI(rs *ResourceStore) *API {
api := &API{
FunctionStore: FunctionStore{ResourceStore: *rs},
HTTPTriggerStore: HTTPTriggerStore{ResourceStore: *rs},
EnvironmentStore: EnvironmentStore{ResourceStore: *rs},
WatchStore: WatchStore{ResourceStore: *rs},
}
return api
}
func (api *API) respondWithSuccess(w http.ResponseWriter, resp []byte) {
@@ -76,6 +87,12 @@ func (api *API) Serve(port int) {
r.HandleFunc("/v1/environments/{environment}", api.EnvironmentApiUpdate).Methods("PUT")
r.HandleFunc("/v1/environments/{environment}", api.EnvironmentApiDelete).Methods("DELETE")
r.HandleFunc("/v1/watches", api.WatchApiList).Methods("GET")
r.HandleFunc("/v1/watches", api.WatchApiCreate).Methods("POST")
r.HandleFunc("/v1/watches/{watch}", api.WatchApiGet).Methods("GET")
r.HandleFunc("/v1/watches/{watch}", api.WatchApiUpdate).Methods("PUT")
r.HandleFunc("/v1/watches/{watch}", api.WatchApiDelete).Methods("DELETE")
address := fmt.Sprintf(":%v", port)
log.WithFields(log.Fields{"port": port}).Info("Server started")