client

package
v1.25.33-jh Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 20 Imported by: 2 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
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

func CachedFallback(service, uri string, params ...map[string]any) func(error) (string, bool)

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 Call added in v1.19.0

func Call(service, uri string, op *Options) (result string, callErr error)

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

func CallResultT[T any](service, uri string, op *Options) models.Result[T]

CallResultT 调用使用 status/data/msg 协议的旧版微服务。

func CallT added in v1.19.0

func CallT[T any](service, uri string, op *Options) vo.Response[T]

CallT 调用微服务并解析 code/data/msg/srvTime 响应。

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:"-"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL