client

package
v0.17.2 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2023 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultLimit     = 50000
	DefaultCacheSize = 2048
)

Functions

func Decode

func Decode(buf []byte, fields []string, val any) error

func DecodeSlice

func DecodeSlice(buf []byte, fields []string, val any) error

func ErrorStatus

func ErrorStatus(err error) int

Types

type ApiError

type ApiError struct {
	Code      int    `json:"code"`
	Status    int    `json:"status"`
	Message   string `json:"message"`
	Scope     string `json:"scope"`
	Detail    string `json:"detail"`
	RequestId string `json:"requestId"`
	Reason    string `json:"reason"`
}

func (ApiError) Error

func (e ApiError) Error() string

type ApiErrors

type ApiErrors struct {
	Errors []ApiError `json:"errors"`
}

func IsErrApi

func IsErrApi(err error) (ApiErrors, bool)

func (ApiErrors) Error

func (e ApiErrors) Error() string

func (*ApiErrors) UnmarshalJSON

func (e *ApiErrors) UnmarshalJSON(buf []byte) error

type Client

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

func NewClient

func NewClient(url string, httpClient *http.Client) *Client

func (*Client) Async

func (c *Client) Async(ctx context.Context, path string, headers http.Header, result any) FutureResult

func (*Client) CacheAdd

func (c *Client) CacheAdd(key, val any)

func (*Client) CacheGet

func (c *Client) CacheGet(key any) (any, bool)

func (*Client) DefaultHeaders

func (c *Client) DefaultHeaders() http.Header

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, path string, headers http.Header) error

func (*Client) Get

func (c *Client) Get(ctx context.Context, path string, headers http.Header, result any) error

func (*Client) Post

func (c *Client) Post(ctx context.Context, path string, headers http.Header, data, result any) error

func (*Client) Put

func (c *Client) Put(ctx context.Context, path string, headers http.Header, data, result any) error

func (Client) Retries

func (c Client) Retries() int

func (Client) RetryDelay

func (c Client) RetryDelay() time.Duration

func (*Client) UseScriptCache

func (c *Client) UseScriptCache(cache *lru.TwoQueueCache)

func (*Client) WithApiKey

func (c *Client) WithApiKey(s string) *Client

func (*Client) WithCacheSize

func (c *Client) WithCacheSize(sz int) *Client

func (*Client) WithHeader

func (c *Client) WithHeader(key, value string) *Client

func (*Client) WithLogger

func (c *Client) WithLogger(log log.Logger) *Client

func (*Client) WithRetry

func (c *Client) WithRetry(num int, delay time.Duration) *Client

func (*Client) WithTLS

func (c *Client) WithTLS(tc *tls.Config) *Client

func (*Client) WithTimeout

func (c *Client) WithTimeout(d time.Duration) *Client

func (*Client) WithUrl

func (c *Client) WithUrl(url string) *Client

func (*Client) WithUserAgent

func (c *Client) WithUserAgent(s string) *Client

type Decoder

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

type ErrRateLimited

type ErrRateLimited struct {
	Status          int
	IsResponseError bool

	Header http.Header
	// contains filtered or unexported fields
}

func IsErrRateLimited

func IsErrRateLimited(err error) (ErrRateLimited, bool)

func NewErrRateLimited

func NewErrRateLimited(d time.Duration, isResponse bool) ErrRateLimited

func (ErrRateLimited) Deadline

func (e ErrRateLimited) Deadline() time.Duration

func (ErrRateLimited) Done

func (e ErrRateLimited) Done() <-chan struct{}

func (ErrRateLimited) Error

func (e ErrRateLimited) Error() string

func (ErrRateLimited) Wait

func (e ErrRateLimited) Wait(ctx context.Context) error

type FieldInfo

type FieldInfo struct {
	Idx      []int
	Name     string
	Alias    string
	Flags    int
	TypeName string
}

FieldInfo holds details for the representation of a single field.

func (FieldInfo) ContainsFlag

func (f FieldInfo) ContainsFlag(flag int) bool

func (*FieldInfo) DerefIndirect

func (finfo *FieldInfo) DerefIndirect(v interface{}) reflect.Value

Load value from interface, but only if the result will be usefully addressable.

func (FieldInfo) String

func (f FieldInfo) String() string

func (*FieldInfo) Value

func (finfo *FieldInfo) Value(v reflect.Value) reflect.Value

value returns v's field value corresponding to finfo. It's equivalent to v.FieldByIndex(finfo.idx), but initializes and dereferences pointers as necessary.

type FillMode

type FillMode string

