All Projects → 1024casts → Snake

1024casts / Snake

Licence: mit
🐍 一款小巧的基于Go构建的开发框架,可以快速构建API服务或者Web网站进行业务开发,遵循SOLID设计原则

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to Snake

Go Gin Example
An example of gin
Stars: ✭ 4,992 (+711.71%)
Mutual labels:  api, swagger, gorm, gin, jwt
Golang Gin Realworld Example App
Exemplary real world application built with Golang + Gin
Stars: ✭ 1,780 (+189.43%)
Mutual labels:  api, restful, gorm, gin, jwt
Go Admin
基于Gin + Vue + Element UI的前后端分离权限管理系统脚手架(包含了:多租户的支持,基础用户管理功能,jwt鉴权,代码生成器,RBAC资源控制,表单构建,定时任务等)3分钟构建自己的中后台项目;文档:https://doc.go-admin.dev Demo: https://www.go-admin.dev Antd beta版本:https://preview.go-admin.dev
Stars: ✭ 5,439 (+784.39%)
Mutual labels:  swagger, gin, jwt, gorm
Full Stack
Full stack, modern web application generator. Using Flask, PostgreSQL DB, Docker, Swagger, automatic HTTPS and more.
Stars: ✭ 451 (-26.67%)
Mutual labels:  api, swagger, jwt
Go Base
Go RESTful API Boilerplate with JWT Authentication backed by PostgreSQL
Stars: ✭ 928 (+50.89%)
Mutual labels:  api, restful, jwt
Python Api Development Fundamentals
Develop a full-stack web application with Python and Flask
Stars: ✭ 44 (-92.85%)
Mutual labels:  api, restful, jwt
Go Gin Api
基于 Gin 进行模块化设计的 API 框架,封装了常用功能,使用简单,致力于进行快速的业务研发。比如,支持 cors 跨域、jwt 签名验证、zap 日志收集、panic 异常捕获、trace 链路追踪、prometheus 监控指标、swagger 文档生成、viper 配置文件解析、gorm 数据库组件、gormgen 代码生成工具、graphql 查询语言、errno 统一定义错误码、gRPC 的使用 等等。
Stars: ✭ 730 (+18.7%)
Mutual labels:  swagger, gorm, gin
Node Express Mongoose Passport Jwt Rest Api Auth
Node, express, mongoose, passport and JWT REST API authentication example
Stars: ✭ 146 (-76.26%)
Mutual labels:  api, restful, jwt
Ugin
UGin is an API boilerplate written in Go (Golang) with Gin Framework.
Stars: ✭ 110 (-82.11%)
Mutual labels:  api, gorm, gin
Koa Rest Api Boilerplate
💯 Boilerplate for Node.js Koa RESTful API application with Docker, Swagger, Jest, CodeCov and CircleCI
Stars: ✭ 420 (-31.71%)
Mutual labels:  api, swagger, restful
Flask Restplus
Fully featured framework for fast, easy and documented API development with Flask
Stars: ✭ 2,585 (+320.33%)
Mutual labels:  api, swagger, restful
Supra Api Nodejs
❤️ Node.js REST API boilerplate
Stars: ✭ 182 (-70.41%)
Mutual labels:  api, restful, jwt
Flasgger
Easy OpenAPI specs and Swagger UI for your Flask API
Stars: ✭ 2,825 (+359.35%)
Mutual labels:  api, swagger, restful
Go Book Store Api
Go Sample project to understand Mysql CRUD operation with best practises Includes logging, JWT, Swagger and Transactions
Stars: ✭ 18 (-97.07%)
Mutual labels:  api, swagger, jwt
Flask Restx
Fork of Flask-RESTPlus: Fully featured framework for fast, easy and documented API development with Flask
Stars: ✭ 1,050 (+70.73%)
Mutual labels:  api, swagger, restful
Ssm
👅基于RESTful风格的前后端分离的SSM框架,集成了shiro和swagger等框架
Stars: ✭ 141 (-77.07%)
Mutual labels:  swagger, restful, jwt
Zendea
A free, open-source, self-hosted forum software written in Go 官方QQ群:656868
Stars: ✭ 116 (-81.14%)
Mutual labels:  gorm, gin, jwt
Gin Web
由gin + gorm + jwt + casbin组合实现的RBAC权限管理脚手架Golang版, 搭建完成即可快速、高效投入业务开发
Stars: ✭ 107 (-82.6%)
Mutual labels:  restful, gin, jwt
Flama
🔥 Fire up your API with this flamethrower
Stars: ✭ 161 (-73.82%)
Mutual labels:  api, swagger, restful
Go-Gin-Api
基于golang开源框架 gin封装的api框架
Stars: ✭ 42 (-93.17%)
Mutual labels:  swagger, gin, gorm

🐍 snake

GitHub Workflow Status codecov GolangCI godoc OpenTracing Badge Go Report Card gitmoji License

一款适合于快速开发业务的 Go 框架,可快速构建 API 服务 或 Web 网站。

Pro Tip: 每个目录下基本都有 README,可以让框架使用起来更轻松 ^_^

设计思想和原则

