Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/arielea/gindemo

๐Ÿ“š A basic go-gin demo
https://github.com/arielea/gindemo

gin-gonic go json jwt-token logger mysql self-development yaml

Last synced: 29 days ago
JSON representation

๐Ÿ“š A basic go-gin demo

Awesome Lists containing this project

README

        

# My Project

#### Package Install

##### Init Project
```
go mod init project_name

go run main.go
```

##### Install gin-gonic/gin moudle
```
go get -u github.com/gin-gonic/gin
```

##### Install Air (Hot Reload) - ใƒ›ใƒƒใƒˆใƒชใƒญใƒผใƒ‰
###### 1ใ€ git ใ‹ใ‚‰
```
git clone https://github.com/cosmtrek/air.git

cd air

go build -o project_directly

cd project

./air
```

###### 2ใ€go ใ‚’ๅˆฉ็”จใ—ใฆใ‚คใƒณใ‚นใƒˆใƒผใƒซใ—ใพใ™
```
go install github.com/cosmtrek/air@latest

air init

./air
```

###### 3ใ€config ใƒ•ใ‚กใ‚คใƒซใชใฉ
```tree
โ”€โ”€ config
โ”‚ย ย  โ”œโ”€โ”€ db.json
โ”‚ย ย  โ”œโ”€โ”€ config.json
โ”‚ย ย  โ”œโ”€โ”€ .env.json
```
db.json
```json
{
"prod": {
"user": "user id",
"password": "password",
"host": "host.url",
"port": "3306",
"dbname": "dbname",
"charset": "utf8mb4",
"parseTime": "True",
"loc": "Asia/Tokyo"
},
"test": {
},
"development": {
}
}

```

.env.json
```json
{
"gin_mode": "debug" // debug, prod, test
}
```

config.json
```json
{
"port": 1234, // your custom port
"db": true,
"redis": false,
"cache": true,
"log": true,
"environment_checker": true,
"error_warning": true,
"console_error":false,
"auto_db_checker": true,
"listener": false,
"test": true
}
```

###### 4ใ€ใ‚ฆใ‚งใƒ–ใ‚ตใ‚คใƒˆใ‹ใ‚‰ใƒ€ใ‚ฆใƒณใƒญใƒผใƒ‰ใ—ใพใ™
###### https://github.com/air-verse/air/releases ใƒšใƒผใ‚ธใซ่จชๅ•ใ—ใฆ้ฉๅˆ‡ใชใƒใƒƒใ‚ทใƒงใƒณใ‚’้ธๆŠžใ—ใ€ใƒ€ใ‚ฆใƒณใƒญใƒผใƒ‰ใ—ใพใ™

This project is a simple web application built with Go.

## Project Structure

- [README.md](#readme-md)
- [main.go](#main-go)
- [config/](#config)
- [config.go](#config-go)
- [settings.go](#settings-go)
- [controllers/](#controllers)
- [home_controller.go](#home-controller-go)
- [user_controller.go](#user-controller-go)
- [models/](#models)
- [user.go](#user-go)
- [product.go](#product-go)

## File Descriptions

### README.md

ใƒ—ใƒญใ‚ธใ‚งใ‚ฏใƒˆใฎใƒ‰ใ‚ญใƒฅใƒกใƒณใƒˆใ€ใƒ—ใƒญใ‚ธใ‚งใ‚ฏใƒˆใฎๆฆ‚่ฆใ€ใ‚ปใƒƒใƒˆใ‚ขใƒƒใƒ—ๆ‰‹้ †ใ€ใใฎไป–ใฎ้‡่ฆใชๆƒ…ๅ ฑใŒๅซใพใ‚Œใ„ใพใ™ใ€‚

### main.go

The entry point of the application. This file contains the main function that starts the server and initializes the application.

### config/

Contains configuration files.

#### config.go

Handles the loading and management of configuration settings.

#### settings.go

Contains specific configuration settings for different environments or services.

### controllers/

Handles the application logic for different routes.

#### home_controller.go

Manages the logic for the home page and related routes.

#### user_controller.go

Manages user-related routes and functionality, such as user registration and login.

### models/

Defines data models representing entities in the application.

#### user.go

Defines the `User` model and its associated methods.

#### product.go

Defines the `Product` model and its associated methods.