forked from elastic/apm-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustomrouter.go
70 lines (57 loc) · 1.75 KB
/
customrouter.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
package customserver
import (
"net/http"
"github.com/gorilla/mux"
)
type CustomRouter struct {
}
// Custom routes registeration
func NewCustomRouter(router *mux.Router) *mux.Router {
customRouter := CustomRouter{}
router.HandleFunc("/", customRouter.createUserHandler).Methods("GET")
router.HandleFunc("/jobs", customRouter.createKafkaPostHandler).Methods("POST")
router.HandleFunc("/post-to-elastic", customRouter.createElasticPostHandler).Methods("POST")
return router
}
func (cr *CustomRouter) createKafkaPostHandler(w http.ResponseWriter, r *http.Request) {
jobsPostHandler(w, r)
}
func (cr *CustomRouter) createElasticPostHandler(w http.ResponseWriter, r *http.Request) {
InsertDataIntoElastic(w, r)
}
func (ur *CustomRouter) createUserHandler(w http.ResponseWriter, r *http.Request) {
// user, err := decodeUser(r)
// if err != nil {
// Error(w, http.StatusBadRequest, "Invalid request payload")
// return
// }
// err = ur.userService.Create(&user)
// if err != nil {
// Error(w, http.StatusInternalServerError, err.Error())
// return
// }
details := make(map[string]string)
details["elastic_service_status"] = "OK"
Json(w, http.StatusOK, details)
}
// func
// func (ur *userRouter) getUserHandler(w http.ResponseWriter, r *http.Request) {
// vars := mux.Vars(r)
// log.Println(vars)
// username := vars["username"]
// user, err := ur.userService.GetByUsername(username)
// if err != nil {
// Error(w, http.StatusNotFound, err.Error())
// return
// }
// Json(w, http.StatusOK, user)
// }
// func decodeUser(ur *http.Request) (root.User, error) {
// var u root.User
// if r.Body == nil {
// return u, errors.New("no request body")
// }
// decoder := json.NewDecoder(r.Body)
// err := decoder.Decode(&u)
// return u, err
// }