Documentation
¶
Index ¶
- Variables
- func Instantiate(ctx context.Context, r wazero.Runtime, hostFunctions HttpLibrary) error
- type HttpLibrary
- type HttpRequest
- func (x *HttpRequest) GetBody() []byte
- func (x *HttpRequest) GetHeaders() map[string]string
- func (x *HttpRequest) GetMethod() string
- func (x *HttpRequest) GetTimeoutMs() int64
- func (x *HttpRequest) GetUrl() string
- func (m *HttpRequest) MarshalToSizedBufferVT(dAtA []byte) (int, error)
- func (m *HttpRequest) MarshalToVT(dAtA []byte) (int, error)
- func (m *HttpRequest) MarshalVT() (dAtA []byte, err error)
- func (x *HttpRequest) ProtoReflect() protoreflect.Message
- func (m *HttpRequest) SizeVT() (n int)
- func (m *HttpRequest) UnmarshalVT(dAtA []byte) error
- type HttpResponse
- func (x *HttpResponse) GetBody() []byte
- func (x *HttpResponse) GetError() string
- func (x *HttpResponse) GetHeaders() map[string]string
- func (x *HttpResponse) GetStatusCode() int32
- func (x *HttpResponse) GetSuccess() bool
- func (m *HttpResponse) MarshalToSizedBufferVT(dAtA []byte) (int, error)
- func (m *HttpResponse) MarshalToVT(dAtA []byte) (int, error)
- func (m *HttpResponse) MarshalVT() (dAtA []byte, err error)
- func (x *HttpResponse) ProtoReflect() protoreflect.Message
- func (m *HttpResponse) SizeVT() (n int)
- func (m *HttpResponse) UnmarshalVT(dAtA []byte) error
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func Instantiate ¶
Instantiate a Go-defined module named "http-library" that exports host functions.
Types ¶
type HttpLibrary ¶
type HttpLibrary interface {
// 发起 HTTP 请求
DoRequest(context.Context, *HttpRequest) (*HttpResponse, error)
}
HTTP Library - 为 WASM 插件提供 HTTP 请求能力 由于 WASM 环境不支持 net/http 包,本 library 通过 host 函数代理实现 HTTP 请求 go:plugin type=host module=http-library
type HttpRequest ¶
type HttpRequest struct {
Method string `protobuf:"bytes,1,opt,name=method,proto3" json:"method,omitempty"` // HTTP方法: GET, POST, PUT, DELETE等
Url string `protobuf:"bytes,2,opt,name=url,proto3" json:"url,omitempty"` // 完整的请求URL
Headers map[string]string `` // 请求头
/* 155-byte string literal not displayed */
Body []byte `protobuf:"bytes,4,opt,name=body,proto3" json:"body,omitempty"` // 请求体
TimeoutMs int64 `protobuf:"varint,5,opt,name=timeout_ms,json=timeoutMs,proto3" json:"timeout_ms,omitempty"` // 超时时间(毫秒),0表示使用默认超时
// contains filtered or unexported fields
}
HTTP 请求
func (*HttpRequest) GetBody ¶
func (x *HttpRequest) GetBody() []byte
func (*HttpRequest) GetHeaders ¶
func (x *HttpRequest) GetHeaders() map[string]string
func (*HttpRequest) GetMethod ¶
func (x *HttpRequest) GetMethod() string
func (*HttpRequest) GetTimeoutMs ¶
func (x *HttpRequest) GetTimeoutMs() int64
func (*HttpRequest) GetUrl ¶
func (x *HttpRequest) GetUrl() string
func (*HttpRequest) MarshalToSizedBufferVT ¶
func (m *HttpRequest) MarshalToSizedBufferVT(dAtA []byte) (int, error)
func (*HttpRequest) MarshalToVT ¶
func (m *HttpRequest) MarshalToVT(dAtA []byte) (int, error)
func (*HttpRequest) MarshalVT ¶
func (m *HttpRequest) MarshalVT() (dAtA []byte, err error)
func (*HttpRequest) ProtoReflect ¶
func (x *HttpRequest) ProtoReflect() protoreflect.Message
func (*HttpRequest) SizeVT ¶
func (m *HttpRequest) SizeVT() (n int)
func (*HttpRequest) UnmarshalVT ¶
func (m *HttpRequest) UnmarshalVT(dAtA []byte) error
type HttpResponse ¶
type HttpResponse struct {
Success bool `protobuf:"varint,1,opt,name=success,proto3" json:"success,omitempty"` // 请求是否成功
Error string `protobuf:"bytes,2,opt,name=error,proto3" json:"error,omitempty"` // 错误信息(如果失败)
StatusCode int32 `protobuf:"varint,3,opt,name=status_code,json=statusCode,proto3" json:"status_code,omitempty"` // HTTP状态码
Headers map[string]string `` // 响应头
/* 155-byte string literal not displayed */
Body []byte `protobuf:"bytes,5,opt,name=body,proto3" json:"body,omitempty"` // 响应体
// contains filtered or unexported fields
}
HTTP 响应
func (*HttpResponse) GetBody ¶
func (x *HttpResponse) GetBody() []byte
func (*HttpResponse) GetError ¶
func (x *HttpResponse) GetError() string
func (*HttpResponse) GetHeaders ¶
func (x *HttpResponse) GetHeaders() map[string]string
func (*HttpResponse) GetStatusCode ¶
func (x *HttpResponse) GetStatusCode() int32
func (*HttpResponse) GetSuccess ¶
func (x *HttpResponse) GetSuccess() bool
func (*HttpResponse) MarshalToSizedBufferVT ¶
func (m *HttpResponse) MarshalToSizedBufferVT(dAtA []byte) (int, error)
func (*HttpResponse) MarshalToVT ¶
func (m *HttpResponse) MarshalToVT(dAtA []byte) (int, error)
func (*HttpResponse) MarshalVT ¶
func (m *HttpResponse) MarshalVT() (dAtA []byte, err error)
func (*HttpResponse) ProtoReflect ¶
func (x *HttpResponse) ProtoReflect() protoreflect.Message
func (*HttpResponse) SizeVT ¶
func (m *HttpResponse) SizeVT() (n int)
func (*HttpResponse) UnmarshalVT ¶
func (m *HttpResponse) UnmarshalVT(dAtA []byte) error
Click to show internal directories.
Click to hide internal directories.