Code Monkey home page Code Monkey logo

gin_restful_demo's Introduction

gin+gorm restful demo

目录结构

.
├── README.md
├── api                     // 对外的API接口(controller)
│   ├── error_code.go
│   └── user.go
├── dao                     // 数据库操作
│   ├── db.go
│   └── user.go
├── go.mod
├── go.sum
├── main.go                 // 主程序
├── migrate.go              // 迁移工具(自动创建表)
├── model                   // 模型
│   └── user.go
└── utils                   // 工具包
    └── utils.go

修改数据库配置

修改dao/db.goconnection变量

创建表结构

go run migrate.go

运行项目

go run main.go
  1. 创建用户
curl 'http://127.0.0.1:8080/users' -XPOST -H 'Content-Type: application/json' -d '{"name":"longerwu","age":23}'
  1. 更新用户
 curl 'http://127.0.0.1:8080/users/5' -XPUT -H 'Content-Type: application/json' -d '{"name":"longerwu","age":24}'
  1. 获取单个用户
curl 'http://127.0.0.1:8080/users/5'
  1. 获取多个用户(分页)
 curl 'http://127.0.0.1:8080/users?limit=1&page=2'

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.