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/Gourouting/singo

更新日志

1.已支持接口测试 2.已经支持go1.20,请安装这个版本的golang使用本项目

视频实况教程

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

使用Singo开发的项目实例

仿B站的G站:https://github.com/Gourouting/giligili

Singo框架为移动端提供Token登录的案例: https://github.com/bydmm/singo-token-exmaple

目的

本项目采用了一系列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. httpexpect: 接口测试工具
  8. 自行实现了国际化i18n的一些基本功能
  9. 本项目是使用基于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 singo
export GOPROXY=http://mirrors.aliyun.com/goproxy/
go run main.go // 自动安装

运行

go run main.go

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

接口测试

【新】本项目内置了接口测试的内容

使用方法

  1. 确保自己在项目根目录下
  2. 在test目录下创建test专用的环境变量文件
cp test/.env.example test/.env
  1. 修改test/.env文件内容里的环境变量,保证可以正常连接mysql/redis
  2. 在项目根目录执行测试,并开启-v检查下测试是否在正确运行
go test -v ./test
  1. 确保测试可正确运行后,后续去掉-v参数,查看测试是否通过
go test ./test
ok      singo/test      (cached)

singo's People

Contributors

bydmm avatar l-helianthus avatar testwill avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

singo's Issues

I have meet some problem, i resolve it.

when i use browser plug-in the origin is like chrome-extension://ieoejemkppmjcdfbnfphhpbfmallhfnc/
is like must use app to send the post request. place 我尝试用英语编写问题

考虑增加一些debug log吗

现在调试起来有点累,手动加入了request和response log之后大幅优化使用体验。考虑包含更多的debug log吗

缺少dockerfile

该脚手架项目是否可以提供dockerfile,如果需要我可以提供PR

怎么配置多个数据库实例/多个数据库访问呢

例如:两个数据库地址127.0.0.1:3006|127.0.0.1:3007,这两个数据库地址分别都有两个database: user、customer;config、other等四个database。我现在需要在同一个项目访问四个数据库里面的表。我连接mysql的代码应该怎么写比较好呢,项目里面并没有相关的说明,只有简单的单个数据库连接并不十分实用。

go run main.go 报错,似乎是redis驱动版本太旧

go run main.go 
go: github.com/go-redis/[email protected]+incompatible: reading https://goproxy.io/github.com/go-redis/redis/@v/v6.15.3+incompatible.mod: 410 Gone

似乎是redis驱动版本太旧的原因

删除go.mod后,重新构建依赖

rm go.mod
go mod init singo
go mod tidy

新的依赖包版本是这样的:

module singo

go 1.13

require (
	github.com/gin-contrib/cors v1.3.0
	github.com/gin-contrib/sessions v0.0.1
	github.com/gin-gonic/gin v1.4.0
	github.com/go-redis/redis v6.15.6+incompatible
	github.com/jinzhu/gorm v1.9.11
	github.com/joho/godotenv v1.3.0
	golang.org/x/crypto v0.0.0-20191122220453-ac88ee75c92c
	gopkg.in/go-playground/validator.v8 v8.18.2
	gopkg.in/yaml.v2 v2.2.7
)

go get gihtub.com/bydmm/singo报错

错误如下

package singo/conf: unrecognized import path "singo/conf" (import path does not begin with hostname)

错误应该是man.go中导入模块未指定hostname

返回403

请问下post请求的时候,403会是什么原因尼?谢谢
image

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.