controller

package
v0.0.0-...-3264219 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 22, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package controller provides a base structure and interface for defining and registering routes in the application.

This package defines the Controller interface that all controllers must implement to register their routes, as well as a BaseController struct that provides a default implementation of the interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterModuleRoutes

func RegisterModuleRoutes(r *router.Router, m module.IModule)

RegisterModuleRoutes is a helper function to register routes for a module. It will panic if there is an error during registration or if a controller does not implement the required interface.

Types

type BaseController

type BaseController struct {
}

BaseController provides a default implementation of the Controller interface. It can be embedded in other controllers to inherit its default behavior, or overridden with custom implementations.

func (*BaseController) RegisterRoutes

func (bc *BaseController) RegisterRoutes(r *router.Router)

RegisterRoutes is the default implementation of the Controller interface's method. This method can be overridden by embedding BaseController in another struct and defining a custom implementation.

Example

type TestController struct {
	LessGo.BaseController
	Path    string
	Service TestService
}

func NewTestController(service *TestService, path string) *TestController {
	return &TestController{
		Service: *service,
		Path:    path,
	}
}

func (tc *TestController) RegisterRoutes(r *LessGo.Router) {
	tr := r.SubRouter(tc.Path)
	tr.Get("/ping", func(ctx *LessGo.Context) {
		ctx.Send("pong")
	})
}

type Controller

type Controller interface {
	RegisterRoutes(r *router.Router)
}

Controller defines the interface that all controllers in the application must implement. Any controller that implements this interface must define the RegisterRoutes method, which is responsible for setting up the necessary routes for the controller.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL