#### 入口:main.go
```go
app := iris.Default() //启动iris服务
route.InitRouter(app) //进入路由
app.Run(iris.Addr(":8080")), iris.WithoutServerError(iris.ErrServerClosed)) //设置端口号
```
#### 路由: route.go
```go
func InitRouter(app *iris.Application) {
g := controllers.NewIamController() //连接控制器层
app.Get("/xx/xx", g.xxx) //根据url调用
app.Post("/xx/xx", g.xxx)
}
```
#### controller.go
```go
type XController struct {
Service service.XService
}
func NewXController() *XController {
return &XController{Service: service.NewXService()}
}//连接service层
func (g *XController) XX(c iris.Context) {
xx := g.Service.XX(xx)//调用service层
}
```
#### service.go
```go
type XService interface {
XX(xx string) (xxx bool, xxxx string)
YY(yy map[string]string) (yyy string)
}
type xService struct{}
func NewXService() XService {
return &xService{}
}//建立接口供controller层调用
func (u xService) XX(xx string) (xxx bool, xxxx string) {
}
```
controller层常用来接收前端传来的信息,service层常用来放置功能算法,models层则放置和数据库的交互操作。
有疑问加站长微信联系(非本文作者))