Giter Site home page Giter Site logo

singo's Introduction

Singo

Singo: Simple Single Golang Web Service

go-crud正式改名为Singo!

使用Singo开发Web服务: 用最简单的架构,实现够用的框架,服务海量用户

https://github.com/bydmm/singo

Singo文档

https://singo.gourouting.com/

视频实况教程

让我们写个G站吧!Golang全栈编程实况

使用Singo开发的项目实例

https://github.com/bydmm/giligili

目的

本项目采用了一系列Golang中比较流行的组件,可以以本项目为基础快速搭建Restful Web API

特色

本项目已经整合了许多开发API所必要的组件:

  1. Gin: 轻量级Web框架,自称路由速度是golang最快的
  2. GORM: ORM工具。本项目需要配合Mysql使用
  3. Gin-Session: Gin框架提供的Session操作工具
  4. Go-Redis: Golang Redis客户端
  5. godotenv: 开发环境下的环境变量工具,方便使用环境变量
  6. Gin-Cors: Gin框架提供的跨域中间件
  7. 自行实现了国际化i18n的一些基本功能
  8. 本项目是使用基于cookie实现的session来保存登录状态的,如果需要可以自行修改为token验证

本项目已经预先实现了一些常用的代码方便参考和复用:

  1. 创建了用户模型
  2. 实现了/api/v1/user/register用户注册接口
  3. 实现了/api/v1/user/login用户登录接口
  4. 实现了/api/v1/user/me用户资料接口(需要登录后获取session)
  5. 实现了/api/v1/user/logout用户登出接口(需要登录后获取session)

本项目已经预先创建了一系列文件夹划分出下列模块:

  1. api文件夹就是MVC框架的controller,负责协调各部件完成任务
  2. model文件夹负责存储数据库模型和数据库操作相关的代码
  3. service负责处理比较复杂的业务,把业务代码模型化可以有效提高业务代码的质量(比如用户注册,充值,下单等)
  4. serializer储存通用的json模型,把model得到的数据库模型转换成api需要的json对象
  5. cache负责redis缓存相关的代码
  6. auth权限控制文件夹
  7. util一些通用的小工具
  8. conf放一些静态存放的配置文件,其中locales内放置翻译相关的配置文件

Godotenv

项目在启动的时候依赖以下环境变量,但是在也可以在项目根目录创建.env文件设置环境变量便于使用(建议开发环境使用)

MYSQL_DSN="db_user:db_password@/db_name?charset=utf8&parseTime=True&loc=Local" # Mysql连接地址
REDIS_ADDR="127.0.0.1:6379" # Redis端口和地址
REDIS_PW="" # Redis连接密码
REDIS_DB="" # Redis库从0到10
SESSION_SECRET="setOnProducation" # Seesion密钥,必须设置而且不要泄露
GIN_MODE="debug"

Go Mod

本项目使用Go Mod管理依赖。

go mod init go-crud
export GOPROXY=http://mirrors.aliyun.com/goproxy/
go run main.go // 自动安装

运行

go run main.go

项目运行后启动在3000端口(可以修改,参考gin文档)

singo's People

Contributors

bydmm avatar l-helianthus avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.