Skip to content

yinjiaming666/goingo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

114 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Goingo

 ██████╗   ██████╗  ██╗ ███╗   ██╗  ██████╗   ██████╗
██╔════╝  ██╔═══██╗ ██║ ████╗  ██║ ██╔════╝  ██╔═══██╗
██║  ███╗ ██║   ██║ ██║ ██╔██╗ ██║ ██║  ███╗ ██║   ██║
██║   ██║ ██║   ██║ ██║ ██║╚██╗██║ ██║   ██║ ██║   ██║
╚██████╔╝ ╚██████╔╝ ██║ ██║ ╚████║ ╚██████╔╝ ╚██████╔╝
 ╚═════╝   ╚═════╝  ╚═╝ ╚═╝  ╚═══╝  ╚═════╝   ╚═════╝

A Go API framework built on Gin + Gorm, with JWT auth, Redis, and Beanstalkd message queue.

中文文档

Tech Stack

Category Library
Router / Middleware Gin
ORM Gorm
Config Viper
Auth golang-jwt/jwt/v5
Cache go-redis
Message Queue go-beanstalk

Project Structure

├── config                  // Config files (ini)
│   ├── dev.ini             // Development
│   ├── prod.ini            // Production
│   └── deploy.ini          // Deploy settings
├── deploy                  // Deployment scripts
│   ├── deploy.go
│   ├── deploy.sh
│   └── run.sh
├── internal
│   ├── callback            // Callback registration (queue, etc.)
│   ├── controller          // Controllers
│   │   ├── admin           // Admin APIs
│   │   └── index           // Public APIs
│   ├── global              // Global variables
│   ├── logic               // Business logic
│   ├── middleware           // Middleware (CORS, auth, error recovery, IP filter)
│   ├── model               // Data models
│   └── router              // Route registration
├── tools                   // Shared utilities
│   ├── beanstalkd          // Message queue (producer / consumer / message / callback)
│   ├── config              // Config reader
│   ├── conv                // Type conversion
│   ├── http_client         // HTTP client
│   ├── jwt                 // JWT helpers
│   ├── key_utils           // Key utilities
│   ├── logger              // Logging
│   ├── queue               // Queue abstraction (legacy)
│   ├── random              // Random utilities
│   ├── resp                // Unified response
│   └── utils.go
├── main.go                 // API server entry point
└── beanstalkd_consumer.go  // Queue consumer entry point

Quick Start

# Run in development mode
go run main.go -mode=dev

# Run in production mode
go run main.go -mode=prod

# Initialize database tables
go run main.go -mode=dev -initDb=true

# Start queue consumer (standalone process)
go run beanstalkd_consumer.go -mode=dev

Configuration

Config files are in config/, selected via the -mode flag.

[server]
port = 8081
name = goingo
version = v1

[mysql]
ip = 127.0.0.1
port = 3306
username = root
password = root
db_name = goingo

[redis]
ip = 127.0.0.1
port = 6379

[beanstalkd]
ip = 127.0.0.1
port = 11300
consumer = 4

API Routes

All routes are prefixed with /{version} (default /v1):

Prefix Module Middleware
/v1/api/index Public APIs CORS, error recovery
/v1/api/admin Admin APIs CORS, error recovery, JWT auth, IP filtering

Message Queue

Beanstalkd-based queue with immediate and delayed delivery. Producer and consumer run in separate processes.

Producing Messages

import (
    "app/tools/beanstalkd/message"
    "app/tools/beanstalkd/producer"
    "time"
)

msg := &message.Message{
    M:    message.MHandelMoney,
    Data: `{"uid": 123, "num": 100.5, "logType": 1}`,
}

// Immediate delivery
id, err := producer.Instance.Push(msg, 0)

// Delayed delivery (60 seconds)
id, err := producer.Instance.Push(msg, 60*time.Second)

Consuming Messages

The consumer runs as a standalone process with built-in auto-reconnect:

import (
    "app/tools/beanstalkd/consumer"
    "app/tools/beanstalkd/message"
    "encoding/json"
)

consumer.Instance.SetCallback(func(msg *message.Message) {
    switch msg.M {
    case message.MHandelMoney:
        bizData := &message.HandelMoneyMsg{}
        if err := json.Unmarshal([]byte(msg.Data), bizData); err != nil {
            consumer.Instance.HandelJob(msg.JobId, "delete")
            return
        }
        // Process business logic...
        consumer.Instance.HandelJob(msg.JobId, "delete")
    }
})

consumerNumber := 3
for i := 1; i <= consumerNumber; i++ {
    go func(index int) {
        consumer.Instance.ReserveLoop(index)
    }(i)
}
select {} // Block main process

Deployment

cd deploy && go run deploy.go

About

A development framework based on Gin + Gorm integration for quickly building API services

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors