endpoint

package
v0.0.0-...-0119d12 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNS               = errorx.NewNamespace("debug_api.endpoint")
	ErrUnknownComponent = ErrNS.NewType("unknown_component")
	ErrInvalidEndpoint  = ErrNS.NewType("invalid_endpoint")
)

Functions

This section is empty.

Types

type APIDefinition

type APIDefinition struct {
	ID          string               `json:"id"`
	Component   topo.Kind            `json:"component"`
	Path        string               `json:"path"`
	Method      string               `json:"method"`
	PathParams  []APIParamDefinition `json:"path_params"`  // e.g. /stats/dump/{db}/{table} -> db, table
	QueryParams []APIParamDefinition `json:"query_params"` // e.g. /debug/pprof?seconds=1 -> seconds

	BeforeSendRequest func(req *httpclient.LazyRequest) `json:"-"`
}

APIDefinition defines what an API endpoints accepts. APIDefinition can be "resolved" to become a request when its parameter values are given via RequestPayload.

type APIParamDefinition

type APIParamDefinition struct {
	Name             string            `json:"name"`
	Required         bool              `json:"required"`
	UIComponentKind  string            `json:"ui_kind"`
	UIComponentProps interface{}       `json:"ui_props"` // varies by different ui kinds
	OnResolve        APIParamResolveFn `json:"-"`
}

APIParamDefinition defines what an API endpoint parameter accepts and how it should look like in the UI. Usually this struct doesn't need to be manually constructed. Use APIParamXxx() helpers.

func APIParamDBName

func APIParamDBName(name string, required bool) APIParamDefinition

func APIParamEnum

func APIParamEnum(name string, required bool, items []EnumItemDefinition) APIParamDefinition

func APIParamInt

func APIParamInt(name string, required bool) APIParamDefinition

func APIParamIntWithDefaultVal

func APIParamIntWithDefaultVal(name string, required bool, defVal string) APIParamDefinition

func APIParamPDKey

func APIParamPDKey(name string, required bool) APIParamDefinition

func APIParamTableID

func APIParamTableID(name string, required bool) APIParamDefinition

func APIParamTableName

func APIParamTableName(name string, required bool) APIParamDefinition

func APIParamText

func APIParamText(name string, required bool) APIParamDefinition

func (*APIParamDefinition) Resolve

func (d *APIParamDefinition) Resolve(value string) ([]string, error)

type APIParamResolveFn

type APIParamResolveFn func(value string) ([]string, error)

type EnumItemDefinition

type EnumItemDefinition struct {
	Value     string `json:"value"`
	DisplayAs string `json:"display_as"` // Optional
}

type HTTPClients

type HTTPClients struct {
	PDAPIClient            *pdclient.APIClient
	TiDBStatusClient       *tidbclient.StatusClient
	TiKVStatusClient       *tikvclient.StatusClient
	TiFlashStatusClient    *tiflashclient.StatusClient
	TiCDCStatusClient      *ticdcclient.StatusClient
	TiProxyStatusClient    *tiproxyclient.StatusClient
	TSOStatusClient        *tsoclient.StatusClient
	SchedulingStatusClient *schedulingclient.StatusClient
}

func (HTTPClients) GetHTTPClientByNodeKind

func (c HTTPClients) GetHTTPClientByNodeKind(kind topo.Kind) *httpclient.Client

type RequestPayload

type RequestPayload struct {
	API         string            `json:"api_id"`
	Host        string            `json:"host"`
	Port        int               `json:"port"`
	ParamValues map[string]string `json:"param_values"`
}

RequestPayload describes how a server-side request should be sent, by describing the API endpoint to send and its parameter values. The content of this struct is specified by the user so that it should be carefully checked.

type RequestPayloadResolver

type RequestPayloadResolver struct {
	// contains filtered or unexported fields
}

RequestPayloadResolver resolves the request payload using specified API definitions.

The relationship is below:

RequestPayload ---(RequestPayloadResolver.ResolvePayload)---> ResolvedRequestPayload

func NewRequestPayloadResolver

func NewRequestPayloadResolver(apis []APIDefinition, acceptedClients HTTPClients) *RequestPayloadResolver

func (*RequestPayloadResolver) ListAPIs

func (r *RequestPayloadResolver) ListAPIs() []APIDefinition

func (*RequestPayloadResolver) ResolvePayload

func (r *RequestPayloadResolver) ResolvePayload(payload RequestPayload) (*ResolvedRequestPayload, error)

type ResolvedRequestPayload

type ResolvedRequestPayload struct {
	// contains filtered or unexported fields
}

ResolvedRequestPayload describes the final request to send by the server. It is constructed by from the RequestPayload and the corresponding APIDefinition.

func (*ResolvedRequestPayload) SendRequestAndPipe

func (p *ResolvedRequestPayload) SendRequestAndPipe(
	ctx context.Context,
	clientsToUse HTTPClients,
	etcdClient *clientv3.Client,
	pdClient *pd.Client,
	w io.Writer,
) (respNoBody *http.Response, err error)

type UIComponentDropdownProps

type UIComponentDropdownProps struct {
	Items []EnumItemDefinition `json:"items"`
}

UIComponentDropdownProps is the type of UIComponentProps when UIComponentKind is "dropdown".

type UIComponentTextProps

type UIComponentTextProps struct {
	Placeholder string `json:"placeholder"`
	DefaultVal  string `json:"default_val"`
}

UIComponentTextProps is the type of UIComponentProps when UIComponentKind is "text".

Jump to

Keyboard shortcuts

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