Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standard library routing #151

Merged
merged 19 commits into from
Oct 21, 2024
Merged

Standard library routing #151

merged 19 commits into from
Oct 21, 2024

Conversation

CtrlSpice
Copy link
Owner

@CtrlSpice CtrlSpice commented Oct 11, 2024

  • Changed server.go to use standard routing instead of gorilla/mux (thank you for your service)
  • Wrote tests for the handlers and routing
  • Fixed small bugs in store.go and queries.go
  • Reintroduced CI testing, and the README because I was in there
  • Made the AI copilot generate capybaras doing human things for my amusement again

A vibrant digital illustration featuring a capybara wearing a blue kigurumi resembling a gopher. The capybara looks delightful as it waves goodbye. Its friend, a gorilla, is reciprocating with a warm expression, making the scene absolutely charming.

@CtrlSpice CtrlSpice requested a review from jmorrell October 11, 2024 20:03
@CtrlSpice CtrlSpice marked this pull request as ready for review October 17, 2024 20:50
Copy link
Collaborator

@jmorrell jmorrell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some suggestions for refinements in this or further PRs, but nothing that should block this from merging

.github/workflow/go.yml Outdated Show resolved Hide resolved
}

serveFromFS, err := strconv.ParseBool(os.Getenv("SERVE_FROM_FS"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider lifting this parsing of the env vars out of the server and have it get passed in as an option in NewServer

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll do this neatly in its own PR so I don't have to look for it later


//TODO: Add sample logs and metrics
writer.WriteHeader(http.StatusOK)
_, isCI := os.LookupEnv("CI")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto for this env var, maybe an "autoOpenBrowser" option, or have the app code itself open the browser instead of the server

Definitely not necessary to change in this PR though

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto this.

desktopexporter/internal/server/server.go Outdated Show resolved Hide resolved
writer.WriteHeader(http.StatusInternalServerError)
return
log.Fatal(err)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider instrumentation / logging instead of immediately failing. We could create a single function to handle errors that cannot be recovered from so they are consistent.

return s.server.Close()
}

func (s *Server) Handler(serveFromFS bool) http.Handler {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

serveFromFS should probably also be an option passed into NewServer.

Naively, I would expect the routes to be set up as part of NewServer not require a further call

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure where else to handle this one, since serveFromFS is only used during development. I'll figure it out in the same PR as the others though.

desktopexporter/internal/server/server_test.go Outdated Show resolved Hide resolved
desktopexporter/internal/server/server_test.go Outdated Show resolved Hide resolved
desktopexporter/internal/server/server_test.go Outdated Show resolved Hide resolved
desktopexporter/internal/server/server.go Show resolved Hide resolved
@CtrlSpice CtrlSpice merged commit 15bfe67 into main Oct 21, 2024
2 checks passed
@CtrlSpice CtrlSpice deleted the standard-library-routing branch October 21, 2024 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants