mirror of https://github.com/statping/statping
travis - notifier api
parent
d279d1c449
commit
13816b2b4b
|
@ -64,7 +64,7 @@ before_install:
|
||||||
|
|
||||||
install:
|
install:
|
||||||
- make dev-deps
|
- make dev-deps
|
||||||
- make dev
|
- make dep
|
||||||
- make install
|
- make install
|
||||||
|
|
||||||
before_script:
|
before_script:
|
||||||
|
|
|
@ -17,8 +17,10 @@ package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/hunterlong/statup/core"
|
"github.com/hunterlong/statup/core"
|
||||||
|
"github.com/hunterlong/statup/core/notifier"
|
||||||
"github.com/hunterlong/statup/types"
|
"github.com/hunterlong/statup/types"
|
||||||
"github.com/hunterlong/statup/utils"
|
"github.com/hunterlong/statup/utils"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -327,6 +329,21 @@ func apiCreateUsersHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
json.NewEncoder(w).Encode(output)
|
json.NewEncoder(w).Encode(output)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func apiNotifierGetHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if !isAPIAuthorized(r) {
|
||||||
|
http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
vars := mux.Vars(r)
|
||||||
|
notify, notifierObj, err := notifier.SelectNotifier(vars["notifier"])
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, fmt.Sprintf("%v notifier was not found", vars["notifier"]), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Println(notify)
|
||||||
|
fmt.Println(notifierObj)
|
||||||
|
}
|
||||||
|
|
||||||
func isAPIAuthorized(r *http.Request) bool {
|
func isAPIAuthorized(r *http.Request) bool {
|
||||||
if os.Getenv("GO_ENV") == "test" {
|
if os.Getenv("GO_ENV") == "test" {
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -110,8 +110,8 @@ func Router() *mux.Router {
|
||||||
r.Handle("/api/users/{id}", http.HandlerFunc(apiUserDeleteHandler)).Methods("DELETE")
|
r.Handle("/api/users/{id}", http.HandlerFunc(apiUserDeleteHandler)).Methods("DELETE")
|
||||||
|
|
||||||
// API Notifier Routes
|
// API Notifier Routes
|
||||||
r.Handle("/api/notifier/{notifier}", http.HandlerFunc(apiCheckinHandler)).Methods("GET")
|
r.Handle("/api/notifier/{notifier}", http.HandlerFunc(apiNotifierGetHandler)).Methods("GET")
|
||||||
r.Handle("/api/notifier/{notifier}", http.HandlerFunc(apiCheckinHandler)).Methods("POST")
|
r.Handle("/api/notifier/{notifier}", http.HandlerFunc(apiNotifierGetHandler)).Methods("POST")
|
||||||
|
|
||||||
// Generic API Routes
|
// Generic API Routes
|
||||||
r.Handle("/api", http.HandlerFunc(apiIndexHandler))
|
r.Handle("/api", http.HandlerFunc(apiIndexHandler))
|
||||||
|
|
Loading…
Reference in New Issue