NetLife Guru

Open source Go packages for fast, maintainable web systems. Built with a documentation-first approach.

Product
OverviewGolang packagesNews
Documentation
DocumentationGo LoggerGo RouterGo DB Form
Company
OverviewContactNewsGitHub
Community / Support
Supportinfo@netlife.guru
© 2026 NetLife Guru. All rights reserved.
GitHubinfo@netlife.guru
NetLife GuruNetLife GuruNetLife Guru
NetLife GuruNetLife GuruNetLife Guru
OverviewDocumentationNewsSupportContact

Golang packages

About
Route HandlersParameterized RoutesWildcard RoutesRoute GroupsMiddlewareGroup MiddlewareMounting Standard HandlersRequest Context
RouterCore Concepts

Wildcard Routes

Capture and forward dynamic URL branches using wildcard routes for static files, frontend applications, mounted services, and catch-all handlers.

Wildcard routes capture the remaining unmatched part of the URL path.

They are useful for:

  • static file serving
  • frontend SPA routing
  • mounted applications
  • reverse proxies
  • catch-all handlers
  • nested services
  • asset delivery

Wildcard matching allows a route to handle an entire URL branch instead of a single fixed path.


Basic Wildcard Syntax

Wildcard routes use the * syntax.

Example:

r.GET("/files/*", func(w http.ResponseWriter, req *http.Request, ctx *router.Context) {
	w.Write([]byte(req.URL.Path))
})

Example requests:

/files/report.pdf
/files/images/logo.png
/files/archive/2026/05/data.json

All requests beginning with:

/files/

are matched by the same handler.


Example

package main

import (
	"net/http"

	"github.com/netlifeguru/router"
)

func main() {
	r := router.New()

	r.GET("/files/*", func(w http.ResponseWriter, req *http.Request, ctx *router.Context) {
		w.Write([]byte(req.URL.Path))
	})

	r.ListenAndServe(":8000")
}

Request:

/files/images/logo.png

Response:

/files/images/logo.png

Wildcards with Mount

Wildcards are commonly used together with mounted handlers.

Example:

r.Mount("/assets/*", http.FileServer(http.Dir("./public")))

This forwards all requests under:

/assets/

to the mounted file server.

Examples:

/assets/style.css
/assets/js/app.js
/assets/images/logo.png

This pattern is commonly used for:

  • static assets
  • frontend applications
  • Swagger UI
  • GraphQL playgrounds
  • mounted services
  • reverse proxies

Wildcards with MountFunc

Wildcard routes also work with MountFunc.

r.MountFunc("/services/*", func(w http.ResponseWriter, req *http.Request) {
	w.Write([]byte(req.URL.Path))
})

This allows standard net/http handlers to process entire URL branches.


SPA Frontend Routing

Wildcard routes are useful for Single Page Applications.

Example:

r.Mount("/app/*", http.FileServer(http.Dir("./frontend")))

Requests such as:

/app/dashboard
/app/settings/profile
/app/users/42

can all be handled by the mounted frontend application.


Wildcard Matching Behavior

Wildcards always match the remaining path after the route prefix.

Example route:

/files/*

Matches:

/files/a.txt
/files/images/logo.png
/files/archive/2026/report.pdf

Does not match:

/file/test.txt

because the prefix differs.


Notes

Wildcard routes are designed for branch-style routing where an entire subtree of URLs should be handled by the same handler.

For single dynamic segments, prefer parameterized routes:

/users/{id}

instead of:

/users/*

This keeps route matching more explicit and easier to maintain.

Parameterized Routes

Use route parameters, prepared pattern matchers, and custom regex constraints to validate URL segments before requests reach handlers.

Route Groups

Organize related routes under shared URL prefixes for APIs, versioning, admin panels, and modular applications.

On this page

Basic Wildcard SyntaxExampleWildcards with MountWildcards with MountFuncSPA Frontend RoutingWildcard Matching BehaviorNotes