client

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2023 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Code generated by ogen, DO NOT EDIT.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithServerURL

func WithServerURL(ctx context.Context, u *url.URL) context.Context

WithServerURL sets context key to override server URL.

Types

type Batch

type Batch struct {
	// Keys list.
	Keys []string `json:"keys"`
	// Cursor used for pagination.
	Cursor int64 `json:"cursor"`
}

Ref: #/components/schemas/batch

func (*Batch) Decode

func (s *Batch) Decode(d *jx.Decoder) error

Decode decodes Batch from json.

func (*Batch) Encode

func (s *Batch) Encode(e *jx.Encoder)

Encode implements json.Marshaler.

func (*Batch) GetCursor

func (s *Batch) GetCursor() int64

GetCursor returns the value of Cursor.

func (*Batch) GetKeys

func (s *Batch) GetKeys() []string

GetKeys returns the value of Keys.

func (*Batch) MarshalJSON

func (s *Batch) MarshalJSON() ([]byte, error)

MarshalJSON implements stdjson.Marshaler.

func (*Batch) SetCursor

func (s *Batch) SetCursor(val int64)

SetCursor sets the value of Cursor.

func (*Batch) SetKeys

func (s *Batch) SetKeys(val []string)

SetKeys sets the value of Keys.

func (*Batch) UnmarshalJSON

func (s *Batch) UnmarshalJSON(data []byte) error

UnmarshalJSON implements stdjson.Unmarshaler.

func (*Batch) Validate

func (s *Batch) Validate() error

type Client

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

Client implements OAS client.

func NewClient

func NewClient(serverURL string, sec SecuritySource, opts ...ClientOption) (*Client, error)

NewClient initializes new Client defined by OAS.

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, params DeleteParams) error

Delete invokes delete operation.

Delete key. Does nothing if key not exists.

DELETE /{namespace}/{key}

func (*Client) DeleteNamespace

func (c *Client) DeleteNamespace(ctx context.Context, params DeleteNamespaceParams) error

DeleteNamespace invokes deleteNamespace operation.

Delete namespace and all keys.

DELETE /{namespace}

func (*Client) Get

func (c *Client) Get(ctx context.Context, params GetParams) (GetRes, error)

Get invokes get operation.

Get value by key.

GET /{namespace}/{key}

func (*Client) Keys

func (c *Client) Keys(ctx context.Context, params KeysParams) (*Batch, error)

Keys invokes keys operation.

List keys in namespace page by page. Iteration may not be consistent if there are updates between pages. At the end of page, operation will return empty list. Iteration order is non-deterministic, but generally tends to be from oldest key to newest key.

GET /{namespace}

func (*Client) Set

func (c *Client) Set(ctx context.Context, request *SetReqWithContentType, params SetParams) error

Set invokes set operation.

Create or replace value in namespace.

POST /{namespace}/{key}

type ClientOption

type ClientOption interface {
	// contains filtered or unexported methods
}

ClientOption is client config option.

func WithClient

func WithClient(client ht.Client) ClientOption

WithClient specifies http client to use.

type DeleteNamespaceNoContent

type DeleteNamespaceNoContent struct{}

DeleteNamespaceNoContent is response for DeleteNamespace operation.

type DeleteNamespaceParams

type DeleteNamespaceParams struct {
	// Key-Value namespace.
	Namespace string
}

DeleteNamespaceParams is parameters of deleteNamespace operation.

type DeleteNoContent

type DeleteNoContent struct{}

DeleteNoContent is response for Delete operation.

type DeleteParams

type DeleteParams struct {
	// Key-Value namespace.
	Namespace string
	// Key name.
	Key string
}

DeleteParams is parameters of delete operation.

type GetNotFound

type GetNotFound struct{}

GetNotFound is response for Get operation.

type GetOK

type GetOK struct {
	Data io.Reader
}

func (GetOK) Read

func (s GetOK) Read(p []byte) (n int, err error)

Read reads data from the Data reader.

Kept to satisfy the io.Reader interface.

type GetOKHeaders

type GetOKHeaders struct {
	XContentType string
	XTTL         OptFloat64
	Response     GetOK
}

