Controller

A controller's purpose is to receive specific requests for the application. The routing mechanism controls which controller receives which requests. Frequently, each controller has more than one route, and different routes can perform different actions.

Syntax for create controller in Tinh Tinh:

package app

import "github.com/tinh-tinh/tinhtinh/core"

func Controller(module *core.DynamicModule) *core.DynamicController {
    ctrl := module.NewController("users")
    
    ctrl.Get("", func (ctx core.Ctx) {
        ctx.JSON(core.Map{
            "data": "ok"
        })
    })
    
    return ctrl
}

Method available in controller

Method
Description

Use(...Middleware)

function for common middleware

Guard(...Guard)

function for check forbidden as middleware

Version(string)

function mark version for controller or routes

Registry()

function registry for group middleware to use for all routes in controller

Pipe(...Pipe)

validate and transform dto

Get(string, Handler)

registry Get Http

Post(string, Handler)

registry Post Http

Put(string, Handler)

registry Put Http

Patch(string, Handler)

registry Patch Http

Delete(string, Handler)

registry Delete Http

Handler(string, http.Handler)

registry Handler for pure http.Handler

Inject(Provide)

get provider with name in module

Last updated