Skip to content

DanarCahyadi12/golang-crud

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Golang CRUD

Golang CRUD operations with JWT authentication

Tech Stack

  • Golang

  • MySQL

Framework & Library

  • Fiber (Http framework)

  • GORM (ORM)

  • Viper (Configuration)

  • Golang Migrate (Database Migration)

  • Go Playground Validator (Validation)

Configuration

All config is in config.json file.

Run migrations

 migrate -database "mysql://<your_username>:<your_password>@tcp(<your_host>:<your_port>)/<your_database>?charset=utf8mb4&parseTime=true&loc=Local" -path database/migrations up

Run application

go run cmd/web/main.go

API Reference

Sign up

  POST /signup
Body field Type Description
name string Required
email string Requried, max 255 character
password string Required, minimum 8 character

Sign in

  POST /auth/signin
Body field Type Description
email string Required
password string required

Sign out

  GET /signout

Get access token

  POST /auth/token

Create product

  POST /products
Headers Description Value
Authorization Type :Bearer token Bearer <YOUR_ACCESS_TOKEN
Body field Type Description
name string Required
price number required
stock number required

Update product

  PUT /products/:id
Headers Description Value
Authorization Type :Bearer token Bearer <YOUR_ACCESS_TOKEN
Body field Type Description
name string Required
price number required
stock number required

Delete product

  DELETE /products/:id
Headers Description Value
Authorization Type :Bearer token Bearer <YOUR_ACCESS_TOKEN

Get products

  GET /products
Headers Description Value
Authorization Type :Bearer token Bearer <YOUR_ACCESS_TOKEN

Query params

Key Description Type
page default value : 1 number
limit default value : 50 number

Get detail products

  GET /product/:id
Headers Description Value
Authorization Type :Bearer token Bearer <YOUR_ACCESS_TOKEN

Run Unit Test

go test ./test

About

Golang CRUD with JWT authentication

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages