GithubHelp home page GithubHelp logo

hxker / gin-gorm-api-example Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cgrant/gin-gorm-api-example

0.0 2.0 0.0 2 KB

[Article] Minimal code for Golang based API

Home Page: http://cgrant.io/tutorials/go/simple-crud-api-with-go-gin-and-gorm/

Go 100.00%

gin-gorm-api-example's Introduction

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:http://cgrant.io/tutorials/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.

gin-gorm-api-example's People

Contributors

cgrant avatar

Watchers

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