type Filter

type Filter struct {
	Mode   FilterMode
	Column string
	Value  any
}

type FilterList

type FilterList []Filter

func (*FilterList) Add

func (l *FilterList) Add(mode FilterMode, col string, val ...any)

type FilterMode

type FilterMode string

type FormatType

type FormatType string

type FutureResult

type FutureResult chan *response

func (FutureResult) Done

func (r FutureResult) Done() bool

func (FutureResult) Receive

func (r FutureResult) Receive(ctx context.Context) error

type HttpError

type HttpError struct {
	Status  int
	Data    string
	Request string
	Header  http.Header
}

func IsErrHttp

func IsErrHttp(err error) (HttpError, bool)

func (HttpError) Error

func (e HttpError) Error() string

type OrderType

type OrderType string

type Query

type Query struct {
	Server string
	Path   string
	Query  url.Values
}

func NewQuery

func NewQuery() Query

func ParseQuery

func ParseQuery(s string) (Query, error)

parse from http://server:port/prefix server:port/prefix server/prefix /prefix

func (Query) And

func (p Query) And(key string) Query

func (Query) AndArg

func (p Query) AndArg(key string, values ...any) Query

func (Query) AndEqual

func (p Query) AndEqual(key string, val any) Query

func (Query) AndFilter

func (p Query) AndFilter(key string, mode FilterMode, values ...any) Query

func (Query) AndGt

func (p Query) AndGt(key string, val any) Query

func (Query) AndGte

func (p Query) AndGte(key string, val any) Query

func (Query) AndIn

func (p Query) AndIn(key string, val ...any) Query

func (Query) AndLt

func (p Query) AndLt(key string, val any) Query

func (Query) AndLte

func (p Query) AndLte(key string, val any) Query

func (Query) AndNot

func (p Query) AndNot(key string) Query

func (Query) AndNotEqual

func (p Query) AndNotEqual(key string, val any) Query

func (Query) AndNotIn

func (p Query) AndNotIn(key string, val ...any) Query

func (Query) AndRange

func (p Query) AndRange(key string, from, to any) Query

func (Query) AndRegexp

func (p Query) AndRegexp(key string, re string) Query

func (Query) Asc

func (p Query) Asc() Query

func (Query) Check

func (p Query) Check() error

func (Query) Clone

func (p Query) Clone() Query

func (Query) Desc

func (p Query) Desc() Query

func (Query) Url

func (p Query) Url() string

func (Query) WithCursor

func (p Query) WithCursor(v uint64) Query

func (Query) WithFrom

func (p Query) WithFrom(t time.Time) Query

func (Query) WithLimit

func (p Query) WithLimit(v uint) Query

func (Query) WithMerge

func (p Query) WithMerge() Query

func (Query) WithMeta

func (p Query) WithMeta() Query

func (Query) WithOffset

func (p Query) WithOffset(v uint) Query

func (Query) WithOrder

func (p Query) WithOrder(o OrderType) Query

func (Query) WithPath

func (p Query) WithPath(path string) Query

func (Query) WithPrim

func (p Query) WithPrim() Query

func (Query) WithRights

func (p Query) WithRights() Query

func (Query) WithStorage

func (p Query) WithStorage() Query

func (Query) WithTags

func (p Query) WithTags(t ...string) Query

func (Query) WithTimeRange

func (p Query) WithTimeRange(from, to time.Time) Query

func (Query) WithTo

func (p Query) WithTo(t time.Time) Query

func (Query) WithUnpack

func (p Query) WithUnpack() Query

type StreamResponse

type StreamResponse struct {
	Runtime time.Duration
	Cursor  string
	Count   int
}

func NewStreamResponse

func NewStreamResponse(header http.Header) (StreamResponse, error)

type TableQuery

type TableQuery[T any] struct {
	Query   Query
	Table   string     // "op", "block", "chain", "flow"
	Format  FormatType // "json", "csv"
	Columns []string
	Limit   int
	Cursor  uint64
	Verbose bool
	Prim    bool
	NoFail  bool
	Filter  FilterList
	Order   OrderType // asc, desc
	// contains filtered or unexported fields
}

func NewTableQuery

func NewTableQuery[T any](c *Client, name string) *TableQuery[T]

func (*TableQuery[T]) AndEqual

func (q *TableQuery[T]) AndEqual(col string, val any) *TableQuery[T]

func (*TableQuery[T]) AndFilter

func (q *TableQuery[T]) AndFilter(mode FilterMode, col string, val ...any) *TableQuery[T]

func (*TableQuery[T]) AndGt

