33![ Lessgo Favicon] ( https://github.com/lessgo/doc/raw/master/img/favicon.png )
44
55##概述
6- Lessgo是一款Go语言开发的简单、稳定、高效、灵活的 web开发框架。它的项目组织形式经过精心设计,实现前后端分离、系统与业务分离,完美兼容MVC与MVVC等多种开发模式,非常利于企业级应用与API接口的开发。当然,最值得关注的是它突破性地支持了运行时路由重建,开发者可在Admin后台轻松实现启用/禁用模块与操作,添加/移除中间件等功能!同时,它推荐以HandlerFunc与MiddlewareFunc为基础的函数式编程,也令开发变得更加灵活富有趣味性。
7- 此外它也博采众长,核心架构修改自[ echo] ( https://github.com/labstack/echo ) ,数据库引擎内置为[ xorm] ( https://github.com/go-xorm/xorm ) ,模板引擎内置为[ pongo2] ( https://github.com/flosch/pongo2 ) ,其他某些功能模块修改自[ beego] ( https://github.com/astaxie/beego ) 以及其他优秀开源项目。(在此感谢这些优秀的开源项目)
6+ Lessgo是一款Go语言开发的简单、稳定、高效、灵活的 web开发框架。它的项目组织形式经过精心设计,实现前后端分离、系统与业务分离,完美兼容MVC与MVVC等多种开发模式,非常利于企业级应用与API接口的开发。当然,最值得关注的是它突破性支持运行时路由重建,开发者可在Admin后台轻松配置路由,并实现启用/禁用模块或操作、添加/移除中间件等!同时,它以ApiHandler与ApiMiddleware为项目基本组成单元,可实现编译期或运行时的自由搭配组合,也令开发变得更加灵活富有趣味性。
7+
8+ 官方QQ群:Go-Web 编程 42730308 [ ![ Go-Web 编程群] ( http://pub.idqqimg.com/wpa/images/group.png )] ( http://jq.qq.com/?_wv=1027&k=fzi4p1 )
89
910##适用场景
1011- 网站
@@ -13,36 +14,126 @@ Lessgo是一款Go语言开发的简单、稳定、高效、灵活的 web开发
1314- 企业应用
1415
1516##当前版本
16- - V0.5 .0
17- - 发布日期:2016.04.28
17+ - V0.6 .0
18+ - 发布日期:2016.05.17
1819
1920##最新功能特性
20- - 使用简单、运行稳定高效
21+ - 使用简单、运行稳定高效(核心架构来自echo的真正意义的二次开发)
2122- 兼容流行系统模式如: MVC 、MVVC、Restful...
22- - 强大的运行时动态路由(动态路由保存在Common/DB/lessgo.db中)
23- - 多异构数据库支持
23+ - 强大的运行时动态路由,同时支持在源码或admin中配置(动态路由保存在数据库中)
24+ - 多异构数据库支持(master分支使用xorm,dev-a分支使用gorm)
2425- 优化的项目目录组织最佳实践,满足复杂企业应用需要
2526- 集成统一的系统日志(system、database独立完整的日志)
26- - 提供Session管理
27+ - 提供Session管理(优化beego框架中的session包)
2728- 多种Token生成方式
28- - swagger集成智能API文档
29+ - 强大的前端模板渲染引擎(pongo2)
30+ - 天生支持运行时可更新的API测试网页(swagger2.0)
31+ - 配置文件自动补填默认值,并按字母排序
2932- 支持热编译
3033- 支持热升级
3134
32- ##项目架构
33- ![ Lessgo Web Framework] ( https://github.com/lessgo/doc/raw/master/img/LessgoWebFramework.jpg )
35+ ![ Lessgo Server] ( https://github.com/lessgo/doc/raw/master/img/server.jpg )
36+ ![ Lessgo Server] ( https://github.com/lessgo/doc/raw/master/img/admin.png )
37+
38+ ##框架下载
39+
40+ ``` sh
41+ go get -u github.com/lessgo/lessgo
42+ go get -u github.com/lessgo/lessgoext
43+ ```
3444
3545##框架构成
3646- 核心框架:[ lessgo] ( https://github.com/lessgo/lessgo )
3747- 框架扩展:[ lessgoext] ( https://github.com/lessgo/lessgoext )
3848- 项目Demo:[ demo] ( https://github.com/lessgo/demo )
3949- 框架文档 [ document] ( https://github.com/lessgo/doc )
4050
41- ##框架下载
51+ ##代码示例
4252
43- ``` sh
44- go get -u github.com/lessgo/lessgo
45- go get -u github.com/lessgo/lessgoext
53+ - Main.go
54+ ``` go
55+ import (
56+ " github.com/lessgo/lessgo"
57+ " github.com/lessgo/lessgoext/swagger"
58+ _ " github.com/lessgo/demo/BusinessAPI"
59+ _ " github.com/lessgo/demo/Common/Middleware"
60+ _ " github.com/lessgo/demo/SystemAPI"
61+ )
62+
63+ func main () {
64+ swagger.Init ()
65+ lessgo.SetHome (" /home" )
66+ lessgo.Run ()
67+ }
68+ ```
69+
70+ - 定义一个较复杂的操作
71+ ```
72+ import (
73+ . "github.com/lessgo/lessgo"
74+ )
75+
76+ var IndexHandle = ApiHandler{
77+ Desc: "后台管理登录操作",
78+ Method: "GET",
79+ Params: []Param{
80+ {"user", "path", true, "henry", "用户名"},
81+ {"password", "path", true, "12345678", "密码"},
82+ },
83+ Handler: func(ctx Context) error {
84+ // 测试读取cookie
85+ id, err := ctx.Request().Cookie("name")
86+ ctx.Logger().Info("cookie中的%v: %#v (%v)", "name", id, err)
87+
88+ // 测试session
89+ ctx.Logger().Info("从session读取上次请求的输入: %#v", ctx.GetSession("info"))
90+
91+ ctx.SetSession("info", map[string]interface{}{
92+ "user": ctx.Param("user"),
93+ "password": ctx.Param("password"),
94+ })
95+
96+ return ctx.Render(200,
97+ "SystemView/Admin/Login/index.tpl",
98+ map[string]interface{}{
99+ "name": ctx.Param("user"),
100+ "password": ctx.Param("password"),
101+ "repeatfunc": repeatfunc,
102+ },
103+ )
104+ },
105+ }.Reg()
106+ ```
107+
108+ - 一个简单的中间件
109+ ```
110+ var ShowHeaderWare = lessgo.RegMiddleware(lessgo.ApiMiddleware{
111+ Name: "显示Header",
112+ Desc: "显示Header测试",
113+ DefaultConfig: nil,
114+ Middleware: func(ctx lessgo.Context) error {
115+ logs.Info("测试中间件-显示Header:%v", ctx.Request().Header)
116+ return nil
117+ },
118+ })
119+ ```
120+
121+ - 在源码中定义路由
122+ ``` go
123+ import (
124+ " github.com/lessgo/lessgo"
125+ " github.com/lessgo/demo/BusinessAPI/Home"
126+ " github.com/lessgo/demo/Common/Middleware"
127+ )
128+
129+ func init () {
130+ lessgo.Root (
131+ lessgo.Leaf (" /websocket" , Home.WebSocketHandle , Middleware.ShowHeaderWare ),
132+ lessgo.Branch (" /home" , " 前台" ,
133+ lessgo.Leaf (" /index" , Home.IndexHandle , Middleware.ShowHeaderWare ),
134+ ).Use (Middleware.PrintWare ),
135+ )
136+ }
46137```
47138
48139##系统文档
@@ -51,6 +142,10 @@ go get -u github.com/lessgo/lessgoext
51142- [ 开始lessgo之旅] ( https://github.com/lessgo/doc/blob/master/Develop01.md )
52143- [ 更多(文档目录)] ( https://github.com/lessgo/doc/blob/master/README.md )
53144
145+ ##项目架构
146+ ![ Lessgo Web Framework] ( https://github.com/lessgo/doc/raw/master/img/LessgoWebFramework.jpg )
147+
148+
54149##项目目录组织
55150─Project 项目开发目录
56151├─Config 配置文件目录
@@ -68,10 +163,6 @@ go get -u github.com/lessgo/lessgoext
68163│ └─Plugin 公共js插件 (url: /static/plugin)
69164├─SystemAPI 系统模块后端目录
70165│ ├─SysRouter.go 系统模块路由文件
71- │ ├─SysCommon 后端公共目录
72- │ │ ├─Middleware 中间件目录
73- │ │ └─Model 数据模型
74- │ │ └─... 其他
75166│ ├─Xxx Xxx子模块目录
76167│ │ ├─ExampleHandle.go Example操作
77168│ │ ├─ExampleModel.go Example数据模型及模板函数
@@ -86,10 +177,6 @@ go get -u github.com/lessgo/lessgoext
86177│ │ └─... Xxx的子模块目录
87178├─BusinessAPI 业务模块后端目录
88179│ ├─BusRouter.go 业务模块路由文件
89- │ ├─BusCommon Business公共目录
90- │ │ ├─Middleware 中间件目录
91- │ │ └─Model 数据模型
92- │ │ └─... 其他
93180│ ├─Xxx Xxx子模块目录
94181│ │ ├─ExampleHandle.go Example操作
95182│ │ ├─ExampleModel.go Example数据模型及模板函数
@@ -114,8 +201,4 @@ go get -u github.com/lessgo/lessgoext
114201
115202##开源协议
116203Lessgo 项目采用商业应用友好的 [ MIT] ( https://github.com/lessgo/lessgo/raw/master/LICENSE ) 协议发布。
117-
118- ##项目联系
119- * 官方QQ群:Go-Web 编程 42730308 [ ![ Go-Web 编程群] ( http://pub.idqqimg.com/wpa/images/group.png )] ( http://jq.qq.com/?_wv=1027&k=fzi4p1 )
120- ![ Lessgo Server] ( https://github.com/lessgo/doc/raw/master/img/server.jpg )
121- ![ Lessgo Server] ( https://github.com/lessgo/doc/raw/master/img/admin.png )
204+
0 commit comments