forked from elastic/apm-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Manish Atri
committed
Jun 3, 2019
1 parent
3c8df64
commit 93f49e3
Showing
6 changed files
with
123 additions
and
1 deletion.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package custom_server | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/gorilla/mux" | ||
) | ||
|
||
type CustomRouter struct { | ||
} | ||
|
||
func NewUserRouter(router *mux.Router) *mux.Router { | ||
customRouter := CustomRouter{} | ||
|
||
router.HandleFunc("/", customRouter.createUserHandler).Methods("GET") | ||
// router.HandleFunc("/{username}", userRouter.getUserHandler).Methods("GET") | ||
return router | ||
} | ||
|
||
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 | ||
// } | ||
Json(w, http.StatusOK, "") | ||
} | ||
|
||
// 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 | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package custom_server | ||
|
||
import ( | ||
"log" | ||
"net/http" | ||
"os" | ||
|
||
"github.com/gorilla/handlers" | ||
"github.com/gorilla/mux" | ||
) | ||
|
||
type CustomServer struct { | ||
router *mux.Router | ||
} | ||
|
||
func NewServer() *CustomServer { | ||
s := CustomServer{router: mux.NewRouter()} | ||
NewUserRouter(s.newSubrouter("/custom_end_point")) | ||
return &s | ||
} | ||
|
||
func (s *CustomServer) Start() { | ||
log.Println("Listening on port 8080") | ||
if err := http.ListenAndServe(":8080", handlers.LoggingHandler(os.Stdout, s.router)); err != nil { | ||
log.Fatal("http.ListenAndServe: ", err) | ||
} | ||
} | ||
|
||
func (s *CustomServer) newSubrouter(path string) *mux.Router { | ||
return s.router.PathPrefix(path).Subrouter() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package custom_server | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
) | ||
|
||
func Error(w http.ResponseWriter, code int, message string) { | ||
Json(w, code, map[string]string{"error": message}) | ||
} | ||
|
||
func Json(w http.ResponseWriter, code int, payload interface{}) { | ||
response, _ := json.Marshal(payload) | ||
|
||
w.Header().Set("Content-Type", "application/json") | ||
w.WriteHeader(code) | ||
w.Write(response) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ import ( | |
"os" | ||
|
||
"github.com/elastic/apm-server/cmd" | ||
|
||
) | ||
|
||
func main() { | ||
|