Golang CRUD operations with JWT authentication
-
Golang
-
MySQL
-
Fiber (Http framework)
-
GORM (ORM)
-
Viper (Configuration)
-
Golang Migrate (Database Migration)
-
Go Playground Validator (Validation)
All config is in config.json
file.
migrate -database "mysql://<your_username>:<your_password>@tcp(<your_host>:<your_port>)/<your_database>?charset=utf8mb4&parseTime=true&loc=Local" -path database/migrations up
go run cmd/web/main.go
POST /signup
Body field | Type | Description |
---|---|---|
name |
string |
Required |
email |
string |
Requried, max 255 character |
password |
string |
Required, minimum 8 character |
POST /auth/signin
Body field | Type | Description |
---|---|---|
email |
string |
Required |
password |
string |
required |
GET /signout
POST /auth/token
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 |
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 /products/:id
Headers | Description | Value |
---|---|---|
Authorization |
Type :Bearer token |
Bearer <YOUR_ACCESS_TOKEN |
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 /product/:id
Headers | Description | Value |
---|---|---|
Authorization |
Type :Bearer token |
Bearer <YOUR_ACCESS_TOKEN |
go test ./test