This commit is contained in:
vipg
2025-12-26 17:32:02 +08:00
parent 9ead420a8a
commit 39e33007d2
2 changed files with 97 additions and 2 deletions

View File

@@ -0,0 +1,69 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
create_src_mod.py - 更新go.mod文件内容
"""
import os
import sys
def update_go_mod(table_name):
"""更新指定服务目录下的go.mod文件内容"""
# 获取项目根目录
project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
services_dir = os.path.join(project_root, 'services')
# 服务目录路径
service_dir = os.path.join(services_dir, table_name)
go_mod_path = os.path.join(service_dir, 'src', 'go.mod')
print(f"🚀 开始更新go.mod: {go_mod_path}")
# go.mod内容模板将xxxxx替换为table_name
go_mod_content = f"""module {table_name}
go 1.25.0
require (
)
require (
)
"""
try:
# 检查文件是否存在
if not os.path.exists(go_mod_path):
print(f"❌ go.mod文件不存在: {go_mod_path}")
return False
# 清空文件内容并写入新内容
with open(go_mod_path, 'w', encoding='utf-8') as f:
f.write(go_mod_content)
print(f"✅ 成功更新go.mod: {go_mod_path}")
print(f"📋 模块名: {table_name}")
return True
except Exception as e:
print(f"❌ 更新go.mod时出错: {e}")
return False
if __name__ == "__main__":
# 从环境变量获取表名
table_name = os.environ.get('TABLE_NAME')
if not table_name:
print("❌ 错误: 未设置 TABLE_NAME 环境变量")
sys.exit(1)
print(f"📋 接收到的表名: {table_name}")
success = update_go_mod(table_name)
if success:
sys.exit(0)
else:
sys.exit(1)