Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build_backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.25"
go-version: "1.26"
check-latest: true

- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.25"
go-version: "1.26"
check-latest: true

# download Go modules
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/copilot-setup-steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.25"
go-version: "1.26"
check-latest: true

- name: Install dependencies
Expand Down
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[中文](./README_zh.md)

[![License: Apache2.0](https://img.shields.io/badge/License-Apache2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![Go Version](https://img.shields.io/badge/Go-1.25.5-blue.svg)](https://golang.org/)
[![Go Version](https://img.shields.io/badge/Go-1.26-blue.svg)](https://golang.org/)
[![Next.js](https://img.shields.io/badge/Next.js-16-black.svg)](https://nextjs.org/)
[![React](https://img.shields.io/badge/React-19-blue.svg)](https://reactjs.org/)

Expand Down Expand Up @@ -52,7 +52,7 @@ LINUX DO Credit is a credit service platform built for the Linux Do community, a
## 🛠️ Tech Stack

### Backend
- **[Go 1.25.5](https://go.dev/doc)** - Primary development language
- **[Go 1.26](https://go.dev/doc)** - Primary development language
- **[GIN](https://github.com/gin-gonic/gin)** - Web Framework
- **[GORM](https://github.com/go-gorm/gorm)** - ORM Framework
- **[Redis](https://github.com/redis/redis)** - Cache and session store
Expand All @@ -70,7 +70,7 @@ LINUX DO Credit is a credit service platform built for the Linux Do community, a

## 📋 Requirements

- **Go** >= 1.25.5
- **Go** >= 1.26
- **Node.js** >= 18.0
- **PostgreSQL** >= 18
- **Redis** >= 6.0
Expand Down Expand Up @@ -136,7 +136,8 @@ pnpm dev

- **Frontend Interface**: http://localhost:3000
- **API Documentation**: http://localhost:8000/swagger/index.html
- **Health Check**: http://localhost:8000/api/health
- **Health Check**: http://localhost:8000/api/v1/health
- **Readiness Check**: http://localhost:8000/api/v1/ready

## ⚙️ Configuration

Expand All @@ -145,6 +146,8 @@ pnpm dev
| Option | Description | Example |
|--------|-------------|---------|
| `app.addr` | Backend service listening address | `:8000` |
| `worker.port` | Worker probe port | `8001` |
| `scheduler.port` | Scheduler probe port | `8002` |
| `oauth2.client_id` | OAuth2 Client ID | `your_client_id` |
| `database.host` | PostgreSQL database host | `127.0.0.1` |
| `database.port` | PostgreSQL database port | `5432` |
Expand Down
11 changes: 7 additions & 4 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[English](./README.md)

[![License: Apache2.0](https://img.shields.io/badge/License-Apache2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![Go Version](https://img.shields.io/badge/Go-1.25.5-blue.svg)](https://golang.org/)
[![Go Version](https://img.shields.io/badge/Go-1.26-blue.svg)](https://golang.org/)
[![Next.js](https://img.shields.io/badge/Next.js-16-black.svg)](https://nextjs.org/)
[![React](https://img.shields.io/badge/React-19-blue.svg)](https://reactjs.org/)

Expand Down Expand Up @@ -52,7 +52,7 @@ LINUX DO Credit 是一个为 Linux Do 社区打造的积分服务平台,旨在
## 🛠️ 技术栈

### 后端
- **[Go 1.25.5](https://go.dev/doc)** - 主要开发语言
- **[Go 1.26](https://go.dev/doc)** - 主要开发语言
- **[GIN](https://github.com/gin-gonic/gin)** - Web 框架
- **[GORM](https://github.com/go-gorm/gorm)** - ORM 框架
- **[Redis](https://github.com/redis/redis)** - 缓存和会话存储
Expand All @@ -70,7 +70,7 @@ LINUX DO Credit 是一个为 Linux Do 社区打造的积分服务平台,旨在

## 📋 环境要求

- **Go** >= 1.25.5
- **Go** >= 1.26
- **Node.js** >= 18.0
- **PostgreSQL** >= 18
- **Redis** >= 6.0
Expand Down Expand Up @@ -136,7 +136,8 @@ pnpm dev

- **前端界面**: http://localhost:3000
- **API 文档**: http://localhost:8000/swagger/index.html
- **健康检查**: http://localhost:8000/api/health
- **健康检查**: http://localhost:8000/api/v1/health
- **就绪检查**: http://localhost:8000/api/v1/ready

## ⚙️ 配置说明

Expand All @@ -145,6 +146,8 @@ pnpm dev
| 配置项 | 说明 | 示例 |
|--------|------|------|
| `app.addr` | 后端服务监听地址 | `:8000` |
| `worker.port` | Worker 探针端口 | `8001` |
| `scheduler.port` | Scheduler 探针端口 | `8002` |
| `oauth2.client_id` | OAuth2 客户端 ID | `your_client_id` |
| `database.host` | PostgreSQL 数据库地址 | `127.0.0.1` |
| `database.port` | PostgreSQL 数据库端口 | `5432` |
Expand Down
2 changes: 2 additions & 0 deletions config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ log:

# Scheduler
scheduler:
port: 8002 # scheduler probe port
update_user_gamification_scores_task_cron: "0 2 * * *"
dispute_auto_refund_dispatch_interval_seconds: 3
auto_refund_expired_disputes_task_cron: "0 0 * * *"
Expand All @@ -115,6 +116,7 @@ scheduler:

# Worker
worker:
port: 8001 # worker probe port
concurrency: 20
strict_priority: false
queues:
Expand Down
24 changes: 24 additions & 0 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1443,6 +1443,30 @@ const docTemplate = `{
}
}
},
"/api/v1/ready": {
"get": {
"produces": [
"application/json"
],
"tags": [
"health"
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
}
}
}
},
"/api/v1/redenvelope/claim": {
"post": {
"consumes": [
Expand Down
24 changes: 24 additions & 0 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1434,6 +1434,30 @@
}
}
},
"/api/v1/ready": {
"get": {
"produces": [
"application/json"
],
"tags": [
"health"
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
}
}
}
},
"/api/v1/redenvelope/claim": {
"post": {
"consumes": [
Expand Down
15 changes: 15 additions & 0 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1438,6 +1438,21 @@ paths:
$ref: '#/definitions/util.ResponseAny'
tags:
- payment
/api/v1/ready:
get:
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/util.ResponseAny'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/util.ResponseAny'
tags:
- health
/api/v1/redenvelope/{id}:
get:
parameters:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/linux-do/credit

go 1.25.5
go 1.26

require (
github.com/ClickHouse/clickhouse-go/v2 v2.37.2
Expand Down
55 changes: 55 additions & 0 deletions internal/apps/health/routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import (
"net/http"

"github.com/gin-gonic/gin"
"github.com/linux-do/credit/internal/config"
"github.com/linux-do/credit/internal/db"
"github.com/linux-do/credit/internal/logger"
"github.com/linux-do/credit/internal/util"
)

Expand All @@ -31,3 +34,55 @@ import (
func Health(c *gin.Context) {
c.JSON(http.StatusOK, util.OKNil())
}

// Ready godoc
// @Tags health
// @Produce json
// @Success 200 {object} util.ResponseAny
// @Failure 500 {object} util.ResponseAny
// @Router /api/v1/ready [get]
func Ready(c *gin.Context) {
ctx := c.Request.Context()

if config.Config.Database.Enabled {
sqlDB, err := db.DB(ctx).DB()
if err != nil {
logger.ErrorF(ctx, "[Ready] PostgreSQL check failed: %v", err)
c.AbortWithStatusJSON(http.StatusInternalServerError, util.Err("PostgreSQL not ready"))
return
}
if err := sqlDB.PingContext(ctx); err != nil {
logger.ErrorF(ctx, "[Ready] PostgreSQL check failed: %v", err)
c.AbortWithStatusJSON(http.StatusInternalServerError, util.Err("PostgreSQL not ready"))
return
}
}

if config.Config.Redis.Enabled {
if db.Redis == nil {
logger.ErrorF(ctx, "[Ready] Redis check failed: client is nil")
c.AbortWithStatusJSON(http.StatusInternalServerError, util.Err("Redis not ready"))
return
}
if err := db.Redis.Ping(ctx).Err(); err != nil {
logger.ErrorF(ctx, "[Ready] Redis check failed: %v", err)
c.AbortWithStatusJSON(http.StatusInternalServerError, util.Err("Redis not ready"))
return
}
}

if config.Config.ClickHouse.Enabled {
if db.ChConn == nil {
logger.ErrorF(ctx, "[Ready] ClickHouse check failed: client is nil")
c.AbortWithStatusJSON(http.StatusInternalServerError, util.Err("ClickHouse not ready"))
return
}
if err := db.ChConn.Ping(ctx); err != nil {
logger.ErrorF(ctx, "[Ready] ClickHouse check failed: %v", err)
c.AbortWithStatusJSON(http.StatusInternalServerError, util.Err("ClickHouse not ready"))
return
}
}

c.JSON(http.StatusOK, util.OKNil())
}
5 changes: 5 additions & 0 deletions internal/cmd/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package cmd
import (
"log"

"github.com/linux-do/credit/internal/config"
"github.com/linux-do/credit/internal/probe"
"github.com/linux-do/credit/internal/task/scheduler"

"github.com/spf13/cobra"
Expand All @@ -29,6 +31,9 @@ var schedulerCmd = &cobra.Command{
Short: "credit Scheduler",
Run: func(cmd *cobra.Command, args []string) {
log.Println("[Scheduler] 启动定时任务调度服务")
if err := probe.Start(config.Config.Scheduler.Port); err != nil {
log.Fatalf("[Scheduler] 启动探针服务失败: %v", err)
}
if err := scheduler.StartScheduler(); err != nil {
log.Fatalf("[调度器] 启动失败: %v", err)
}
Expand Down
5 changes: 5 additions & 0 deletions internal/cmd/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package cmd
import (
"log"

"github.com/linux-do/credit/internal/config"
"github.com/linux-do/credit/internal/probe"
"github.com/linux-do/credit/internal/task/worker"

"github.com/spf13/cobra"
Expand All @@ -29,6 +31,9 @@ var workerCmd = &cobra.Command{
Short: "credit Worker",
Run: func(cmd *cobra.Command, args []string) {
log.Println("[Worker] 启动任务处理服务")
if err := probe.Start(config.Config.Worker.Port); err != nil {
log.Fatalf("[Worker] 启动探针服务失败: %v", err)
}
if err := worker.StartWorker(); err != nil {
log.Fatalf("[工作器] 启动失败: %v", err)
}
Expand Down
2 changes: 2 additions & 0 deletions internal/config/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ type logConfig struct {

// schedulerConfig 定时任务配置
type schedulerConfig struct {
Port int `mapstructure:"port"`
UpdateUserGamificationScoresTaskCron string `mapstructure:"update_user_gamification_scores_task_cron"`
DisputeAutoRefundDispatchIntervalSeconds int `mapstructure:"dispute_auto_refund_dispatch_interval_seconds"`
AutoRefundExpiredDisputesTaskCron string `mapstructure:"auto_refund_expired_disputes_task_cron"`
Expand All @@ -158,6 +159,7 @@ type schedulerConfig struct {

// workerConfig 工作配置
type workerConfig struct {
Port int `mapstructure:"port"`
Concurrency int `mapstructure:"concurrency"`
StrictPriority bool `mapstructure:"strict_priority"`
Queues []QueueConfig `mapstructure:"queues"`
Expand Down
Loading
Loading