This repository has been archived by the owner on Jun 2, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Remove unsupported flag see: golang/go#50501 * Sync general project structure from mp3binder * Introduce a simple health endpoint * Simple health service * Change permanent redirect to temporary * Fixes a known issue with httprouter * Fixes parameter access for httprouter * Updates inspiration references and golang 1.18b2 * Closed todo about other routers
- Loading branch information
Showing
20 changed files
with
722 additions
and
137 deletions.
There are no files selected for viewing
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
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 was deleted.
Oops, something went wrong.
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,38 @@ | ||
package chirouter | ||
|
||
import ( | ||
"fmt" | ||
"hex-microservice/adder" | ||
"hex-microservice/deleter" | ||
"hex-microservice/health" | ||
"hex-microservice/http/rest" | ||
"hex-microservice/lookup" | ||
"net/http" | ||
|
||
chi "github.com/go-chi/chi/v5" | ||
"github.com/go-chi/chi/v5/middleware" | ||
"github.com/go-logr/logr" | ||
) | ||
|
||
// New returns a http.Handler that exposes the service with the chi router. | ||
func New(log logr.Logger, mappedURL string, h health.Service, a adder.Service, l lookup.Service, d deleter.Service) http.Handler { | ||
r := chi.NewRouter() | ||
r.Use(middleware.RequestID) | ||
r.Use(middleware.RealIP) | ||
r.Use(middleware.Logger) | ||
r.Use(middleware.Recoverer) | ||
r.Use(middleware.StripSlashes) | ||
|
||
r.NotFound(http.NotFound) | ||
r.MethodNotAllowed(http.NotFound) | ||
|
||
s := rest.New(log, h, a, l, d, chi.URLParam) | ||
|
||
r.Get("/health", s.Health()) | ||
|
||
r.Get(fmt.Sprintf("/{%s}", rest.UrlParameterCode), s.RedirectGet(mappedURL)) | ||
r.Post("/", s.RedirectPost(mappedURL)) | ||
r.Delete(fmt.Sprintf("/{%s}/{%s}", rest.UrlParameterCode, rest.UrlParameterToken), s.RedirectDelete(mappedURL)) | ||
|
||
return r | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.