func (q *TableQuery[T]) AndGt(col string, val any) *TableQuery[T]

func (*TableQuery[T]) AndGte

func (q *TableQuery[T]) AndGte(col string, val any) *TableQuery[T]

func (*TableQuery[T]) AndIn

func (q *TableQuery[T]) AndIn(col string, val ...any) *TableQuery[T]

func (*TableQuery[T]) AndLt

func (q *TableQuery[T]) AndLt(col string, val any) *TableQuery[T]

func (*TableQuery[T]) AndLte

func (q *TableQuery[T]) AndLte(col string, val any) *TableQuery[T]

func (*TableQuery[T]) AndNotEqual

func (q *TableQuery[T]) AndNotEqual(col string, val any) *TableQuery[T]

func (*TableQuery[T]) AndNotIn

func (q *TableQuery[T]) AndNotIn(col string, val ...any) *TableQuery[T]

func (*TableQuery[T]) AndRange

func (q *TableQuery[T]) AndRange(col string, from, to any) *TableQuery[T]

func (*TableQuery[T]) AndRegexp

func (q *TableQuery[T]) AndRegexp(col string, re string) *TableQuery[T]

func (*TableQuery[T]) Asc

func (q *TableQuery[T]) Asc() *TableQuery[T]

func (TableQuery[T]) Check

func (p TableQuery[T]) Check() error

func (*TableQuery[T]) Desc

func (q *TableQuery[T]) Desc() *TableQuery[T]

func (*TableQuery[T]) GetColumns

func (q *TableQuery[T]) GetColumns() []string

func (*TableQuery[T]) ReplaceFilter

func (q *TableQuery[T]) ReplaceFilter(mode FilterMode, col string, val ...any) *TableQuery[T]

func (*TableQuery[T]) ResetFilter

func (q *TableQuery[T]) ResetFilter() *TableQuery[T]

func (TableQuery[T]) Run

func (q TableQuery[T]) Run(ctx context.Context) (*TableQueryResult[T], error)

func (TableQuery[T]) Url

func (p TableQuery[T]) Url() string

func (*TableQuery[T]) WithColumns

func (q *TableQuery[T]) WithColumns(cols ...string) *TableQuery[T]

func (*TableQuery[T]) WithCursor

func (q *TableQuery[T]) WithCursor(c uint64) *TableQuery[T]

func (*TableQuery[T]) WithFormat

func (q *TableQuery[T]) WithFormat(format FormatType) *TableQuery[T]

func (*TableQuery[T]) WithLimit

func (q *TableQuery[T]) WithLimit(limit int) *TableQuery[T]

func (*TableQuery[T]) WithNoFail

func (q *TableQuery[T]) WithNoFail() *TableQuery[T]

func (*TableQuery[T]) WithOrder

func (q *TableQuery[T]) WithOrder(order OrderType) *TableQuery[T]

func (*TableQuery[T]) WithPrim

func (q *TableQuery[T]) WithPrim() *TableQuery[T]

func (*TableQuery[T]) WithQuiet

func (q *TableQuery[T]) WithQuiet() *TableQuery[T]

func (*TableQuery[T]) WithVerbose

func (q *TableQuery[T]) WithVerbose() *TableQuery[T]

type TableQueryResult

type TableQueryResult[T any] struct {
	// contains filtered or unexported fields
}

func NewTableQueryResult

func NewTableQueryResult[T any](cols []string) *TableQueryResult[T]

func (*TableQueryResult[T]) Cursor

func (r *TableQueryResult[T]) Cursor() uint64

func (*TableQueryResult[T]) Last

func (r *TableQueryResult[T]) Last() (t T)

func (*TableQueryResult[T]) Len

func (r *TableQueryResult[T]) Len() int

func (*TableQueryResult[T]) Rows

func (r *TableQueryResult[T]) Rows() []T

func (*TableQueryResult[T]) UnmarshalJSON

func (r *TableQueryResult[T]) UnmarshalJSON(data []byte) error

type TypeInfo

type TypeInfo struct {
	Name     string
	Fields   []FieldInfo
	IsGoType bool
	TagName  string
}

TypeInfo holds details for the representation of a type.

func (TypeInfo) Aliases

func (t TypeInfo) Aliases() []string

func (TypeInfo) FieldNames

func (t TypeInfo) FieldNames() []string

func (TypeInfo) FilteredAliases

func (t TypeInfo) FilteredAliases(f int) []string

func (TypeInfo) Find

func (t TypeInfo) Find(name string) (FieldInfo, bool)

Jump to

Keyboard shortcuts

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