Files
ssq-desk/docs/01-规范/02-接口规范.md
2026-01-14 14:17:38 +08:00

54 lines
1009 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Wails 绑定规范
## 1. 概述
Wails 通过 context 绑定 Go 方法供前端调用,无需 HTTP API。
## 2. Go 后端绑定
### 2.1 结构体定义
```go
type App struct {
ctx context.Context
}
func NewApp() *App {
return &App{}
}
```
### 2.2 方法绑定
- 导出方法(首字母大写)自动绑定
- 方法参数不超过3个超过时使用结构体
- 返回错误统一使用 `error` 类型
### 2.3 命名规范
- 查询:`GetXxx()``ListXxx()`
- 新增:`CreateXxx()``SaveXxx()`
- 更新:`UpdateXxx()`
- 删除:`DeleteXxx()`
## 3. 前端调用
### 3.1 调用方式
```typescript
// 导入绑定的方法
import { GetXxx, SaveXxx } from '@/wailsjs/go/main/App'
// 调用
const data = await GetXxx()
```
### 3.2 错误处理
- 统一使用 try-catch 处理
- 错误信息展示给用户
## 4. 参数规范
- 简单参数直接传递
- 复杂参数使用结构体/对象
- 字段命名使用小驼峰
---
> 文档维护者JueChen
> 创建时间2026-01-07