All Projects → cgrant → gin-gorm-api-example

cgrant / gin-gorm-api-example

Licence: other
[Article] Minimal code for Golang based API

Programming Languages

go
31211 projects - #10 most used programming language

Labels

Projects that are alternatives of or similar to gin-gorm-api-example

iam
企业级的 Go 语言实战项目:认证和授权系统
Stars: ✭ 1,900 (+1838.78%)
Mutual labels:  gin, gorm
Go init
一个用go组织项目结构,主要包括 gin, goredis, gorm, websocket, rabbitmq等。👉
Stars: ✭ 183 (+86.73%)
Mutual labels:  gin, gorm
Gosql
golang orm and sql builder
Stars: ✭ 141 (+43.88%)
Mutual labels:  gin, gorm
Golang Gin Realworld Example App
Exemplary real world application built with Golang + Gin
Stars: ✭ 1,780 (+1716.33%)
Mutual labels:  gin, gorm
pink-lady
a template project of gin app.
Stars: ✭ 44 (-55.1%)
Mutual labels:  gin, gorm
Zendea
A free, open-source, self-hosted forum software written in Go 官方QQ群:656868
Stars: ✭ 116 (+18.37%)
Mutual labels:  gin, gorm
Goilerplate
Clean Boilerplate of Go, Domain-Driven Design, Clean Architecture, Gin and GORM.
Stars: ✭ 173 (+76.53%)
Mutual labels:  gin, gorm
Ginbro
Converting a MySQL database'schema to a RESTful golang APIs app in the fastest way
Stars: ✭ 97 (-1.02%)
Mutual labels:  gin, gorm
ginadmin
基于Gin开发的后台管理系统,集成了、数据库操作、日志管理、权限分配管理、多模板页面、自动分页器、数据库迁移和填充、Docker集成部署等功能、静态资源打包
Stars: ✭ 149 (+52.04%)
Mutual labels:  gin, gorm
go api boilerplate
🐶Go (Golang)🚀REST / GraphQL API + Postgres boilerplate
Stars: ✭ 127 (+29.59%)
Mutual labels:  gin, gorm
Ultimate Go
This repo contains my notes on working with Go and computer systems.
Stars: ✭ 1,530 (+1461.22%)
Mutual labels:  gin, gorm
kuu
Modular Go Web Framework based on GORM and Gin.
Stars: ✭ 15 (-84.69%)
Mutual labels:  gin, gorm
Logrus
Hooks for logrus logging
Stars: ✭ 110 (+12.24%)
Mutual labels:  gin, gorm
Gin bbs
Gin BBS App
Stars: ✭ 123 (+25.51%)
Mutual labels:  gin, gorm
Ugin
UGin is an API boilerplate written in Go (Golang) with Gin Framework.
Stars: ✭ 110 (+12.24%)
Mutual labels:  gin, gorm
Cmall Go
golang写的电子商城的API接口
Stars: ✭ 167 (+70.41%)
Mutual labels:  gin, gorm
Goforum
Let's go a forum
Stars: ✭ 23 (-76.53%)
Mutual labels:  gin, gorm
Duckygo
一个同时支持Session以及JWT的高性能高可用 Golang Restful API 脚手架 !
Stars: ✭ 57 (-41.84%)
Mutual labels:  gin, gorm
Goweibo
Go Weibo App
Stars: ✭ 243 (+147.96%)
Mutual labels:  gin, gorm
laya-template
服务基本框架,template
Stars: ✭ 13 (-86.73%)
Mutual labels:  gin, gorm

Simple CRUD API in Go

This is an example of a minimalist api that might be ideal for prototyping.

Read the walkthrough on my blog at:https://cgrant.io/post/code/go/simple-crud-api-with-go-gin-and-gorm/

Dynamic Model - Simply update the struct

It has AutoMigrate enabled in the main function which allows the model struct to me changed as needed during development phases.

Simplified Data Persistence with GORM

In general I'm not a fan of ORM solutions, and in practice I would recommend manually coding the persistence logic. This code however is intended to shorten the cycle and focus on prototyping in as little code as possible. I’ve found GORM to be a popular and flexible ORM. It seems to be pretty good in this space.

Simplified route handling with Gin

Previously I worked with gorilla and negroni for my web handling. I stumble across Gin and didn't want yet another new framework but it turned out to be just want I needed here. It's straightforward and simple with some built in features ideal for API work

Favorite Parts

In general I like that I can get a working solution with just 80 lines of code.

Also I liked the parsing and mapping from the request to persistence. You're able to pass in one field or the entire model and the system correctly updates. No need to specify the exact input.

Streamlined update. There a bit of code in the upsert method that gets a model from the db, and the maps the PUT body onto it, then saves it in three simple lines. It was just refreshingly simple.

db.Where("id = ?", id).First(&person)
c.BindJSON(&person)
db.Save(&person)

Wrap up

Any rate I'll probably use this for simple prototyping and tutorials. Clearly needs more code before production use.

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