2

【Go实战】Gin + Gorm 基于RESTful API 的简单备忘录 | 含接口文档

 2 years ago
source link: https://blog.csdn.net/weixin_45304503/article/details/120680957
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Todo List 备忘录

在这里插入图片描述

此项目使用Gin+Gorm ,基于RESTful API实现的一个备忘录

规范是非常重要的,此项目非常适合小白入门学习web开发

Github开源链接

Todo List 接口文档

密码:0000

在这里插入图片描述

项目主要功能介绍

  • 用户注册登录 ( jwt-go鉴权 )
  • 新增 / 删除 / 修改 / 查询 备忘录
  • 存储每条备忘录的浏览次数view

项目部分代码介绍

	//任务操作
	authed.GET("tasks", api.ListTasks)
	authed.POST("task", api.CreateTask)
	authed.GET("task/:id", api.ShowTask)
	authed.DELETE("task/:id", api.DeleteTask)
	authed.PUT("task/:id", api.UpdateTask)
	authed.POST("search",api.SearchTasks)
type ShowTaskService struct {
}
func (service *ShowTaskService) Show(id string) serializer.Response


type DeleteTaskService struct {
}
func (service *DeleteTaskService) Delete(id string) serializer.Response


type UpdateTaskService struct {
	ID            uint   `form:"id" json:"id"`
	Title         string `form:"title" json:"title" binding:"required,min=2,max=100"`
	Content       string `form:"content" json:"content" binding:"max=1000"`
	Status 		  int    `form:"status" json:"status"`   //0 待办   1已完成
}
func (service *UpdateTaskService) Update(id string) serializer.Response


type SearchTaskService struct {
	Info string `form:"info" json:"info"`
}
func (service *SearchTaskService) Search() serializer.Response

项目主要依赖:

Golang V1.15

  • mysql
  • redis
  • jwt-go
TodoList/
├── api
├── cache
├── conf
├── middleware
├── model
├── pkg
│  ├── e
│  ├── logging
│  ├── util
├── routes
├── serializer
└── servive
  • api : 用于定义接口函数
  • cache : 放置redis缓存
  • conf : 用于存储配置文件
  • middleware : 应用中间件
  • model : 应用数据库模型
  • pkg / e : 封装错误码
  • pkg / logging : 日志打印
  • pkg / util : 工具函数
  • routes : 路由逻辑处理
  • serializer : 将数据序列化为 json 的函数
  • servive : 接口函数的实现
  1. mysql是存储主要数据
  2. redis用来存储备忘录的浏览次数

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

下载依赖

go mod tidy

运行

go run main.go

小生凡一,期待你的关注。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK