• Stars
    star
    479
  • Rank 91,752 (Top 2 %)
  • Language
    Go
  • License
    MIT License
  • Created over 8 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Lessgo 是一款简单、稳定、高效、灵活的 golang web 开发框架,支持动态路由、自动化API测试文档、热编译、热更新等,实现前后端分离、系统与业务分离,完美兼容MVC与MVVC等多种开发模式,非常利于企业级应用与API接口的开发。[A simple, stable, efficient and flexible web framework.]

Lessgo Web Framework GoDoc GitHub release

Lessgo Favicon

概述

Lessgo是一款Go语言开发的简单、稳定、高效、灵活的 web开发框架。它的项目组织形式经过精心设计,实现前后端分离、系统与业务分离,完美兼容MVC与MVVC等多种开发模式,非常利于企业级应用与API接口的开发。当然,最值得关注的是它突破性支持运行时路由重建,开发者可在Admin后台轻松配置路由,并实现启用/禁用模块或操作、添加/移除中间件等!同时,它以ApiHandler与ApiMiddleware为项目基本组成单元,可实现编译期或运行时的自由搭配组合,也令开发变得更加灵活富有趣味性。

官方QQ群:Go-Web 编程 42730308 Go-Web 编程群

适用场景

  • 网站
  • 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以及各种条码生成工具等常用工具包

Lessgo Server Lessgo Server

框架下载

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),
    )
}

系统文档

项目架构

Lessgo Web Framework

项目目录结构

─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 协议发布。

More Repositories

1

pholcus

Pholcus is a distributed high-concurrency crawler software written in pure golang
Go
7,471
star
2

erpc

An efficient, extensible and easy-to-use RPC framework.
Go
2,496
star
3

faygo

Faygo is a fast and concise Go Web framework that can be used to develop high-performance web app(especially API) with fewer codes. Just define a struct handler, faygo will automatically bind/verify the request parameters and generate the online API doc.
Go
1,593
star
4

goutil

Golang common tool functions and components.
Go
369
star
5

surfer

Package surfer is a high level concurrency http client. It has surf andphantom download engines, highly simulated browser behavior, the function of analog login and so on.
Go
214
star
6

aster

Easily get the golang syntax tree and modify the code.
Go
151
star
7

faydoc

User manual of faygo frame.
117
star
8

gust

A Rust-inspired declarative-programming and generic-type module for Golang that helps avoid bugs and improve development efficiency.
Go
89
star
9

algorithm

algorithm library
Go
58
star
10

erpc-doc

eRPC Documents
Go
55
star
11

tp-micro

TP-Micro is a simple, powerful micro service framework based on Teleport.
Go
54
star
12

pholcus_lib

仅供学习的Pholcus爬虫规则库
Go
43
star
13

ameda

Powerful toolbox for golang data types.
Go
31
star
14

lessgo_demo

A demo of Lessgo.
Go
31
star
15

rester

Fast and concise RESTful web framework based on fasthttp
Go
27
star
16

apiware

Apiware binds the specified parameters of the Golang net/http and fasthttp requests to the structure and verifies the validity of the parameter values.
Go
24
star
17

wasmy

wasmy, easily customize my wasm app!
Rust
22
star
18

lessgoext

Lessgo's expansion module.
Go
22
star
19

timer

Go语言各种定时器的实现。
Go
21
star
20

rpc-benchmark

golang RPC framework benchmark
Go
20
star
21

go-crawler-practice

📕《Go语言爬虫编写实战》
19
star
22

lessgo_doc

Lessgo user's manual.
Go
18
star
23

pool

通用资源池,动态增加资源实例,并支持空闲资源定时回收。
Go
18
star
24

opay

以订单为主线、面向接口开发的在线支付通用模块
Go
17
star
25

mahonia

Copy from http://code.google.com/p/mahonia/
Go
17
star
26

pholcus_dependent

Pholcus第三方依赖包源码下载
Go
16
star
27

gofield

High-performance struct field accessor based on unsafe pointers.
Go
14
star
28

wasmesh

wasmesh is a WebAssembly service mesh framework.
Rust
14
star
29

erpc-book

Handbook of eRPC which is an efficient, extensible and easy-to-use RPC framework.
Go
12
star
30

beelogs

Upgrade from beego logs !
Go
12
star
31

tp-ext

Teleport v3 custom extensions collection.
Go
12
star
32

tconfig

源自beego的升级版配置文件解析库,目前支持解析的文件格式有 ini、json、xml、yaml。
Go
10
star
33

faygos

A micro service framework developed using 'faygo' and 'etcd'
Go
10
star
34

ipc

IPC Inter-Process Communication.
Go
9
star
35

cfgo

Cfgo from the YAML document, bi-directional synchronous multi-module configuration.
Go
9
star
36

beauty-go

Go解答《编程之美》系列
Go
9
star
37

less

lessgo 项目部署工具
Go
9
star
38

TRRW-Chrome-Extension-Template

Use React + TypeScript + Antd + Rust-Wasm to develop Chrome Extension.
TypeScript
8
star
39

flagx

Standard flag package extension with more features, such as struct flag, app framework, etc.
Go
8
star
40

easysync2

The EasySync2 Algorithm
Rust
7
star
41

utils

Go语言中的一些常用函数。
Go
7
star
42

lessgo_dependency

Lessgo‘s dependency package.
Go
7
star
43

env

Package env provides a convenient way to initialize variables from the environment.
Go
7
star
44

currip

currip helps you get current extranet ip or intranet ip.
Go
7
star
45

widerror

Error type with wide attributes, used for API unified error code
Rust
5
star
46

mysql-aes

MySQL Transparent Data Encryption
Go
5
star
47

henrylee2cn.github.com

Share Notes !
CSS
5
star
48

tp-p2p

A teleport-based p2p application framework that penetrates the intranet through TCP tunnel.
Go
5
star
49

option

Go-generics option module inspired by rust.
Go
4
star
50

sulfa

Basic algorithm library implemented by rust.
Rust
4
star
51

lycee

lycee is a key-value storage system being developed for me to learn rust.
Rust
4
star
52

codec_protobuf

Go
4
star
53

chinaid

Make or verify China ID
Go
4
star
54

andeya

3
star
55

slinbo

A personal chat application.
C++
2
star
56

result

Go-generics result module inspired by rust.
Go
2
star
57

sqlab

The project waiting for planning, some SQL tool functions are temporarily deposited.
Go
2
star
58

enum_const

enum const trait
Rust
2
star
59

vscode_debug_go

Configure my own local launch.json to improve ease of use
Go
2
star
60

api-response

A consistent structure for API responses, including success and error handling.
Rust
1
star
61

cubix

Standardized building block components born for Rust craft.
Rust
1
star
62

py-layout

Python Project Generator
Python
1
star
63

imgs-repo

我的图床仓库
1
star
64

convert_traits

Define your own conversion traits to solve the problem of converting two external types without using new types.
Rust
1
star