henrylee2cn / Lessgo
Licence: mit
Lessgo 是一款简单、稳定、高效、灵活的 golang web 开发框架,支持动态路由、自动化API测试文档、热编译、热更新等,实现前后端分离、系统与业务分离,完美兼容MVC与MVVC等多种开发模式,非常利于企业级应用与API接口的开发。[A simple, stable, efficient and flexible web framework.]
Stars: ✭ 481
Programming Languages
go
31211 projects - #10 most used programming language
Labels
Projects that are alternatives of or similar to Lessgo
Phoenix
Peace of mind from prototype to production
Stars: ✭ 17,476 (+3533.26%)
Mutual labels: web-framework
Bocadillo
(UNMAINTAINED) Fast, scalable and real-time capable web APIs for everyone
Stars: ✭ 401 (-16.63%)
Mutual labels: web-framework
Macaron
Package macaron is a high productive and modular web framework in Go.
Stars: ✭ 3,233 (+572.14%)
Mutual labels: web-framework
Iris
The fastest HTTP/2 Go Web Framework. AWS Lambda, gRPC, MVC, Unique Router, Websockets, Sessions, Test suite, Dependency Injection and more. A true successor of expressjs and laravel | 谢谢 https://github.com/kataras/iris/issues/1329 |
Stars: ✭ 21,587 (+4387.94%)
Mutual labels: web-framework
Farrow
Farrow is a progressive, incrementally-adoptable TypeScript framework for full stack development.
Stars: ✭ 384 (-20.17%)
Mutual labels: web-framework
Ofbiz Framework
Apache OFBiz is an open source product for the automation of enterprise processes. It includes framework components and business applications for ERP, CRM, E-Business/E-Commerce, Supply Chain Management and Manufacturing Resource Planning. OFBiz provides a foundation and starting point for reliable, secure and scalable enterprise solutions.
Stars: ✭ 315 (-34.51%)
Mutual labels: web-framework
Centurion
Centurion is a web-based framework for rapid prototyping and building larger web projects.
Stars: ✭ 327 (-32.02%)
Mutual labels: web-framework
Routing Controllers
Create structured, declarative and beautifully organized class-based controllers with heavy decorators usage in Express / Koa using TypeScript and Routing Controllers Framework.
Stars: ✭ 3,557 (+639.5%)
Mutual labels: web-framework
Zkweb
A flexible web framework supports .Net Framework and .Net Core
Stars: ✭ 475 (-1.25%)
Mutual labels: web-framework
Vapor
💧 A server-side Swift HTTP web framework.
Stars: ✭ 21,194 (+4306.24%)
Mutual labels: web-framework
Echo
High performance, minimalist Go web framework
Stars: ✭ 21,297 (+4327.65%)
Mutual labels: web-framework
Lessgo Web Framework
概述
Lessgo是一款Go语言开发的简单、稳定、高效、灵活的 web开发框架。它的项目组织形式经过精心设计,实现前后端分离、系统与业务分离,完美兼容MVC与MVVC等多种开发模式,非常利于企业级应用与API接口的开发。当然,最值得关注的是它突破性支持运行时路由重建,开发者可在Admin后台轻松配置路由,并实现启用/禁用模块或操作、添加/移除中间件等!同时,它以ApiHandler与ApiMiddleware为项目基本组成单元,可实现编译期或运行时的自由搭配组合,也令开发变得更加灵活富有趣味性。
适用场景
- 网站
- web应用
- Restful API服务应用
- 企业应用
当前版本
- V0.7.0
- 发布日期:2016.06.01
最新功能特性
- 使用简单、运行稳定高效(核心架构来自对echo真正意义的二次开发)
- 兼容流行系统模式如:MVC、MVVC、Restful...
- httprouter真实路由配合强大的虚拟路由层,不仅性能优秀更可同时支持在源码或admin中动态配置
- 多异构数据库支持,且用户可以选择xorm或者gorm两种引擎(当然愿意,用户还可以同时使用两种引擎)
- 优化的项目目录组织最佳实践,满足复杂企业应用需要
- 集成统一的系统日志(system、database独立完整的日志)
- 提供Session管理(优化beego框架中的session包)
- 强大的前端模板渲染引擎(pongo2)
- 天生支持运行时可更新的API测试网页(swagger2.0)
- 配置文件自动补填默认值,并按字母排序
- 支持热编译
- 支持热升级
- 另外灵活的扩展包中还包含HOTP、TOTP、UUID以及各种条码生成工具等常用工具包
框架下载
go get -u github.com/henrylee2cn/lessgo
go get -u github.com/henrylee2cn/less
go get -u github.com/henrylee2cn/lessgoext/...
框架构成
代码示例
- main.go
import (
"github.com/henrylee2cn/lessgo"
"github.com/henrylee2cn/lessgoext/swagger"
_ "github.com/henrylee2cn/lessgoext/dbservice/xorm"
// _ "github.com/henrylee2cn/lessgoext/dbservice/gorm"
_ "github.com/henrylee2cn/lessgo_demo/middleware"
_ "github.com/henrylee2cn/lessgo_demo/router"
)
func main() {
// 开启自动api文档,通过config/apidoc_allow.myconfig进行配置
swagger.Reg()
// 指定根目录URL
lessgo.SetHome("/home")
// 开启网络服务
lessgo.Run()
}
- 定义一个较复杂的操作
import (
. "github.com/henrylee2cn/lessgo"
"github.com/henrylee2cn/lessgo_demo/sysmodel/admin"
)
var Index = ApiHandler{
Desc: "后台管理登录操作",
Method: "POST|PUT",
Params: []Param{
{"user", "formData", true, "henry11111", "用户名"},
{"user", "query", true, "henry22222", "用户名"},
{"user", "path", true, "henry33333", "用户名"},
{"password", "formData", true, "1111111111", "密码"},
{"password", "query", true, "2222222222", "密码"},
{"password", "path", true, "3333333333", "密码"},
},
Handler: func(c *Context) error {
// 测试读取cookie
id := c.CookieParam(Config.Session.SessionName)
c.Log().Info("cookie中的%v: %#v", Config.Session.SessionName, id)
// 测试session
c.Log().Info("从session读取上次请求的输入: %#v", c.GetSession("info"))
c.SetSession("info", map[string]interface{}{
"user": c.FormParam("user"),
"password": c.FormParam("password"),
})
c.Log().Info("path用户名: %#v", c.PathParam("user"))
c.Log().Info("query用户名: %#v", c.QueryParam("user"))
c.Log().Info("formData用户名: %#v", c.FormParam("user"))
c.Log().Info("path密码: %#v", c.PathParam("password"))
c.Log().Info("query密码: %#v", c.QueryParam("password"))
c.Log().Info("formData密码: %#v", c.FormParam("password"))
return c.Render(200,
"sysview/admin/login/index.tpl",
map[string]interface{}{
"name": c.FormParam("user"),
"password": c.FormParam("password"),
"repeatfunc": admin.Login.Repeatfunc,
},
)
},
}.Reg()
- 一个简单的数据模型
import (
"strings"
)
type login struct{}
var Login = login{}
func (_ login) Repeatfunc(s string, count int) string {
return strings.Repeat(s, count)
}
- 一个简单的中间件
var ShowHeader = lessgo.ApiMiddleware{
Name: "显示Header",
Desc: "显示Header测试",
Config: nil,
Middleware: func(c *lessgo.Context) error {
c.Log().Info("测试中间件-显示Header:%v", c.Request().Header)
return nil
},
}.Reg()
- 在源码中定义路由
package router
import (
"github.com/henrylee2cn/lessgo"
"github.com/henrylee2cn/lessgo_demo/bizhandler/home"
"github.com/henrylee2cn/lessgo_demo/middleware"
)
func init() {
lessgo.Root(
lessgo.Leaf("/websocket", home.WebSocket, middleware.ShowHeader),
lessgo.Branch("/home", "前台",
lessgo.Leaf("/index", home.Index, middleware.ShowHeader),
).Use(middleware.Print),
)
}
系统文档
项目架构
项目目录结构
─Project 项目开发目录
├─config 配置文件目录
│ ├─app.config 系统应用配置文件
│ └─db.config 数据库配置文件
├─common 后端公共目录
│ └─... 如utils等其他
├─middleware 后端公共中间件目录
├─static 前端公共目录 (url: /static)
│ ├─tpl 公共tpl模板目录
│ ├─js 公共js目录 (url: /static/js)
│ ├─css 公共css目录 (url: /static/css)
│ ├─img 公共img目录 (url: /static/img)
│ └─plugin 公共js插件 (url: /static/plugin)
├─uploads 默认上传下载目录
├─router 源码路由配置
│ ├─sys_router.go 系统模块路由文件
│ ├─biz_router.go 业务模块路由文件
├─sys_handler 系统模块后端目录
│ ├─xxx 子模块目录
│ │ ├─example.go example操作
│ │ └─... xxx的子模块目录
│ └─... 其他子模块目录
├─sys_model 系统模块数据模型目录
├─sys_view 系统模块前端目录 (url: /sys)
│ ├─xxx 与sys_handler对应的子模块目录 (url: /sys/xxx)
│ │ ├─example.tpl 相应操作的模板文件
│ │ ├─example2.html 无需绑定操作的静态html文件
│ │ ├─xxx.css css文件(可有多个)
│ │ ├─xxx.js js文件(可有多个)
│ │ └─... xxx的子模块目录
├─biz_handler 业务模块后端目录
│ ├─xxx 子模块目录
│ │ ├─example.go example操作
│ │ └─... xxx的子模块目录
│ └─... 其他子模块目录
├─biz_model 业务模块数据模型目录
├─biz_view 业务模块前端目录 (url: /biz)
│ ├─xxx 与biz_handler对应的子模块目录 (url: /biz/xxx)
│ │ ├─example.tpl 相应操作的模板文件
│ │ ├─example2.html 无需绑定操作的静态html文件
│ │ ├─xxx.css css文件(可有多个)
│ │ ├─xxx.js js文件(可有多个)
│ │ └─... xxx的子模块目录
├─database 默认数据库文件存储目录
├─logger 运行日志输出目录
└─main.go 应用入口文件
贡献者名单
贡献者 | 贡献概要 |
---|---|
henrylee2cn | 代码的主要实现者 (第一作者) |
changyu72 | 架构的主要设计者 (第二作者) |
LeSou |
开源协议
Lessgo 项目采用商业应用友好的 MIT 协议发布。
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].