add
This commit is contained in:
@@ -15,10 +15,10 @@ log_error() {
|
||||
}
|
||||
|
||||
# 定义配置常量(等号两侧无空格!集中管理,便于修改)
|
||||
IMAGE_NAME="futures-trading-record-api"
|
||||
IMAGE_NAME="futures-trade-record-api"
|
||||
IMAGE_TAG="1.0.0"
|
||||
FULL_IMAGE="${IMAGE_NAME}:${IMAGE_TAG}"
|
||||
COMPOSE_PROJECT_NAME="futures_trading_record_service"
|
||||
COMPOSE_PROJECT_NAME="futures_trade_record_service"
|
||||
DOCKER_COMPOSE_FILE="./docker-compose.yaml"
|
||||
SRC_DIR="./src"
|
||||
DOCKERFILE_PATH="${SRC_DIR}/Dockerfile"
|
||||
|
||||
@@ -1 +1 @@
|
||||
docker run -itd --name go_futures_trading_record_dev -v $(pwd)/src:/app -p 20010:80 golang:1.25.0-alpine3.22
|
||||
docker run -itd --name go_futures_trade_record_dev -v $(pwd)/src:/app -p 20010:80 golang:1.25.0-alpine3.22
|
||||
@@ -1,7 +1,7 @@
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:17.4-alpine
|
||||
container_name: futures_trading_record_db
|
||||
container_name: futures_trade_record_db
|
||||
restart: always
|
||||
ports:
|
||||
- 20011:5432
|
||||
@@ -13,21 +13,21 @@ services:
|
||||
POSTGRES_DB: ${DB_NAME}
|
||||
TZ: ${TZ}
|
||||
volumes:
|
||||
- ./shared_data/futures_trading_record_db:/var/lib/postgresql/data
|
||||
- ./shared_data/futures_trade_record_db:/var/lib/postgresql/data
|
||||
- ./sql:/docker-entrypoint-initdb.d
|
||||
- ./scripts:/scripts
|
||||
networks:
|
||||
- futures-trading-record-network
|
||||
futures_trading_record:
|
||||
- futures-trade-record-network
|
||||
futures_trade_record:
|
||||
image: golang:1.25.0-alpine3.22
|
||||
container_name: futures_trading_record_api
|
||||
container_name: futures_trade_record_api
|
||||
restart: always
|
||||
ports:
|
||||
- 20010:80
|
||||
depends_on:
|
||||
- postgres
|
||||
networks:
|
||||
- futures-trading-record-network
|
||||
- futures-trade-record-network
|
||||
environment:
|
||||
DB_HOST: postgres
|
||||
DB_PORT: ${DB_PORT}
|
||||
@@ -39,6 +39,6 @@ services:
|
||||
- ./src:/app
|
||||
command: sh -c "cd /app && go mod tidy && go run main.go"
|
||||
networks:
|
||||
futures-trading-record-network:
|
||||
futures-trade-record-network:
|
||||
driver: bridge
|
||||
volumes: {}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:17.4-alpine
|
||||
container_name: futures_trading_record_db
|
||||
container_name: futures_trade_record_db
|
||||
restart: always
|
||||
ports:
|
||||
- 20011:5432
|
||||
@@ -13,21 +13,21 @@ services:
|
||||
POSTGRES_DB: ${DB_NAME}
|
||||
TZ: ${TZ}
|
||||
volumes:
|
||||
- ./shared_data/futures_trading_record_db:/var/lib/postgresql/data
|
||||
- ./shared_data/futures_trade_record_db:/var/lib/postgresql/data
|
||||
- ./sql:/docker-entrypoint-initdb.d
|
||||
- ./scripts:/scripts
|
||||
networks:
|
||||
- futures-trading-record-network
|
||||
futures_trading_record:
|
||||
image: futures-trading-record-api:1.0.0
|
||||
container_name: futures_trading_record_api
|
||||
- futures-trade-record-network
|
||||
futures_trade_record:
|
||||
image: futures-trade-record-api:1.0.0
|
||||
container_name: futures_trade_record_api
|
||||
restart: always
|
||||
ports:
|
||||
- 20010:80
|
||||
depends_on:
|
||||
- postgres
|
||||
networks:
|
||||
- futures-trading-record-network
|
||||
- futures-trade-record-network
|
||||
environment:
|
||||
DB_HOST: postgres
|
||||
DB_PORT: ${DB_PORT}
|
||||
@@ -39,6 +39,6 @@ services:
|
||||
# 挂载添加日志目录挂载,将容器内日志日志目录映射到宿主机的 ./logs 目录
|
||||
- ./logs:/app/logs # 假设代码中日志存储路径为 /app/logs
|
||||
networks:
|
||||
futures-trading-record-network:
|
||||
futures-trade-record-network:
|
||||
driver: bridge
|
||||
volumes: {}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
-- 切换到目标数据库
|
||||
\c postgres;
|
||||
|
||||
CREATE OR REPLACE FUNCTION update_futures_trading_record_modified_column()
|
||||
CREATE OR REPLACE FUNCTION update_futures_trade_record_modified_column()
|
||||
RETURNS TRIGGER AS $$
|
||||
BEGIN
|
||||
NEW.updated_at = CURRENT_TIMESTAMP;
|
||||
@@ -11,20 +11,20 @@ $$ LANGUAGE plpgsql VOLATILE;
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'futures_trading_record') THEN
|
||||
CREATE TABLE "futures_trading_record" ( -- futures_trading_record是关键字,用双引号包裹
|
||||
IF NOT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'futures_trade_record') THEN
|
||||
CREATE TABLE "futures_trade_record" ( -- futures_trade_record是关键字,用双引号包裹
|
||||
id UUID DEFAULT gen_random_uuid_v7() PRIMARY KEY NOT NULL,
|
||||
deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
CREATE TRIGGER update_futures_trading_record_updated_at
|
||||
BEFORE UPDATE ON "futures_trading_record"
|
||||
CREATE TRIGGER update_futures_trade_record_updated_at
|
||||
BEFORE UPDATE ON "futures_trade_record"
|
||||
FOR EACH ROW
|
||||
EXECUTE FUNCTION update_futures_trading_record_modified_column();
|
||||
EXECUTE FUNCTION update_futures_trade_record_modified_column();
|
||||
|
||||
RAISE NOTICE 'Created futures_trading_record table and trigger';
|
||||
RAISE NOTICE 'Created futures_trade_record table and trigger';
|
||||
ELSE
|
||||
RAISE NOTICE 'futures_trading_record table already exists';
|
||||
RAISE NOTICE 'futures_trade_record table already exists';
|
||||
END IF;
|
||||
END $$;
|
||||
@@ -14,7 +14,7 @@ BEGIN
|
||||
IF NOT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'code') THEN
|
||||
CREATE TABLE code (
|
||||
id UUID DEFAULT gen_random_uuid_v7() PRIMARY KEY NOT NULL,
|
||||
futures_trading_record_id UUID NOT NULL,
|
||||
futures_trade_record_id UUID NOT NULL,
|
||||
code VARCHAR NOT NULL,
|
||||
deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
@@ -7,30 +7,30 @@ BEGIN
|
||||
-- 检查视图是否已存在
|
||||
SELECT EXISTS (
|
||||
SELECT 1 FROM information_schema.views
|
||||
WHERE table_name = 'futures_trading_record_info_view'
|
||||
WHERE table_name = 'futures_trade_record_info_view'
|
||||
) INTO view_exists;
|
||||
|
||||
-- 创建或更新视图
|
||||
CREATE OR REPLACE VIEW futures_trading_record_info_view AS
|
||||
CREATE OR REPLACE VIEW futures_trade_record_info_view AS
|
||||
SELECT
|
||||
u.id AS futures_trading_record_id,
|
||||
u.id AS futures_trade_record_id,
|
||||
n.name AS name,
|
||||
c.code AS code,
|
||||
u.deleted AS deleted
|
||||
FROM
|
||||
"futures_trading_record" u
|
||||
"futures_trade_record" u
|
||||
JOIN
|
||||
name n ON u.id = n.futures_trading_record_id
|
||||
name n ON u.id = n.futures_trade_record_id
|
||||
JOIN
|
||||
code c ON u.id = c.futures_trading_record_id
|
||||
code c ON u.id = c.futures_trade_record_id
|
||||
WHERE
|
||||
u.deleted = FALSE;
|
||||
|
||||
-- 根据视图是否已存在输出不同提示
|
||||
IF view_exists THEN
|
||||
RAISE NOTICE '视图 futures_trading_record_info_view 已更新';
|
||||
RAISE NOTICE '视图 futures_trade_record_info_view 已更新';
|
||||
ELSE
|
||||
RAISE NOTICE '视图 futures_trading_record_info_view 已创建';
|
||||
RAISE NOTICE '视图 futures_trade_record_info_view 已创建';
|
||||
END IF;
|
||||
EXCEPTION
|
||||
WHEN OTHERS THEN
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
module futures_trading_record
|
||||
module futures_trade_record
|
||||
|
||||
go 1.25.0
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"futures_trading_record/db" // 数据库相关操作包
|
||||
"futures_trading_record/logger" // 日志工具包
|
||||
"futures_trading_record/logic" // 业务逻辑处理包
|
||||
"futures_trade_record/db" // 数据库相关操作包
|
||||
"futures_trade_record/logger" // 日志工具包
|
||||
"futures_trade_record/logic" // 业务逻辑处理包
|
||||
|
||||
"github.com/gin-contrib/cors"
|
||||
"github.com/gin-gonic/gin" // Gin框架,用于构建HTTP服务
|
||||
@@ -50,8 +50,8 @@ func main() {
|
||||
zap.L().Info("✅ 配置跨域中间件完成")
|
||||
|
||||
// 注册创建国家的接口,POST请求,由logic.CreateHandler处理
|
||||
// r.POST("/futurestradingrecord/create", logic.CreateHandler)
|
||||
// zap.L().Info("✅ 创建接口注册完成: POST /futurestradingrecord/create")
|
||||
// r.POST("/futurestraderecord/create", logic.CreateHandler)
|
||||
// zap.L().Info("✅ 创建接口注册完成: POST /futurestraderecord/create")
|
||||
|
||||
// 记录服务启动日志,监听80端口
|
||||
zap.L().Info("✅ 服务启动在80端口")
|
||||
|
||||
Reference in New Issue
Block a user