command
Version:
v0.5.0
Opens a new window with list of versions in this module.
Published: Jul 19, 2025
License: AGPL-3.0
Opens a new window with license information.
Imports: 4
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
README
¶
Domain-Based Routing Example
This example demonstrates how to use the router's domain-based routing feature to handle different domains with different routes.
Features
- Routes requests based on the
Host header
- Supports multiple domains with different route handlers
- Includes a default handler for unmatched domains
- Demonstrates serving both API and admin interfaces on different domains
Setup
- Add the following entries to your
/etc/hosts (Unix/Mac) or C:\\Windows\\System32\\drivers\\etc\\hosts (Windows) file:
127.0.0.1 api.example.com admin.example.com
- Run the example:
go run main.go
Testing
Open the following URLs in your browser or use curl:
Code Overview
The example creates two domains:
-
api.example.com - Handles API requests
/status - Returns API status
/users - Returns a list of users
-
admin.example.com - Serves an admin interface
How It Works
- The router checks the
Host header of incoming requests
- Routes are matched based on the domain first, then the path
- If no matching domain is found, the
NotFoundHandler is used
Documentation
¶
There is no documentation for this package.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.