Documentation
¶
Index ¶
- Constants
- func CachedFallback(service, uri string, params ...map[string]any) func(error) (string, bool)deprecated
- func Call(service, uri string, op *Options) (result string, callErr error)
- func CallContext(ctx context.Context, service, uri string, op *Options) (result string, callErr error)
- func CallPageT[T any](service, uri string, op *Options) vo.ResponsePage[T]
- func CallResultT[T any](service, uri string, op *Options) models.Result[T]
- func CallT[T any](service, uri string, op *Options) vo.Response[T]
- type Options
Constants ¶
const ( CONTENT_TYPE_FORM = "x-form" CONTENT_TYPE_JSON = "json" CONTENT_TYPE_RESTFUL = "restful" CONTENT_TYPE_FILE = "file" )
Variables ¶
This section is empty.
Functions ¶
func CachedFallback
deprecated
CachedFallback is the legacy entry point. It only reads responses cached for the current caller's credential headers, so it can never replay another principal's data, but it cannot match entries cached under a Method/Group variant. Prefer CachedFallbackFor.
Deprecated: use CachedFallbackFor.
func CallContext ¶
func CallContext(ctx context.Context, service, uri string, op *Options) (result string, callErr error)
CallContext performs discovery and the outbound request within one caller-owned deadline.
func CallPageT ¶
func CallPageT[T any](service, uri string, op *Options) vo.ResponsePage[T]
CallPageT 调用微服务并解析 data.list/total/page/pageSize 分页响应。
func CallResultT ¶
CallResultT 调用使用 status/data/msg 协议的旧版微服务。
Types ¶
type Options ¶ added in v1.19.0
type Options struct {
Method string `json:"method"` //接口方法 GET|POST|PUT|DELETE
Protocol string `json:"protocol"` //协议 x-form|json|restful
Group string `json:"group"` //应用分组,用于nacos中分组,不传为当前nacos分组及默认分组
Registry string `json:"registry"` //目标注册中心实例名称,留空使用默认实例
Header any `json:"header"` //额外的头部参数
Query any `json:"query"` //URL Query参数
Data any `json:"data"` //x-form Postform参数
Json any `json:"json"` //json或restful模式的body参数
Path map[string]string `json:"path"` //restful模式的路径参数
Files []grequests.FileUpload //文件上传数据
Retry bool `json:"retry"` //是否重试
// Timeout bounds the complete outbound request. Zero uses the framework default.
Timeout time.Duration `json:"timeout"`
Fallback func(error) (string, bool) `json:"-"`
CircuitKey string `json:"circuit_key"`
// CircuitFailures and CircuitOpenWindow override the safe defaults when set.
CircuitFailures int `json:"circuit_failures"`
CircuitOpenWindow time.Duration `json:"circuit_open_window"`
// Cache opts a successful GET response into the shared response cache and
// installs the built-in cached fallback when Fallback is nil. It can also be
// enabled process-wide with go.client.cache.enabled.
Cache bool `json:"cache"`
// CacheTTL bounds how long a cached response stays usable; zero uses
// go.client.cache.ttl (default 30s).
CacheTTL time.Duration `json:"cache_ttl"`
// CacheScope isolates cached entries by an explicit tenant, principal or
// permission version. Never place raw tokens in it. When empty, an opaque
// identity is derived from the credential headers.
CacheScope string `json:"cache_scope"`
// OnFallback is invoked with the original error when a fallback result is
// returned, letting callers mark the response as degraded.
OnFallback func(error) `json:"-"`
}