feat: 初始化项目结构

This commit is contained in:
wood911010 committed 2025-07-29 23:37:55 +08:00
1 parent 5082bfcb8f
commit 5f39264dbc
11 files changed
+362 -1

No files matched your search

+23
View File
@@ -0,0 +1,23 @@
# Multi-stage build
FROM node:18-alpine AS frontend-builder
WORKDIR /app/frontend
COPY frontend/package*.json ./
RUN npm install
COPY frontend/ ./
RUN npm run build
FROM golang:1.23-alpine AS backend-builder
WORKDIR /app/backend
COPY backend/go.mod backend/go.sum ./
RUN go mod download
COPY backend/ ./
RUN go build -o license-manager cmd/main.go
FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /app
COPY --from=backend-builder /app/backend/license-manager .
COPY --from=frontend-builder /app/frontend/dist ./static
COPY backend/configs/config.example.yaml ./config.yaml
EXPOSE 8080
CMD ["./license-manager"]
+37
View File
@@ -0,0 +1,37 @@
package main
import (
"log"
"net/http"
"github.com/gorilla/mux"
"github.com/sirupsen/logrus"
)
func main() {
logrus.Info("Starting License Manager Server...")
r := mux.NewRouter()
// API routes
api := r.PathPrefix("/api").Subrouter()
api.HandleFunc("/validate", validateHandler).Methods("POST")
api.HandleFunc("/activate", activateHandler).Methods("POST")
api.HandleFunc("/heartbeat", heartbeatHandler).Methods("POST")
api.HandleFunc("/license/{code}", getLicenseHandler).Methods("GET")
api.HandleFunc("/customers", getCustomersHandler).Methods("GET")
// Tools route
r.HandleFunc("/tools/{tool}", getToolHandler).Methods("GET")
logrus.Info("Server starting on :8080")
log.Fatal(http.ListenAndServe(":8080", r))
}
// Placeholder handlers
func validateHandler(w http.ResponseWriter, r *http.Request) {}
func activateHandler(w http.ResponseWriter, r *http.Request) {}
func heartbeatHandler(w http.ResponseWriter, r *http.Request) {}
func getLicenseHandler(w http.ResponseWriter, r *http.Request) {}
func getCustomersHandler(w http.ResponseWriter, r *http.Request) {}
func getToolHandler(w http.ResponseWriter, r *http.Request) {}
+20
View File
@@ -0,0 +1,20 @@
server:
port: 8080
host: "0.0.0.0"
database:
type: "postgres" # postgres or mysql
host: "localhost"
port: 5432
name: "license_manager"
user: "postgres"
password: "password"
ssl_mode: "disable"
security:
hmac_secret: "your-secret-key-here"
jwt_secret: "your-jwt-secret-here"
logging:
level: "info" # debug, info, warn, error
format: "json" # json or text
+9
View File
@@ -0,0 +1,9 @@
module license-manager
go 1.23
require (
github.com/gorilla/mux v1.8.0
github.com/sirupsen/logrus v1.9.0
gopkg.in/yaml.v3 v3.0.1
)
+151
View File
@@ -0,0 +1,151 @@
# 软件授权管理平台 - 目录结构说明
## 项目整体结构
```
license-manager/
├── README.md # 项目说明文档
├── LICENSE # 开源许可证
├── .gitignore # Git忽略文件配置
├── Dockerfile # Docker构建配置
├── docker-compose.yml # Docker编排配置
├── Makefile # 构建自动化脚本
│
├── backend/ # 后端服务目录
├── frontend/ # 前端应用目录
├── docs/ # 项目文档目录
├── scripts/ # 项目级脚本目录
├── tests/ # 端到端测试目录
└── bin/ # 编译产物目录
```
## 后端目录 (backend/)
```
backend/
├── cmd/ # 应用程序入口
│ └── main.go # 主程序入口文件
├── internal/ # 内部包(不对外暴露)
│ ├── api/ # API路由和控制器
│ ├── config/ # 配置管理
│ ├── models/ # 数据模型定义
│ ├── service/ # 业务逻辑层
│ ├── repository/ # 数据访问层
│ └── middleware/ # HTTP中间件
├── pkg/ # 可重用的公共包
├── configs/ # 配置文件目录
│ ├── config.yaml # 生产环境配置
│ └── config.example.yaml # 配置模板文件
├── migrations/ # 数据库迁移脚本
├── scripts/ # 后端专用脚本
├── tools/ # 硬件信息获取工具
├── go.mod # Go模块依赖
└── go.sum # Go依赖校验
```
## 前端目录 (frontend/)
```
frontend/
├── public/ # 静态资源目录
│ ├── index.html # HTML模板
│ └── favicon.ico # 网站图标
├── src/ # 前端源代码
│ ├── components/ # Vue组件
│ ├── views/ # 页面视图
│ ├── router/ # 路由配置
│ ├── store/ # 状态管理(Pinia)
│ ├── api/ # API请求封装
│ ├── utils/ # 工具函数
│ ├── assets/ # 资源文件
│ └── main.js # 应用入口
├── package.json # NPM依赖配置
├── vite.config.js # Vite构建配置
└── .env.example # 环境变量模板
```
## 文档目录 (docs/)
```
docs/
├── api/ # API接口文档
├── architecture/ # 架构设计文档
│ ├── 需求说明书.md # 项目需求规格
│ └── 目录结构说明.md # 本文档
└── deployment/ # 部署相关文档
```
## 脚本目录 (scripts/)
```
scripts/
├── build.sh # 项目构建脚本
├── deploy.sh # 部署脚本
└── dev.sh # 开发环境启动脚本
```
## 测试目录 (tests/)
```
tests/
├── integration/ # 集成测试
└── e2e/ # 端到端测试
```
## 编译产物目录 (bin/)
```
bin/
└── license-manager # 编译后的可执行文件
```
## 目录设计原则
### 1. 前后端分离
- backend/ 和 frontend/ 完全独立,可以分别开发和部署
- 各自拥有独立的依赖管理和构建配置
### 2. 职责清晰
- internal/ 存放内部业务逻辑,不对外暴露
- pkg/ 存放可重用的公共代码
- cmd/ 只包含应用启动代码
### 3. 标准化
- 遵循Go项目标准布局
- 遵循Vue.js项目最佳实践
- 符合开源项目规范
### 4. 易于维护
- 配置文件集中管理
- 脚本统一放置
- 文档结构清晰
## 开发流程
### 开发环境启动
```bash
# 启动开发环境(前后端同时启动)
./scripts/dev.sh
```
### 项目构建
```bash
# 构建整个项目
./scripts/build.sh
```
### Docker部署
```bash
# 构建Docker镜像
docker build -t license-manager .
# 运行容器
docker run -p 8080:8080 license-manager
```
## 注意事项
1. 权限管理:确保脚本文件具有执行权限
2. 配置文件:不要提交包含敏感信息的配置文件
3. 依赖管理:定期更新依赖版本,注意安全漏洞
4. 代码规范:前后端代码都要遵循各自的编码规范
@@ -95,7 +95,7 @@
- **架构模式**:B/S架构 - **架构模式**:B/S架构
- **后端技术**:Go 1.23+,Gorilla Mux路由,Logrus日志 - **后端技术**:Go 1.23+,Gorilla Mux路由,Logrus日志
- **数据库**:PostgreSQL 12+,mysql12+ - **数据库**:PostgreSQL 12+,mysql12+
- **前端**:x - **前端**:Vue.js 3+ 配合Vite,响应式UI组件
- **配置**:YAML格式配置文件 - **配置**:YAML格式配置文件
### 4.2 部署要求 ### 4.2 部署要求
@@ -132,5 +132,34 @@
- 统一错误响应格式 - 统一错误响应格式
- 支持数据分页和筛选 - 支持数据分页和筛选
## 7. 项目交付物
### 7.1 软件交付
- 完整源代码(前后端)
- 编译后的可执行文件
- Docker镜像文件
- 数据库初始化脚本
### 7.2 文档交付
- 部署安装文档
- API接口文档
- 用户操作手册
- 系统架构文档
### 7.3 工具交付
- 硬件信息获取工具(Windows/Linux)
- 客户端SDK示例
- 配置文件模板
## 8. 开发计划
### 8.1 开发阶段
1. **架构设计**(1周):技术选型、数据库设计、API设计
2. **核心功能**(3周):客户管理、授权生成、验证API
3. **Web界面**(2周):前端页面开发、交互逻辑
4. **测试部署**(1周):功能测试、性能测试、部署验证
### 8.2 质量保证
- 单元测试覆盖率 > 80%
- 接口测试和性能测试
- 安全性测试和代码审查
+20
View File
@@ -0,0 +1,20 @@
{
"name": "license-manager-frontend",
"version": "1.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"dependencies": {
"vue": "^3.4.0",
"vue-router": "^4.2.0",
"pinia": "^2.1.0",
"axios": "^1.6.0"
},
"devDependencies": {
"@vitejs/plugin-vue": "^5.0.0",
"vite": "^5.0.0"
}
}
+9
View File
@@ -0,0 +1,9 @@
import { createApp } from 'vue'
import { createPinia } from 'pinia'
import router from './router'
import App from './App.vue'
const app = createApp(App)
app.use(createPinia())
app.use(router)
app.mount('#app')
+15
View File
@@ -0,0 +1,15 @@
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
export default defineConfig({
plugins: [vue()],
server: {
port: 3000,
proxy: {
'/api': {
target: 'http://localhost:8080',
changeOrigin: true
}
}
}
})
+21
View File
@@ -0,0 +1,21 @@
#!/bin/bash
echo "Building License Manager..."
# Build backend
echo "Building backend..."
cd backend
go mod tidy
go build -o ../bin/license-manager cmd/main.go
cd ..
# Build frontend
echo "Building frontend..."
cd frontend
npm install
npm run build
cd ..
echo "Build completed successfully!"
echo "Backend binary: ./bin/license-manager"
echo "Frontend dist: ./frontend/dist"
+27
View File
@@ -0,0 +1,27 @@
#!/bin/bash
echo "Starting development environment..."
# Start backend in background
echo "Starting backend server..."
cd backend
go run cmd/main.go &
BACKEND_PID=$!
cd ..
# Start frontend
echo "Starting frontend server..."
cd frontend
npm run dev &
FRONTEND_PID=$!
cd ..
echo "Development servers started:"
echo "Backend: http://localhost:8080"
echo "Frontend: http://localhost:3000"
echo ""
echo "Press Ctrl+C to stop all servers"
# Wait for interrupt
trap "kill $BACKEND_PID $FRONTEND_PID; exit" INT
wait