https://github.com/dedidot/gorm-gin
Simple api with gin and gorm
https://github.com/dedidot/gorm-gin
api gin-gonic golang gorm orm rest-api
Last synced: 3 months ago
JSON representation
Simple api with gin and gorm
- Host: GitHub
- URL: https://github.com/dedidot/gorm-gin
- Owner: dedidot
- Created: 2018-02-27T09:53:18.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-03-10T06:55:06.000Z (over 7 years ago)
- Last Synced: 2025-04-09T13:12:12.094Z (6 months ago)
- Topics: api, gin-gonic, golang, gorm, orm, rest-api
- Language: Go
- Homepage:
- Size: 7.8 MB
- Stars: 108
- Watchers: 4
- Forks: 29
- Open Issues: 0
-
Metadata Files:
- Readme: README.MD
Awesome Lists containing this project
README
# Api go simple
It is a just simple RESTful API with Go using:
1. **Gin Framework**
2. **Gorm**## Installation & Run
```bash
# Download this project
$ go get github.com/dedidot/gorm-gin# Download Gin Framework
$ go get github.com/gin-gonic/gin# Download GORM
$ go get github.com/jinzhu/gorm
```Setting DB in main.go
```go
Config.DB, err = gorm.Open("mysql", "DBUSERNAME:DBPASSWORD@tcp(127.0.0.1:3306)/DBNAME?charset=utf8&parseTime=True&loc=Local")
```## Structure
```
├── Models
│ ├── Book.go // Book models
| ├── Scheme.go // Book struct and tabel
├── Config
│ └── Database.go // Global DB
├── Controllers
│ └── Book.go // Book Controller
├── ApiHelpers
│ └── Response.go // response function
├── Routers
| └── Routers.go // Routers
└── main.go
```## API
#### /book
* `GET` : Get all book
* `POST` : Create a new book#### /book/:id
* `GET` : Get a book
* `PUT` : Update a book
* `DELETE` : Delete a book#Post Params
```
{
"author": "Op Super John Doe Bilw",
"name": "Implementation Golang",
"category": "Knowledge"
}
```