框架中用到的设计思想和原则,尽量满足 "高内聚、低耦合",主要遵从下面几个原则

    1. 单一职责原则
    1. 基于接口而非实现编程
    1. 依赖注入
    1. 多用组合
    1. 迪米特法则

迪米特法则: 不该有直接依赖关系的类之间,不要有依赖;有依赖关系的类之间,尽量只依赖必要的接口

✨ 技术栈

  • 框架路由使用 Gin 路由
  • 中间件使用 Gin 框架的中间件
  • 数据库组件 GORM
  • 文档使用 Swagger 生成
  • 配置文件解析库 Viper
  • 使用 JWT 进行身份鉴权认证
  • 校验器使用 validator 也是 Gin 框架默认的校验器
  • 任务调度 cron
  • 包管理工具 Go Modules
  • 测试框架 GoConvey
  • CI/CD GitHub Actions
  • 使用 GolangCI-lint 进行代码检测
  • 使用 make 来管理 Go 工程
  • 使用 shell(admin.sh) 脚本来管理进程
  • 使用 YAML 文件进行多环境配置

📗 目录结构

├── Makefile                     # 项目管理文件
├── build                        # 编译目录
├── cmd                          # 脚手架目录
├── config                       # 配置文件统一存放目录
├── docs                         # Swagger 文档,执行 swag init 生成的
├── handler                      # 控制器目录,用来读取输入、调用业务处理、返回结果
├── internal                     # 业务目录
│   ├── cache                    # 基于业务封装的cache
│   ├── idl                      # 数据结构转换
│   ├── model                    # 数据库 model
│   ├── repository               # 数据访问层
│   └── service                  # 业务逻辑层
├── logs                         # 存放日志的目录
├── main.go                      # 项目入口文件
├── pkg                          # 公共的 package
├── router                       # 路由及中间件目录
└── scripts                      # 存放用于执行各种构建,安装,分析等操作的脚本

🛠️ 快速开始

方式一

直接Clone项目的方式,文件比较全

TIPS: 需要本地安装MySQL数据库和 Redis

# 下载安装,可以不用是 GOPATH
git clone https://github.com/1024casts/snake

# 进入到下载目录
cd snake

# 生成环境配置文件
cd config
cp config.local.yaml config.{ENV}.yaml

# 编译
make build

# 运行
./scripts/admin.sh start

方式二

使用脚手架,仅生成基本目录, 不包含pkg等部分公共模块目录

# 下载
go get github.com/1024casts/snake/cmd/snake

export GO111MODULE=on
# 或者在.bashrc 或 .zshrc中加入
# source .bashrc 或 source .zshrc

# 使用
snake new snake-demo 
# 或者 
snake new github.com/foo/bar

💻 常用命令

  • make help 查看帮助
  • make dep 下载 Go 依赖包
  • make build 编译项目
  • make gen-docs 生成接口文档
  • make test-coverage 生成测试覆盖
  • make lint 检查代码规范

🏂 模块

公共模块

  • 图片上传(支持本地、七牛)
  • 短信验证码(支持七牛)

用户模块

  • 注册
  • 登录(邮箱登录,手机登录)
  • 发送手机验证码(使用七牛云服务)
  • 更新用户信息
  • 关注/取消关注
  • 关注列表
  • 粉丝列表

📝 接口文档

http://localhost:8080/swagger/index.html

开发规范

遵循: Uber Go 语言编码规范

📖 开发规约

🚀 部署

单独部署

上传到服务器后,直接运行命令即可

./scripts/admin.sh start

Docker 部署

如果安装了 Docker 可以通过下面命令启动应用:

# 运行
docker-compose up -d

# 验证
http://127.0.0.1/health

Supervisord

编译并生成二进制文件

go build -o bin_snake

如果应用有多台机器,可以在编译机器进行编译,然后使用rsync同步到对应的业务应用服务器

以下内容可以整理为脚本

export GOROOT=/usr/local/go1.13.8
export GOPATH=/data/build/test/src
export GO111MODULE=on
cd /data/build/test/src/github.com/1024casts/snake
/usr/local/go1.13.8/bin/go build -o /data/build/bin/bin_snake -mod vendor main.go
rsync -av /data/build/bin/ x.x.x.x:/home/go/snake
supervisorctl restart snake

这里日志目录设定为 /data/log 如果安装了 Supervisord,可以在配置文件中添加下面内容(默认:/etc/supervisor/supervisord.conf):

[program:snake]
# environment=
directory=/home/go/snake
command=/home/go/snake/bin_snake
autostart=true
autorestart=true
user=root
stdout_logfile=/data/log/snake_std.log
startsecs = 2
startretries = 2
stdout_logfile_maxbytes=10MB
stdout_logfile_backups=10
stderr_logfile=/data/log/snake_err.log
stderr_logfile_maxbytes=10MB
stderr_logfile_backups=10

重启 Supervisord

supervisorctl restart snake

📜 CHANGELOG

🏘️ 谁在用

💬 Discussion

🔋 JetBrains 开源证书支持

snake 项目一直以来都是在 JetBrains 公司旗下的 GoLand 集成开发环境中进行开发,基于 free JetBrains Open Source license(s) 正版免费授权,在此表达我的谢意。

📄 License

MIT. See the LICENSE file for details.

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].