GetOKHeaders wraps GetOK with response headers.

func (*GetOKHeaders) GetResponse

func (s *GetOKHeaders) GetResponse() GetOK

GetResponse returns the value of Response.

func (*GetOKHeaders) GetXContentType

func (s *GetOKHeaders) GetXContentType() string

GetXContentType returns the value of XContentType.

func (*GetOKHeaders) GetXTTL

func (s *GetOKHeaders) GetXTTL() OptFloat64

GetXTTL returns the value of XTTL.

func (*GetOKHeaders) SetResponse

func (s *GetOKHeaders) SetResponse(val GetOK)

SetResponse sets the value of Response.

func (*GetOKHeaders) SetXContentType

func (s *GetOKHeaders) SetXContentType(val string)

SetXContentType sets the value of XContentType.

func (*GetOKHeaders) SetXTTL

func (s *GetOKHeaders) SetXTTL(val OptFloat64)

SetXTTL sets the value of XTTL.

func (*GetOKHeaders) Validate

func (s *GetOKHeaders) Validate() error

type GetParams

type GetParams struct {
	// Key-Value namespace.
	Namespace string
	// Key name.
	Key string
}

GetParams is parameters of get operation.

type GetRes

type GetRes interface {
	// contains filtered or unexported methods
}

type HeaderAuth

type HeaderAuth struct {
	APIKey string
}

func (*HeaderAuth) GetAPIKey

func (s *HeaderAuth) GetAPIKey() string

GetAPIKey returns the value of APIKey.

func (*HeaderAuth) SetAPIKey

func (s *HeaderAuth) SetAPIKey(val string)

SetAPIKey sets the value of APIKey.

type HeaderToken

type HeaderToken string

HeaderToken is header base authorization with pre-shared token.

func (HeaderToken) HeaderAuth

func (ta HeaderToken) HeaderAuth(_ context.Context, _ string) (HeaderAuth, error)

type Iterator added in v0.1.3

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

func (*Iterator) Error added in v0.1.3

func (it *Iterator) Error() error

func (*Iterator) Keys added in v0.1.3

func (it *Iterator) Keys() []string

func (*Iterator) Next added in v0.1.3

func (it *Iterator) Next(ctx context.Context) bool

type KV added in v0.1.3

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

KV is simplified wrapper around client.

func Dial added in v0.1.3

func Dial(url string, namespace string, token string) (*KV, error)
Example
ctx := context.Background()

// errors omitted for demonstration purpose
kv, _ := Dial("https://example.com", "my-app", "deadbeaf")
// set item
_ = kv.Set(ctx, "foo", []byte("bar"))
// get item
value, _ := kv.Get(ctx, "foo")
fmt.Println("Got", string(value))
// delete item
_ = kv.Delete(ctx, "foo")
Output:

func New added in v0.1.3

func New(apiClient *Client, namespace string) *KV

func (*KV) Delete added in v0.1.3

func (app *KV) Delete(ctx context.Context, key string) error

Delete single key.

func (*KV) Destroy added in v0.1.3

func (app *KV) Destroy(ctx context.Context) error

Destroy the whole namespace.

func (*KV) Get added in v0.1.3

func (app *KV) Get(ctx context.Context, key string) ([]byte, error)

Get item from API-KV. Returns nil if key not found.

func (*KV) Keys added in v0.1.3

func (app *KV) Keys() *Iterator

Keys in namespace.

Example
ctx := context.Background()

// errors omitted for demonstration purpose
kv, _ := Dial("https://example.com", "my-app", "deadbeaf")
// set item
_ = kv.Set(ctx, "foo", []byte("bar"))
_ = kv.Set(ctx, "bar", []byte("baz"))
// iterate
it := kv.Keys()
for it.Next(ctx) {
	for _, key := range it.Keys() {
		fmt.Println(key)
	}
}
// check errors
if it.Error() != nil {
	panic(it.Error())
}
Output:

func (*KV) Set added in v0.1.3

func (app *KV) Set(ctx context.Context, key string, data []byte) error

Set new or replace old value by key.

func (*KV) SetExpire added in v0.1.3

func (app *KV) SetExpire(ctx context.Context, key string, data []byte, ttl time.Duration) error

