FIx shared structs + add better debugging/linting (#379)
* fix: Fixes issues w/ shared pointers to structs (#378) * feat: Adds even better debugging and linting support (#376) This is a #PATCH release.
This commit is contained in:
committed by
GitHub
parent
c3d7f26e3c
commit
5c9b88db4f
@@ -86,7 +86,13 @@ func CreateRouter(gitlabClient *Client, projectInfo *ProjectInfo, s *shutdownSer
|
||||
for _, optFunc := range optFuncs {
|
||||
err := optFunc(&d)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
if os.Getenv("DEBUG") != "" {
|
||||
// TODO: We have some JSON files (emojis.json) we import relative to the binary in production and
|
||||
// expect to break during debugging, do not throw when that occurs.
|
||||
fmt.Fprintf(os.Stdout, "Issue occured setting up router: %s\n", err)
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,28 +105,28 @@ func CreateRouter(gitlabClient *Client, projectInfo *ProjectInfo, s *shutdownSer
|
||||
commentService{d, gitlabClient},
|
||||
withMr(d, gitlabClient),
|
||||
withPayloadValidation(methodToPayload{
|
||||
http.MethodPost: &PostCommentRequest{},
|
||||
http.MethodDelete: &DeleteCommentRequest{},
|
||||
http.MethodPatch: &EditCommentRequest{},
|
||||
http.MethodPost: newPayload[PostCommentRequest],
|
||||
http.MethodDelete: newPayload[DeleteCommentRequest],
|
||||
http.MethodPatch: newPayload[EditCommentRequest],
|
||||
}),
|
||||
withMethodCheck(http.MethodPost, http.MethodDelete, http.MethodPatch),
|
||||
))
|
||||
m.HandleFunc("/mr/merge", middleware(
|
||||
mergeRequestAccepterService{d, gitlabClient},
|
||||
withMr(d, gitlabClient),
|
||||
withPayloadValidation(methodToPayload{http.MethodPost: &AcceptMergeRequestRequest{}}),
|
||||
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[AcceptMergeRequestRequest]}),
|
||||
withMethodCheck(http.MethodPost),
|
||||
))
|
||||
m.HandleFunc("/mr/discussions/list", middleware(
|
||||
discussionsListerService{d, gitlabClient},
|
||||
withMr(d, gitlabClient),
|
||||
withPayloadValidation(methodToPayload{http.MethodPost: &DiscussionsRequest{}}),
|
||||
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[DiscussionsRequest]}),
|
||||
withMethodCheck(http.MethodPost),
|
||||
))
|
||||
m.HandleFunc("/mr/discussions/resolve", middleware(
|
||||
discussionsResolutionService{d, gitlabClient},
|
||||
withMr(d, gitlabClient),
|
||||
withPayloadValidation(methodToPayload{http.MethodPut: &DiscussionResolveRequest{}}),
|
||||
withPayloadValidation(methodToPayload{http.MethodPut: newPayload[DiscussionResolveRequest]}),
|
||||
withMethodCheck(http.MethodPut),
|
||||
))
|
||||
m.HandleFunc("/mr/info", middleware(
|
||||
@@ -131,19 +137,19 @@ func CreateRouter(gitlabClient *Client, projectInfo *ProjectInfo, s *shutdownSer
|
||||
m.HandleFunc("/mr/assignee", middleware(
|
||||
assigneesService{d, gitlabClient},
|
||||
withMr(d, gitlabClient),
|
||||
withPayloadValidation(methodToPayload{http.MethodPut: &AssigneeUpdateRequest{}}),
|
||||
withPayloadValidation(methodToPayload{http.MethodPut: newPayload[AssigneeUpdateRequest]}),
|
||||
withMethodCheck(http.MethodPut),
|
||||
))
|
||||
m.HandleFunc("/mr/summary", middleware(
|
||||
summaryService{d, gitlabClient},
|
||||
withMr(d, gitlabClient),
|
||||
withPayloadValidation(methodToPayload{http.MethodPut: &SummaryUpdateRequest{}}),
|
||||
withPayloadValidation(methodToPayload{http.MethodPut: newPayload[SummaryUpdateRequest]}),
|
||||
withMethodCheck(http.MethodPut),
|
||||
))
|
||||
m.HandleFunc("/mr/reviewer", middleware(
|
||||
reviewerService{d, gitlabClient},
|
||||
withMr(d, gitlabClient),
|
||||
withPayloadValidation(methodToPayload{http.MethodPut: &ReviewerUpdateRequest{}}),
|
||||
withPayloadValidation(methodToPayload{http.MethodPut: newPayload[ReviewerUpdateRequest]}),
|
||||
withMethodCheck(http.MethodPut),
|
||||
))
|
||||
m.HandleFunc("/mr/revisions", middleware(
|
||||
@@ -154,7 +160,7 @@ func CreateRouter(gitlabClient *Client, projectInfo *ProjectInfo, s *shutdownSer
|
||||
m.HandleFunc("/mr/reply", middleware(
|
||||
replyService{d, gitlabClient},
|
||||
withMr(d, gitlabClient),
|
||||
withPayloadValidation(methodToPayload{http.MethodPost: &ReplyRequest{}}),
|
||||
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[ReplyRequest]}),
|
||||
withMethodCheck(http.MethodPost),
|
||||
))
|
||||
m.HandleFunc("/mr/label", middleware(
|
||||
@@ -175,15 +181,15 @@ func CreateRouter(gitlabClient *Client, projectInfo *ProjectInfo, s *shutdownSer
|
||||
draftNoteService{d, gitlabClient},
|
||||
withMr(d, gitlabClient),
|
||||
withPayloadValidation(methodToPayload{
|
||||
http.MethodPost: &PostDraftNoteRequest{},
|
||||
http.MethodPatch: &UpdateDraftNoteRequest{},
|
||||
http.MethodPost: newPayload[PostDraftNoteRequest],
|
||||
http.MethodPatch: newPayload[UpdateDraftNoteRequest],
|
||||
}),
|
||||
withMethodCheck(http.MethodGet, http.MethodPost, http.MethodPatch, http.MethodDelete),
|
||||
))
|
||||
m.HandleFunc("/mr/draft_notes/publish", middleware(
|
||||
draftNotePublisherService{d, gitlabClient},
|
||||
withMr(d, gitlabClient),
|
||||
withPayloadValidation(methodToPayload{http.MethodPost: &DraftNotePublishRequest{}}),
|
||||
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[DraftNotePublishRequest]}),
|
||||
withMethodCheck(http.MethodPost),
|
||||
))
|
||||
m.HandleFunc("/pipeline", middleware(
|
||||
@@ -200,17 +206,17 @@ func CreateRouter(gitlabClient *Client, projectInfo *ProjectInfo, s *shutdownSer
|
||||
))
|
||||
m.HandleFunc("/attachment", middleware(
|
||||
attachmentService{data: d, client: gitlabClient, fileReader: attachmentReader{}},
|
||||
withPayloadValidation(methodToPayload{http.MethodPost: &AttachmentRequest{}}),
|
||||
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[AttachmentRequest]}),
|
||||
withMethodCheck(http.MethodPost),
|
||||
))
|
||||
m.HandleFunc("/create_mr", middleware(
|
||||
mergeRequestCreatorService{d, gitlabClient},
|
||||
withPayloadValidation(methodToPayload{http.MethodPost: &CreateMrRequest{}}),
|
||||
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[CreateMrRequest]}),
|
||||
withMethodCheck(http.MethodPost),
|
||||
))
|
||||
m.HandleFunc("/job", middleware(
|
||||
traceFileService{d, gitlabClient},
|
||||
withPayloadValidation(methodToPayload{http.MethodGet: &JobTraceRequest{}}),
|
||||
withPayloadValidation(methodToPayload{http.MethodGet: newPayload[JobTraceRequest]}),
|
||||
withMethodCheck(http.MethodGet),
|
||||
))
|
||||
m.HandleFunc("/project/members", middleware(
|
||||
@@ -219,17 +225,17 @@ func CreateRouter(gitlabClient *Client, projectInfo *ProjectInfo, s *shutdownSer
|
||||
))
|
||||
m.HandleFunc("/merge_requests", middleware(
|
||||
mergeRequestListerService{d, gitlabClient},
|
||||
withPayloadValidation(methodToPayload{http.MethodPost: &gitlab.ListProjectMergeRequestsOptions{}}), // TODO: How to validate external object
|
||||
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[gitlab.ListProjectMergeRequestsOptions]}), // TODO: How to validate external object
|
||||
withMethodCheck(http.MethodPost),
|
||||
))
|
||||
m.HandleFunc("/merge_requests_by_username", middleware(
|
||||
mergeRequestListerByUsernameService{d, gitlabClient},
|
||||
withPayloadValidation(methodToPayload{http.MethodPost: &MergeRequestByUsernameRequest{}}),
|
||||
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[MergeRequestByUsernameRequest]}),
|
||||
withMethodCheck(http.MethodPost),
|
||||
))
|
||||
m.HandleFunc("/shutdown", middleware(
|
||||
*s,
|
||||
withPayloadValidation(methodToPayload{http.MethodPost: &ShutdownRequest{}}),
|
||||
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[ShutdownRequest]}),
|
||||
withMethodCheck(http.MethodPost),
|
||||
))
|
||||
|
||||
@@ -245,13 +251,13 @@ func CreateRouter(gitlabClient *Client, projectInfo *ProjectInfo, s *shutdownSer
|
||||
func checkServer(port int) error {
|
||||
for i := 0; i < 10; i++ {
|
||||
resp, err := http.Get("http://localhost:" + fmt.Sprintf("%d", port) + "/ping")
|
||||
if resp.StatusCode == 200 && err == nil {
|
||||
if resp != nil && resp.StatusCode == 200 && err == nil {
|
||||
return nil
|
||||
}
|
||||
time.Sleep(100 * time.Microsecond)
|
||||
}
|
||||
|
||||
return errors.New("Could not start server!")
|
||||
return errors.New("could not start server")
|
||||
}
|
||||
|
||||
/* Creates a TCP listener on the port specified by the user or a random port */
|
||||
|
||||
Reference in New Issue
Block a user