src

package
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package src iris web framework bootstrap.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Application

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

Application is a component for iris web framework.

func (*Application) AddAnnotationControllers

func (o *Application) AddAnnotationControllers(entries ...*ControllerEntry) *Application

AddAnnotationControllers adds a controller entry list into application.

Example
// Controller entries.
//
// You can run `go run main.go gen:annotation` to generate from
// controller files in app/controllers directory then save to target
// file `app/annotations/annotation_controllers.go`.
var AnnotationControllers = []*ControllerEntry{
	{
		Controller:  &TestController{},
		Middlewares: []string{"key"},
		Prefix:      "/test",
	},
}

// Component create and run.
component := New()
component.Application.AddAnnotationControllers(AnnotationControllers...)
component.Run()
Output:

func (*Application) AddAnnotationCrontabs

func (o *Application) AddAnnotationCrontabs(workers ...*crontab.Worker) *Application

AddAnnotationCrontabs adds a crontab worker list into application.

Example
// Controller entries.
//
// You can run `go run main.go gen:annotation` to generate from
// crontab files in app/crontabs directory then save to target
// file `app/annotations/annotation_crontabs.go`.
var AnnotationCrontabs = []*crontab.Worker{
	crontab.NewWorker(crontab.EveryMinute, &TestCrontab{}).
		SetRunOnStartup(true),
}

// Component create and run.
component := New()
component.Application.AddAnnotationCrontabs(AnnotationCrontabs...)
component.Run()
Output:

func (*Application) AddAnnotationHandlers

func (o *Application) AddAnnotationHandlers(entries ...*HandlerEntry) *Application

AddAnnotationHandlers adds an annotation handlers list for application.

Example
// Controller entries.
//
// You can run `go run main.go gen:annotation` to generate from
// controller files in app/controllers directory then save to target
// file `app/annotations/annotation_handlers.go`.
var AnnotationHandlers = []*HandlerEntry{
	{
		Handler:     func(i iris.Context) {},
		Middlewares: []string{"key"},
		Method:      "POST",
		Path:        "/test",
	},
}

// Component create and run.
component := New()
component.Application.AddAnnotationHandlers(AnnotationHandlers...)
component.Run()
Output:

func (*Application) AddAnnotationMiddlewares

func (o *Application) AddAnnotationMiddlewares(mapper map[string]iris.Handler) *Application

AddAnnotationMiddlewares adds an annotation middlewares mapping for application.

Example
// Annotation middlewares.
//
// You can run `go run main.go gen:annotation` to generate from
// controller files in app/controllers directory then save to target
// file `app/annotations/annotation_middlewares.go`.
var AnnotationMiddlewares = map[string]iris.Handler{
	"middleware-name": func(i iris.Context) {
		println("user middleware")

		// Note: follow code `i.Next()` is required. Request handler will not
		//       be fired if `i.Next()` not set.
		i.Next()
	},
}

// Component create and run.
component := New()
component.Application.AddAnnotationMiddlewares(AnnotationMiddlewares)
component.Run()
Output:

func (*Application) AddMiddlewares

func (o *Application) AddMiddlewares(middlewares ...iris.Handler)

AddMiddlewares adds a global middleware list into application. All controllers and handlers are affected.

func (*Application) AddParallels

func (o *Application) AddParallels(runners ...ParallelRunner) *Application

AddParallels adds a runner list into application.

func (*Application) Framework

func (o *Application) Framework() *iris.Application

Framework returns an iris web framework application.

type Component

type Component struct {
	Application *Application
	Console     *console.Container
}

Component is a top level component for iris web framework with console.

func New

func New() *Component

New creates a top level component instance with a console and an application.

func (*Component) Run

func (o *Component) Run()

Run runs the top level component. It's schedule to console runner.

type ControllerEntry

type ControllerEntry struct {
	// Controller
	// is a pointer instance of any type.
	//
	// Example:
	//   entry.Controller = &controllers.Controller{}
	Controller any

	// Middlewares
	// is a list name for http request. Each name must be registered in
	// annotation middlewares.
	//
	// Example:
	//   entry.Middlewares = []string{
	//       "name-1",
	//       "ExampleMiddleware",
	//   }
	Middlewares []string

	// Prefix
	// is a route prefix for http request like follows.
	//
	// Example:
	//   entry.Prefix = "/user"
	//   entry.Prefix = "/v1/user"
	Prefix string
}

ControllerEntry is a controller entry.

entry := &ControllerEntry{
   Controller: &controllers.Controller{},
   Middlewares: {"name-1", "ExampleMiddleware"},
   Prefix: "v1/users",
}

type HandlerEntry

type HandlerEntry struct {
	// Handler
	// is a handler for http request.
	//
	// Example:
	//
	//  entry.Handler = handlers.UserLogin
	//
	//  entry.Handler = func(i iris.Context){
	//      framework.Do(i, user.Login)
	//  }
	Handler iris.Handler

	// Method
	// is a method name for http request like GET, POST etc. Empty string
	// for any request method.
	//
	// Example:
	//   entry.Method = "GET"
	//   entry.Method = "POST"
	Method string

	// Middlewares
	// is a list name for http request. Each name must be registered in
	// annotation middlewares.
	//
	// Example:
	//   entry.Middlewares = []string{
	//       "name-1",
	//       "ExampleMiddleware",
	//   }
	Middlewares []string

	// Path
	// is route uri for http request like follows.
	//
	// Example:
	//   entry.Path = "/v1/user/login"
	//   entry.Path = "/v1/user/id:int"
	//   entry.Path = "/v1/user/id:int/name:string"
	Path string
}

HandlerEntry is a handler entry.

entry := &HandlerEntry{
   Handler: handlers.UserLogin,
   Middlewares: {"name-1", "ExampleMiddleware"},
   Path: "/v1/user/login",
}

type ParallelRunner

type ParallelRunner func(ctx context.Context)

ParallelRunner is an executable function that run in goroutine when iris application start.

Directories

Path Synopsis
gen_annotation
Package gen_annotation parse annotation from source code file and recognize follows.
Package gen_annotation parse annotation from source code file and recognize follows.
Package conf built-in iris web application configuration.
Package conf built-in iris web application configuration.
Package errs built-in iris web application errors.
Package errs built-in iris web application errors.
Package logics request logical scheduler.
Package logics request logical scheduler.
Package middlewares built-in iris web application middlewares.
Package middlewares built-in iris web application middlewares.

Jump to

Keyboard shortcuts

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