kieclient

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2020 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	QueryParamQ      = "q"
	QueryByLabelsCon = "&"
	QueryParamMatch  = "match"
	QueryParamKeyID  = "kv_id"
)

match mode

View Source
const (
	HeaderRevision    = "X-Kie-Revision"
	HeaderContentType = "Content-Type"
)

http headers

View Source
const (
	APIPathKV = "kie/kv"

	MsgOpFailed = "operation failed"
	FmtOpFailed = "operate failed [%s], http status [%s], body [%s]"
	APIFmt      = "%s/%s/%s/%s/%s"
)

const

View Source
const (
	ContentTypeJSON = "application/json"
)

ContentType

Variables

View Source
var (
	ErrKeyNotExist = errors.New("can not find value")
	ErrIDEmpty     = errors.New("id is empty")
	ErrNoChanges   = errors.New("kv has not been changed since last polling")
)

client errors

Functions

func ReadBody

func ReadBody(resp *http.Response) []byte

ReadBody read body from the from the response

Types

type Client

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

Client is the servicecomb kie rest client. it is concurrency safe

func New

func New(config Config) (*Client, error)

New create a client

func (*Client) Create added in v1.3.0

func (c *Client) Create(ctx context.Context, kv KVRequest, opts ...OpOption) (*KVDoc, error)

Create create value of a key

func (*Client) CurrentRevision

func (c *Client) CurrentRevision() int

CurrentRevision return the current revision of kie, which is updated on the last get request

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, kvID string, opts ...OpOption) error

Delete remove kv

func (*Client) List added in v1.3.0

func (c *Client) List(ctx context.Context, opts ...GetOption) (*KVResponse, int, error)

List get value of a key

func (*Client) Put

func (c *Client) Put(ctx context.Context, kv KVRequest, opts ...OpOption) (*KVDoc, error)

Put update value of a key

type Config

type Config struct {
	Endpoint      string
	DefaultLabels map[string]string
	VerifyPeer    bool //TODO make it works, now just keep it false
}

Config is the config of client

type GetOption

type GetOption func(*GetOptions)

GetOption is the functional option of client func

func WithExact

func WithExact() GetOption

WithExact means label exact match

func WithGetProject

func WithGetProject(project string) GetOption

WithGetProject query keys with certain project

func WithKey

func WithKey(k string) GetOption

WithKey query keys with certain key

func WithLabels

func WithLabels(l ...map[string]string) GetOption

WithLabels query kv by labels

func WithRevision

func WithRevision(revision int) GetOption

WithRevision query keys with certain revision

func WithWait

func WithWait(duration string) GetOption

WithWait is for long polling,format is 1s,2m

type GetOptions

type GetOptions struct {
	Labels   []map[string]string
	Project  string
	Key      string
	Wait     string
	Exact    bool
	Revision string
}

GetOptions is the options of client func

type KVDoc

type KVDoc struct {
	ID             string `json:"id,omitempty" bson:"id,omitempty" yaml:"id,omitempty" swag:"string"`
	Key            string `json:"key" yaml:"key"`
	Value          string `json:"value,omitempty" yaml:"value,omitempty"`
	ValueType      string `json:"value_type,omitempty" bson:"value_type,omitempty" yaml:"value_type,omitempty"` //ini,json,text,yaml,properties
	Checker        string `json:"check,omitempty" yaml:"check,omitempty"`                                       //python script
	CreateRevision int64  `json:"create_revision,omitempty" bson:"create_revision," yaml:"create_revision,omitempty"`
	UpdateRevision int64  `json:"update_revision,omitempty" bson:"update_revision," yaml:"update_revision,omitempty"`
	Project        string `json:"project,omitempty" yaml:"project,omitempty"`
	Status         string `json:"status,omitempty" yaml:"status,omitempty"`
	CreatTime      int64  `json:"create_time,omitempty" yaml:"create_time,omitempty"`
	UpdateTime     int64  `json:"update_time,omitempty" yaml:"update_time,omitempty"`

	Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"` //redundant
	Domain string            `json:"domain,omitempty" yaml:"domain,omitempty"` //redundant

}

KVDoc is database struct to store kv

type KVRequest

type KVRequest struct {
	ID        string            `json:"id" yaml:"id"`
	Key       string            `json:"key" yaml:"key"`
	Value     string            `json:"value,omitempty" yaml:"value,omitempty"`
	Status    string            `json:"status,omitempty" yaml:"status,omitempty"`
	ValueType string            `json:"value_type,omitempty" bson:"value_type,omitempty" yaml:"value_type,omitempty"` //ini,json,text,yaml,properties
	Checker   string            `json:"check,omitempty" yaml:"check,omitempty"`                                       //python script
	Labels    map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`                                     //redundant
}

KVRequest is http request body

type KVResponse

type KVResponse struct {
	LabelDoc *LabelDocResponse `json:"label,omitempty"`
	Total    int               `json:"total,omitempty"`
	Data     []*KVDoc          `json:"data,omitempty"`
}

KVResponse represents the key value list

type LabelDocResponse

type LabelDocResponse struct {
	Labels map[string]string `json:"labels,omitempty"`
}

LabelDocResponse is label struct

type OpOption

type OpOption func(*OpOptions)

OpOption is the functional option of client func

func WithProject

func WithProject(project string) OpOption

WithProject set project to param

type OpOptions

type OpOptions struct {
	Project string
}

OpOptions is the options of client func

Jump to

Keyboard shortcuts

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