-
-
Notifications
You must be signed in to change notification settings - Fork 0
Add fixtures #35
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
Merged
Merged
Add fixtures #35
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
7290809
add fixtures
gocanto 5877048
start working on endpoints
gocanto b2e965d
format
gocanto 50d8e54
token + chain middleware
gocanto b7948c8
format
gocanto 6426287
stract http pkg
gocanto 74124a8
format
gocanto 35a6148
remove username
gocanto 44012ed
format
gocanto 34fdbc3
naming
gocanto e7e96d6
start working on router
gocanto 4686457
remove const
gocanto e0cc3ce
extract app
gocanto ebfea3a
helpers
gocanto 3145f5d
add rources
gocanto baf3d5d
format
gocanto f335c1f
duplicated uuid
gocanto 0a101e9
Fix semantic inconsistency between status code and error message.
gocanto 301d0eb
Fix logging level for error messages.
gocanto ca745f1
Fix slog.Error formatting issue.
gocanto ff8f251
Fix typo in import alias.
gocanto e043fda
Add nil checks for safe resource cleanup
gocanto 093c810
format
gocanto d36cb4b
Add nil check before dereferencing router.
gocanto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,45 @@ | ||
| package boost | ||
|
|
||
| import ( | ||
| "github.com/oullin/database" | ||
| "github.com/oullin/env" | ||
| baseHttp "net/http" | ||
| ) | ||
|
|
||
| func (a *App) SetRouter(router Router) { | ||
| a.router = &router | ||
| } | ||
|
|
||
| func (a *App) CloseLogs() { | ||
| if a.logs == nil { | ||
| return | ||
| } | ||
|
|
||
| driver := *a.logs | ||
| driver.Close() | ||
| } | ||
|
|
||
| func (a *App) CloseDB() { | ||
| if a.db == nil { | ||
| return | ||
| } | ||
|
|
||
| driver := *a.db | ||
| driver.Close() | ||
| } | ||
|
|
||
| func (a *App) GetEnv() *env.Environment { | ||
| return a.env | ||
| } | ||
|
|
||
| func (a *App) GetDB() *database.Connection { | ||
| return a.db | ||
| } | ||
|
|
||
| func (a *App) GetMux() *baseHttp.ServeMux { | ||
| if a.router == nil { | ||
| return nil | ||
| } | ||
|
|
||
| return a.router.Mux | ||
| } |
This file contains hidden or 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 hidden or 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,79 @@ | ||
| package boost | ||
|
|
||
| import ( | ||
| "github.com/oullin/env" | ||
| "github.com/oullin/handler" | ||
| "github.com/oullin/pkg/http" | ||
| "github.com/oullin/pkg/http/middleware" | ||
| baseHttp "net/http" | ||
| ) | ||
|
|
||
| type Router struct { | ||
| Env *env.Environment | ||
| Mux *baseHttp.ServeMux | ||
| Pipeline middleware.Pipeline | ||
| } | ||
|
|
||
| func (r *Router) PipelineFor(apiHandler http.ApiHandler) baseHttp.HandlerFunc { | ||
| tokenMiddleware := middleware.MakeTokenMiddleware( | ||
| r.Env.App.Credentials, | ||
| ) | ||
|
|
||
| return http.MakeApiHandler( | ||
| r.Pipeline.Chain( | ||
| apiHandler, | ||
| middleware.UsernameCheck, | ||
| tokenMiddleware.Handle, | ||
| ), | ||
| ) | ||
| } | ||
|
|
||
| func (r *Router) Profile() { | ||
| abstract := handler.MakeProfileHandler() | ||
|
|
||
| resolver := r.PipelineFor( | ||
| abstract.Handle, | ||
| ) | ||
|
|
||
| r.Mux.HandleFunc("GET /profile", resolver) | ||
| } | ||
|
|
||
| func (r *Router) Experience() { | ||
| abstract := handler.MakeExperienceHandler() | ||
|
|
||
| resolver := r.PipelineFor( | ||
| abstract.Handle, | ||
| ) | ||
|
|
||
| r.Mux.HandleFunc("GET /experience", resolver) | ||
| } | ||
|
|
||
| func (r *Router) Projects() { | ||
| abstract := handler.MakeProjectsHandler() | ||
|
|
||
| resolver := r.PipelineFor( | ||
| abstract.Handle, | ||
| ) | ||
|
|
||
| r.Mux.HandleFunc("GET /projects", resolver) | ||
| } | ||
|
|
||
| func (r *Router) Social() { | ||
| abstract := handler.MakeSocialHandler() | ||
|
|
||
| resolver := r.PipelineFor( | ||
| abstract.Handle, | ||
| ) | ||
|
|
||
| r.Mux.HandleFunc("GET /social", resolver) | ||
| } | ||
|
|
||
| func (r *Router) Talks() { | ||
| abstract := handler.MakeTalks() | ||
|
|
||
| resolver := r.PipelineFor( | ||
| abstract.Handle, | ||
| ) | ||
|
|
||
| r.Mux.HandleFunc("GET /talks", resolver) | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,34 @@ | ||
| package handler | ||
|
|
||
| import ( | ||
| "github.com/oullin/pkg/http" | ||
| "log/slog" | ||
| baseHttp "net/http" | ||
| "os" | ||
| ) | ||
|
|
||
| type ExperienceHandler struct { | ||
| content string | ||
| } | ||
|
|
||
| func MakeExperienceHandler() ExperienceHandler { | ||
| return ExperienceHandler{ | ||
| content: "./storage/fixture/experience.json", | ||
| } | ||
| } | ||
|
|
||
| func (h ExperienceHandler) Handle(w baseHttp.ResponseWriter, r *baseHttp.Request) *http.ApiError { | ||
| fixture, err := os.ReadFile(h.content) | ||
|
|
||
| if err != nil { | ||
| slog.Error("Error reading projects file", "error", err) | ||
|
|
||
| return http.InternalError("could not read experience data") | ||
| } | ||
|
|
||
| if err := writeJSON(fixture, w); err != nil { | ||
| return http.InternalError(err.Error()) | ||
| } | ||
|
|
||
| return nil // A nil return indicates success. | ||
| } | ||
This file contains hidden or 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,34 @@ | ||
| package handler | ||
|
|
||
| import ( | ||
| "github.com/oullin/pkg/http" | ||
| "log/slog" | ||
| baseHttp "net/http" | ||
| "os" | ||
| ) | ||
|
|
||
| type ProfileHandler struct { | ||
| content string | ||
| } | ||
|
|
||
| func MakeProfileHandler() ProfileHandler { | ||
| return ProfileHandler{ | ||
| content: "./storage/fixture/profile.json", | ||
| } | ||
| } | ||
|
|
||
| func (h ProfileHandler) Handle(w baseHttp.ResponseWriter, r *baseHttp.Request) *http.ApiError { | ||
| fixture, err := os.ReadFile(h.content) | ||
|
|
||
| if err != nil { | ||
| slog.Error("Error reading projects file", "error", err) | ||
|
|
||
| return http.InternalError("could not read profile data") | ||
| } | ||
|
|
||
| if err := writeJSON(fixture, w); err != nil { | ||
| return http.InternalError(err.Error()) | ||
| } | ||
|
|
||
| return nil // A nil return indicates success. | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.