mirror of
https://github.com/chaitin/MonkeyCode.git
synced 2026-11-22 11:28:46 +08:00
- consts/host.go: Host/VM/Terminal 相关常量 - pkg/taskflow/: 完整的 taskflow HTTP+WebSocket 客户端实现 - ent/types/virtualmachine.go: VM Condition 类型定义 - pkg/request: 函数签名添加 context.Context 参数
34 lines
800 B
Go
34 lines
800 B
Go
package taskflow
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/chaitin/MonkeyCode/backend/pkg/request"
|
|
)
|
|
|
|
type hostClient struct {
|
|
client *request.Client
|
|
}
|
|
|
|
func newHostClient(client *request.Client) Hoster {
|
|
return &hostClient{client: client}
|
|
}
|
|
|
|
func (h *hostClient) List(ctx context.Context, userID string) (map[string]*Host, error) {
|
|
resp, err := request.Get[Resp[map[string]*Host]](h.client, ctx, "/internal/host/list", request.WithQuery(request.Query{
|
|
"user_id": userID,
|
|
}))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return resp.Data, nil
|
|
}
|
|
|
|
func (h *hostClient) IsOnline(ctx context.Context, req *IsOnlineReq[string]) (*IsOnlineResp, error) {
|
|
resp, err := request.Post[Resp[*IsOnlineResp]](h.client, ctx, "/internal/host/is-online", req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return resp.Data, nil
|
|
}
|