1 Star 0 Fork 0

非一般/framework-iris

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

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){
    ...
}

空文件

简介

iris web framework application 展开 收起
README
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/go-wares/framework-iris.git
git@gitee.com:go-wares/framework-iris.git
go-wares
framework-iris
framework-iris
v1.1.8

搜索帮助