SetExpire create new or replace old value by key with desired TTL. TTL <= 0 means disabled expiration.

type KeysParams

type KeysParams struct {
	// Key-Value namespace.
	Namespace string
	// Cursor of the previous page, should be passed in from the previous request or absent for new
	// request.
	Cursor OptInt64
}

KeysParams is parameters of keys operation.

type OptFloat64

type OptFloat64 struct {
	Value float64
	Set   bool
}

OptFloat64 is optional float64.

func NewOptFloat64

func NewOptFloat64(v float64) OptFloat64

NewOptFloat64 returns new OptFloat64 with value set to v.

func (OptFloat64) Get

func (o OptFloat64) Get() (v float64, ok bool)

Get returns value and boolean that denotes whether value was set.

func (OptFloat64) IsSet

func (o OptFloat64) IsSet() bool

IsSet returns true if OptFloat64 was set.

func (OptFloat64) Or

func (o OptFloat64) Or(d float64) float64

Or returns value if set, or given parameter if does not.

func (*OptFloat64) Reset

func (o *OptFloat64) Reset()

Reset unsets value.

func (*OptFloat64) SetTo

func (o *OptFloat64) SetTo(v float64)

SetTo sets value to v.

type OptInt64

type OptInt64 struct {
	Value int64
	Set   bool
}

OptInt64 is optional int64.

func NewOptInt64

func NewOptInt64(v int64) OptInt64

NewOptInt64 returns new OptInt64 with value set to v.

func (OptInt64) Get

func (o OptInt64) Get() (v int64, ok bool)

Get returns value and boolean that denotes whether value was set.

func (OptInt64) IsSet

func (o OptInt64) IsSet() bool

IsSet returns true if OptInt64 was set.

func (OptInt64) Or

func (o OptInt64) Or(d int64) int64

Or returns value if set, or given parameter if does not.

func (*OptInt64) Reset

func (o *OptInt64) Reset()

Reset unsets value.

func (*OptInt64) SetTo

func (o *OptInt64) SetTo(v int64)

SetTo sets value to v.

type Option

type Option interface {
	ClientOption
}

Option is config option.

func WithMeterProvider

func WithMeterProvider(provider metric.MeterProvider) Option

WithMeterProvider specifies a meter provider to use for creating a meter.

If none is specified, the otel.GetMeterProvider() is used.

func WithTracerProvider

func WithTracerProvider(provider trace.TracerProvider) Option

WithTracerProvider specifies a tracer provider to use for creating a tracer.

If none is specified, the global provider is used.

type SecuritySource

type SecuritySource interface {
	// HeaderAuth provides HeaderAuth security value.
	HeaderAuth(ctx context.Context, operationName string) (HeaderAuth, error)
}

SecuritySource is provider of security values (tokens, passwords, etc.).

type SetNoContent

type SetNoContent struct{}

SetNoContent is response for Set operation.

type SetParams

type SetParams struct {
	// Key-Value namespace.
	Namespace string
	// Key name.
	Key string
	// Time-to-live for the key in seconds (floating).
	TTL OptFloat64
}

SetParams is parameters of set operation.

type SetReq

type SetReq struct {
	Data io.Reader
}

func (SetReq) Read

func (s SetReq) Read(p []byte) (n int, err error)

Read reads data from the Data reader.

Kept to satisfy the io.Reader interface.

type SetReqWithContentType

type SetReqWithContentType struct {
	ContentType string
	Content     SetReq
}

SetReqWithContentType wraps SetReq with Content-Type.

func (*SetReqWithContentType) GetContent

func (s *SetReqWithContentType) GetContent() SetReq

GetContent returns the value of Content.

func (*SetReqWithContentType) GetContentType

func (s *SetReqWithContentType) GetContentType() string

GetContentType returns the value of ContentType.

func (*SetReqWithContentType) SetContent

func (s *SetReqWithContentType) SetContent(val SetReq)

SetContent sets the value of Content.

func (*SetReqWithContentType) SetContentType

func (s *SetReqWithContentType) SetContentType(val string)

SetContentType sets the value of ContentType.

Jump to

Keyboard shortcuts

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