framework_iris

package module
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: 0 Imported by: 0

README

IRIS Web Application

import "gitee.com/go-wares/framework-iris/framework"

Workspace

Follow is an example application workspace structure.

/data/sketch
├─ app
│  ├─ annotations
│  │  ├─ annotation_controllers.go
│  │  ├─ annotation_crontabs.go
│  │  ├─ annotation_handlers.go
│  │  └─ annotation_middlewares.go
│  ├─ controllers
│  │  └─ controller.go
│  ├─ crontabs
│  │  └─ example_crontab.go
│  ├─ handlers
│  │  └─ example_handler.go
│  ├─ logics
│  │  ├─ home
│  │  │  └─ logic.go
│  │  └─ user
│  │     ├─ logic.go
│  │     ├─ request.go
│  │     └─ response.go
│  └─ middlewares
│     └─ example_middleware.go
│
├─ config
│  ├─ app.yaml
│  ├─ db.yaml
│  ├─ iris.yaml
│  ├─ log.yaml
│  └─ redis.yaml
│
└─ main.go

Example

import (
	"gitee.com/go-wares/framework-iris/framework"
	"gitee.com/go-wares/log"
    "sketch/app/annotations"
)

func main(){
    defer log.Close()

    c := framework.New()

    // Annotations can be generated by `go run main.go gen:annotation`
    c.Application.AddAnnotationMiddlewares(annotations.AnnotationMiddlewares)
	c.Application.AddAnnotationControllers(annotations.AnnotationControllers...)
	c.Application.AddAnnotationHandlers(annotations.AnnotationHandlers...)
	c.Application.AddAnnotationCrontabs(annotations.AnnotationCrontab...)

    // Run service.
    c.Run()
}

Run

go run main.go start

Build binary

go build \
   -trimpath \
   -gcflags "-trimpath=$GOPATH" \
   -ldflags "-s -w" \
   -o sketch

Build Annotation

You can run follow script to generate docs.

go run main.go gen:annotation
Controller

Scan source code files from app/controllers directory then generated to app/annotations/annotation_controllers.go.

Crontab

Scan source code files from app/crontabs directory then generated to app/annotations/annotation_crontabs.go.

Accepts

  • @Crontab("0 */1 * * * * *") - required,
  • @CrontabGlobalUnique(bool) - optional, default: false
  • @CrontabNodeUnique(bool) - optional, default: true
  • @CrontabRunOnStartup(bool) - optional, default: false

Example

// ExampleCrontab
// example crontab processor.
//
// @Crontab("0 */1 * * * * *")
// @CrontabGlobalUnique(true)
// @CrontabNodeUnique(true)
// @CrontabRunOnStartup(true)
type ExampleCrontab struct{}

// Required methods.

func (o *ExampleCrontab) OnRun(ctx context.Context) (err error) {return}

// Optional methods.

func (o *ExampleCrontab) OnBefore(ctx context.Context) (err error) {return}
func (o *ExampleCrontab) OnFailed(ctx context.Context, err error) {}
func (o *ExampleCrontab) OnFinish(ctx context.Context) {}
func (o *ExampleCrontab) OnSucceed(ctx context.Context) {}
Handler
Middleware

Scan source code files from app/middlewares directory then generated to app/annotations/annotation_middlewares.go.

Accepts

  • @Name(string)

Example 1 with same name in app/middlewares/example.go without annotation like follows.

// Example
// is an example middleware.
func Example(i iris.Context){
    i.Next()
}
// PostLogin
// send login request with POST method.
//
// @Middleware("Example")
func (o *Controller) PostLogin(i iris.Context){
    ...
}

Example 2 with custom name in app/middlewares/example.go with @Name modify like follows.

// Example
// is an example middleware.
//
// @Name("custom")
func Example(i iris.Context){
    i.Next()
}
// PostLogin
// send login request with POST method.
//
// @Middleware("custom")
func (o *Controller) PostLogin(i iris.Context){
    ...
}

Documentation

Overview

Package framework_iris iris web framework with console.

Directories

Path Synopsis
_examples
Package framework built-in iris web application alias.
Package framework built-in iris web application alias.
src
Package src iris web framework bootstrap.
Package src iris web framework bootstrap.
src/commands/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.
src/conf
Package conf built-in iris web application configuration.
Package conf built-in iris web application configuration.
src/errs
Package errs built-in iris web application errors.
Package errs built-in iris web application errors.
src/logics
Package logics request logical scheduler.
Package logics request logical scheduler.
src/middlewares
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