add
This commit is contained in:
85
create/create_src.py
Normal file
85
create/create_src.py
Normal file
@@ -0,0 +1,85 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
create_src.py - 在services目录下创建服务文件夹和文件结构
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
def create_service_structure(table_name):
|
||||
"""创建服务文件夹结构"""
|
||||
|
||||
# 获取项目根目录
|
||||
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)
|
||||
|
||||
print(f"🚀 开始创建服务结构: {table_name}")
|
||||
print(f"📁 目标目录: {service_dir}")
|
||||
|
||||
try:
|
||||
# 创建主目录
|
||||
os.makedirs(service_dir, exist_ok=True)
|
||||
print(f"✅ 创建主目录: {service_dir}")
|
||||
|
||||
# 创建子目录
|
||||
subdirs = ['src', 'src/crud', 'src/infra', 'src/model']
|
||||
for subdir in subdirs:
|
||||
dir_path = os.path.join(service_dir, subdir)
|
||||
os.makedirs(dir_path, exist_ok=True)
|
||||
print(f"✅ 创建子目录: {dir_path}")
|
||||
|
||||
# 定义要创建的文件列表
|
||||
files_to_create = [
|
||||
'dev.sh',
|
||||
'README.md',
|
||||
'src/Dockerfile',
|
||||
'src/go.mod',
|
||||
'src/go.sum',
|
||||
'src/main.go',
|
||||
'src/crud/create.go',
|
||||
'src/crud/read.go',
|
||||
'src/crud/update.go',
|
||||
'src/crud/delete.go',
|
||||
'src/infra/launch.go',
|
||||
'src/infra/logger.go',
|
||||
'src/infra/postgres.go',
|
||||
'src/model/payload.go'
|
||||
]
|
||||
|
||||
# 创建所有文件
|
||||
for file_path in files_to_create:
|
||||
full_path = os.path.join(service_dir, file_path)
|
||||
os.makedirs(os.path.dirname(full_path), exist_ok=True) # 确保目录存在
|
||||
|
||||
# 创建空文件
|
||||
with open(full_path, 'w', encoding='utf-8') as f:
|
||||
f.write('') # 创建空文件
|
||||
|
||||
print(f"✅ 创建文件: {full_path}")
|
||||
|
||||
print(f"🎉 服务结构创建完成: {table_name}")
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ 创建服务结构时出错: {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 = create_service_structure(table_name)
|
||||
|
||||
if success:
|
||||
sys.exit(0)
|
||||
else:
|
||||
sys.exit(1)
|
||||
Reference in New Issue
Block a user