Skip to main content

Routing

Go-Web handles all HTTP requests within routers. Routers are simple structures that define every request/group of requests included in the web application. You can find and define all the routers in the router package.

Every router must be an instance of the register.HTTPRouter structure and should implement at least a Route or a Group.

The HTTPRouter structure
// HTTPRouter contains Route and Group that defines a complete HTTP Router
type HTTPRouter struct {
Route []Route
Groups []Group
}

Route

This structure is used to define a concrete HTTP endpoint and must be an instance of the register.Route structure.

The Route structure
// Route defines an HTTP Router endpoint
type Route struct {
Name string
Path string
Action string
Method string
Description string
Validation interface{}
Middleware []Middleware
}

As you can see in the figure above a Route structure is a simple structure that contains all request information:

FieldDescription
NameThe name of the route
PathThe path of the route
ActionThe action of the route
MethodThe method of the route
DescriptionThe description of the route
ValidationThe validation of the route
MiddlewareThe middlewares of the route

Groups

As the name explains, the Groups field contains a list of Group structure. This contains a list of routes grouped by a prefix.

The Group structure
// Group defines a group of HTTP Route
type Group struct {
Name string
Prefix string
Routes []Route
Middleware []Middleware
}
FieldDescription
NameThe name of the group
PrefixThe prefix of the group
RoutesThe routes of the group
MiddlewareThe middlewares of the group