Skip to content

Commit

Permalink
feat: add host parameter to route configuration functions
Browse files Browse the repository at this point in the history
- Updated `routeNotFoundSpecifier` and `noRouteSpecifier` to accept
  a string parameter for host, enhancing configurability.
- Modified `SetupHostBasedRoutes` to pass hostnames to additional
  configuration functions, enabling host-specific routing setups.
- This change improves the flexibility and clarity of route
  configuration, making it easier to manage routes based on hostnames.
  • Loading branch information
infuzu-yidisprei committed Sep 19, 2024
1 parent 6be15b2 commit 721c035
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func defineHost2Routes(group *echo.Group) {
}

// routeNotFoundSpecifier defines behavior for unspecified routes.
func routeNotFoundSpecifier(group *echo.Group) error {
func routeNotFoundSpecifier(_ string, group *echo.Group) error {
// Route handler for unspecified routes, returns a not-found message.
group.RouteNotFound("/*", func(c echo.Context) error {
return c.String(http.StatusNotFound, "No known route")
Expand Down
2 changes: 1 addition & 1 deletion example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func defineHost2Routes(group *echo.Group) {
}

// routeNotFoundSpecifier defines behavior for unspecified routes.
func routeNotFoundSpecifier(group *echo.Group) error {
func routeNotFoundSpecifier(_ string, group *echo.Group) error {
// Route handler for unspecified routes, returns a not-found message.
group.RouteNotFound("/*", func(c echo.Context) error {
return c.String(http.StatusNotFound, "No known route")
Expand Down
6 changes: 3 additions & 3 deletions hostroute.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func SecureAgainstUnknownHosts(knownHosts map[string]bool) echo.MiddlewareFunc {
}

// SetupHostBasedRoutes configures routing based on hostnames.
func SetupHostBasedRoutes(e *echo.Echo, hostConfigs []HostConfig, genericHosts []string, secureAgainstUnknownHosts bool, additionalHostConfig ...func(*echo.Group) error) error {
func SetupHostBasedRoutes(e *echo.Echo, hostConfigs []HostConfig, genericHosts []string, secureAgainstUnknownHosts bool, additionalHostConfig ...func(string, *echo.Group) error) error {
var allHosts []string

for _, hostConfig := range hostConfigs {
Expand All @@ -40,7 +40,7 @@ func SetupHostBasedRoutes(e *echo.Echo, hostConfigs []HostConfig, genericHosts [
}
if len(additionalHostConfig) > 0 {
for _, config := range additionalHostConfig {
err := config(hostGroup) // Apply additional configurations if provided
err := config(hostConfig.Host, hostGroup) // Apply additional configurations if provided
if err != nil {
return err // Return on error
}
Expand All @@ -65,7 +65,7 @@ func SetupHostBasedRoutes(e *echo.Echo, hostConfigs []HostConfig, genericHosts [

if len(additionalHostConfig) > 0 {
for _, config := range additionalHostConfig {
err := config(genericGroup) // Apply additional configurations
err := config(genericHost, genericGroup) // Apply additional configurations
if err != nil {
return err // Return on error
}
Expand Down
2 changes: 1 addition & 1 deletion hostroute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func noRouteHandler(c echo.Context) error {
return c.String(http.StatusNotFound, "No known route")
}

func noRouteSpecifier(group *echo.Group) error {
func noRouteSpecifier(_ string, group *echo.Group) error {
group.RouteNotFound("*", noRouteHandler)
return nil
}
Expand Down

0 comments on commit 721c035

Please sign in to comment.