日志操作系统 API 文档
大约 2 分钟
日志操作系统 API 文档
概述
本文档基于 log_action.proto,描述日志操作的 gRPC 接口,包括创建操作日志与分页查询操作日志。
包信息
- 包名:
log_action - 语法版本:
proto3
通用消息类型
LogAction(操作日志)
| 字段 | 类型 | 说明 |
|---|---|---|
| id | string | 日志 ID |
| user_id | string | 用户 ID |
| user_name | string | 用户名 |
| operation_module | string | 操作模块 |
| operation_type | string | 操作类型 |
| operation_content | string | 操作描述 |
| operation_ip | string | 操作 IP |
| request_params | string | 请求参数 |
| response_params | string | 响应参数 |
| user_agent | string | 用户代理 |
| operation_time | string | 操作时间 |
服务接口
服务名:LogActionService
1. 创建操作日志 CreateLogAction
请求:
message CreateLogActionRequest {
string access_token = 1;
string user_id = 2;
string user_name = 3;
string operation_module = 4;
string operation_type = 5;
string operation_content = 6;
string operation_ip = 7;
string request_params = 8;
string response_params = 9;
string user_agent = 10;
}响应:
message CreateLogActionResponse {
string code = 1;
string message = 2;
}RPC:
rpc CreateLogAction(CreateLogActionRequest) returns (CreateLogActionResponse);2. 获取操作日志列表 GetLogActionList
请求:
message GetLogActionListRequest {
string access_token = 1;
string page = 2;
string size = 3;
string start_time = 4;
string end_time = 5;
string keywords = 6;
}响应:
message GetLogActionListResponse {
string code = 1;
string message = 2;
repeated LogAction items = 3;
int64 page = 4;
int64 size = 5;
int64 total = 6;
}RPC:
rpc GetLogActionList(GetLogActionListRequest) returns (GetLogActionListResponse);状态码说明
| 状态码 | 说明 |
|---|---|
| 200 | 成功 |
| 400 | 参数错误 |
| 401 | 未授权 |
| 403 | 权限不足 |
| 404 | 资源不存在 |
| 500 | 服务器内部错误 |
使用示例(Go)
以下示例仅演示调用方式,需替换实际
pb包路径和服务地址。
创建日志
conn, _ := grpc.Dial("localhost:50051", grpc.WithTransportCredentials(insecure.NewCredentials()))
defer conn.Close()
cli := pb.NewLogActionServiceClient(conn)
_, _ = cli.CreateLogAction(context.Background(), &pb.CreateLogActionRequest{
AccessToken: "token",
UserId: "1001",
UserName: "admin",
OperationModule: "用户管理",
OperationType: "新增",
OperationContent:"创建用户",
OperationIp: "127.0.0.1",
RequestParams: "{...}",
ResponseParams: "{...}",
UserAgent: "curl/8.0",
})分页查询日志
conn, _ := grpc.Dial("localhost:50051", grpc.WithTransportCredentials(insecure.NewCredentials()))
defer conn.Close()
cli := pb.NewLogActionServiceClient(conn)
resp, _ := cli.GetLogActionList(context.Background(), &pb.GetLogActionListRequest{Page: "1", Size: "20", StartTime: "2024-01-01", EndTime: "2024-12-31"})
for _, item := range resp.Items { fmt.Println(item.Id, item.OperationType, item.OperationModule) }代码生成(Go)
protoc --go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
log_action.proto