router_builder

package module
v0.0.0-...-1775dd6 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2023 License: MIT Imports: 8 Imported by: 0

README

Echo router builder

A builder design pattern for the echo framework router. This lib made mvc projects easier to create and simpler to maintain. See the example bellow:

Example

controller file: controllers/access.go:


package controllers

import (
  "github.com/labstack/echo/v4"
  r "github.com/Mth-Ryan/echo_router_builder"
)

AccessController = r.NewController("/access").
  View("/login", "login.tmpl.html", nil).
  Post("/login", loginAction))
  
func loginAction(c echo.Context) error {
  ...
}

main file: main.go

  package main
  
  import (
    m "github.com/labstack/echo/v4/middleware"
    r "github.com/Mth-Ryan/echo_router_builder"
    "example.com/project/controllers"
  )
  
  builder := r.NewBuilder(m.Logger(), m.Recovery()).
    RegisterStatic("/public", "assets").
    RegisterViews("views", ".tmpl.html").
    Register(AccessController)
    
  e := builder.Build
  e.Logger.Fatal(e.Start(":8080"))

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Controller

type Controller struct {
	// contains filtered or unexported fields
}

func NewController

func NewController(baseRoute string, middlewares ...echo.MiddlewareFunc) *Controller

func (*Controller) Delete

func (c *Controller) Delete(route string, inner echo.HandlerFunc, middlewares ...echo.MiddlewareFunc) *Controller

func (*Controller) Get

func (c *Controller) Get(route string, inner echo.HandlerFunc, middlewares ...echo.MiddlewareFunc) *Controller

func (*Controller) Head

func (c *Controller) Head(route string, inner echo.HandlerFunc, middlewares ...echo.MiddlewareFunc) *Controller

func (*Controller) Options

func (c *Controller) Options(route string, inner echo.HandlerFunc, middlewares ...echo.MiddlewareFunc) *Controller

func (*Controller) Patch

func (c *Controller) Patch(route string, inner echo.HandlerFunc, middlewares ...echo.MiddlewareFunc) *Controller

func (*Controller) Post

func (c *Controller) Post(route string, inner echo.HandlerFunc, middlewares ...echo.MiddlewareFunc) *Controller

func (*Controller) Put

func (c *Controller) Put(route string, inner echo.HandlerFunc, middlewares ...echo.MiddlewareFunc) *Controller

func (*Controller) RedirectDelete

func (c *Controller) RedirectDelete(route string, to string, status int) *Controller

func (*Controller) RedirectGet

func (c *Controller) RedirectGet(route string, to string, status int) *Controller

func (*Controller) RedirectPatch

func (c *Controller) RedirectPatch(route string, to string, status int) *Controller

func (*Controller) RedirectPost

func (c *Controller) RedirectPost(route string, to string, status int) *Controller

func (*Controller) RedirectPut

func (c *Controller) RedirectPut(route string, to string, status int) *Controller

func (*Controller) SubController

func (c *Controller) SubController(sub *Controller) *Controller

func (*Controller) View

func (c *Controller) View(route string, view string, args any, middlewares ...echo.MiddlewareFunc) *Controller

func (*Controller) ViewWitchCB

func (c *Controller) ViewWitchCB(route string, view string, dataCB func(echo.Context) any, middlewares ...echo.MiddlewareFunc) *Controller

type ErrorHandler

type ErrorHandler struct {
	// contains filtered or unexported fields
}

func NewErrorHandler

func NewErrorHandler() *ErrorHandler

func (*ErrorHandler) AddHandler

func (e *ErrorHandler) AddHandler(status int, handler echo.HTTPErrorHandler)

func (*ErrorHandler) GetHandler

func (e *ErrorHandler) GetHandler() echo.HTTPErrorHandler

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

type InnerRouter

type InnerRouter interface {
	Add(method, path string, handler echo.HandlerFunc, middleware ...echo.MiddlewareFunc) *echo.Route
	Group(prefix string, m ...echo.MiddlewareFunc) (g *echo.Group)
}

type Renderer

type Renderer struct {
	// contains filtered or unexported fields
}

func NewRenderer

func NewRenderer(baseFolder, ext string) *Renderer

func (*Renderer) Render

func (t *Renderer) Render(w io.Writer, name string, data interface{}, c echo.Context) error

type RouterBuilder

type RouterBuilder struct {
	// contains filtered or unexported fields
}

func NewBuilder

func NewBuilder(middlewares ...echo.MiddlewareFunc) *RouterBuilder

func (*RouterBuilder) Build

func (b *RouterBuilder) Build() *echo.Echo

func (*RouterBuilder) ForbidenHandler

func (b *RouterBuilder) ForbidenHandler(h echo.HTTPErrorHandler) *RouterBuilder

func (*RouterBuilder) ForbidenView

func (b *RouterBuilder) ForbidenView(view string, data any) *RouterBuilder

func (*RouterBuilder) InternalServerErrorHandler

func (b *RouterBuilder) InternalServerErrorHandler(h echo.HTTPErrorHandler) *RouterBuilder

func (*RouterBuilder) InternalServerErrorView

func (b *RouterBuilder) InternalServerErrorView(view string, data any) *RouterBuilder

func (*RouterBuilder) NotFoundHandler

func (b *RouterBuilder) NotFoundHandler(h echo.HTTPErrorHandler) *RouterBuilder

func (*RouterBuilder) NotFoundView

func (b *RouterBuilder) NotFoundView(view string, data any) *RouterBuilder

func (*RouterBuilder) Register

func (b *RouterBuilder) Register(c *Controller) *RouterBuilder

func (*RouterBuilder) RegisterStatic

func (b *RouterBuilder) RegisterStatic(route, folder string) *RouterBuilder

func (*RouterBuilder) RegisterViews

func (b *RouterBuilder) RegisterViews(baseFolder, ext string) *RouterBuilder

func (*RouterBuilder) UnauthorizedHandler

func (b *RouterBuilder) UnauthorizedHandler(h echo.HTTPErrorHandler) *RouterBuilder

func (*RouterBuilder) UnauthorizedView

func (b *RouterBuilder) UnauthorizedView(view string, data any) *RouterBuilder

Jump to

Keyboard shortcuts

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