client

package
v0.0.0-...-b4fed4d Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2024 License: Apache-2.0 Imports: 22 Imported by: 7

Documentation

Overview

Copyright 2021 Layotto Authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. CODE ATTRIBUTION: https://github.com/dapr/go-sdk Modified the import package to use layotto's pb We use same sdk code with Dapr's for state API because we want to keep compatible with Dapr state API

Copyright 2021 Layotto Authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2021 Layotto Authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. CODE ATTRIBUTION: https://github.com/dapr/go-sdk Modified the import package to use layotto's pb We use same sdk code with Dapr's for state API because we want to keep compatible with Dapr state API

Copyright 2021 Layotto Authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. CODE ATTRIBUTION: https://github.com/dapr/go-sdk Modified the import package to use layotto's pb We use same sdk code with Dapr's for state API because we want to keep compatible with Dapr state API

Copyright 2021 Layotto Authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2021 Layotto Authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. CODE ATTRIBUTION: https://github.com/dapr/go-sdk Modified the import package to use layotto's pb We use same sdk code with Dapr's for state API because we want to keep compatible with Dapr state API

Index

Constants

View Source
const (
	// StateConsistencyUndefined is the undefined value for state consistency.
	StateConsistencyUndefined StateConsistency = 0
	// StateConsistencyEventual represents eventual state consistency value.
	StateConsistencyEventual StateConsistency = 1
	// StateConsistencyStrong represents strong state consistency value.
	StateConsistencyStrong StateConsistency = 2

	// StateConcurrencyUndefined is the undefined value for state concurrency.
	StateConcurrencyUndefined StateConcurrency = 0
	// StateConcurrencyFirstWrite represents first write concurrency value.
	StateConcurrencyFirstWrite StateConcurrency = 1
	// StateConcurrencyLastWrite represents last write concurrency value.
	StateConcurrencyLastWrite StateConcurrency = 2

	// StateOperationTypeUndefined is the undefined value for state operation type.
	StateOperationTypeUndefined OperationType = 0
	// StateOperationTypeUpsert represents upsert operation type value.
	StateOperationTypeUpsert OperationType = 1
	// StateOperationTypeDelete represents delete operation type value.
	StateOperationTypeDelete OperationType = 2
	// UndefinedType represents undefined type value
	UndefinedType = "undefined"
)

Variables

This section is empty.

Functions

func GoWithRecover

func GoWithRecover(handler func(), recoverHandler func(r interface{}))

GoWithRecover wraps a `go func()` with recover()

func RegisterRecoverLogger

func RegisterRecoverLogger(f func(w io.Writer, r interface{}))

RegisterRecoverLogger replace the log handler when go with recover catch a panic notice the replaced handler should be simple. if the handler panic, the recover handler will be failed.

Types

type BulkStateItem

type BulkStateItem struct {
	Key      string
	Value    []byte
	Etag     string
	Metadata map[string]string
	Error    string
}

BulkStateItem represents a single state item.

type Client

type Client interface {
	s3.ObjectStorageServiceClient

	// "mosn.io/layotto/spec/proto/extension/v1/cryption"
	cryption.CryptionServiceClient

	// "mosn.io/layotto/spec/proto/extension/v1/delay_queue"
	delay_queue.DelayQueueClient

	// "mosn.io/layotto/spec/proto/extension/v1/email"
	email.EmailServiceClient

	// "mosn.io/layotto/spec/proto/extension/v1/phone"
	phone.PhoneCallServiceClient

	// "mosn.io/layotto/spec/proto/extension/v1/sms"
	sms.SmsServiceClient
	// contains filtered or unexported methods
}

Client is the interface for runtime client implementation.

func NewClient

func NewClient() (client Client, err error)

NewClient instantiates runtime client using runtime_GRPC_PORT environment variable as port. Note, this default factory function creates runtime client only once. All subsequent invocations will return the already created instance. To create multiple instances of the runtime client, use one of the parameterized factory functions:

NewClientWithPort(port string) (client Client, err error) NewClientWithAddress(address string) (client Client, err error) NewClientWithConnection(conn *grpc.ClientConn) Client

func NewClientWithAddress

func NewClientWithAddress(address string) (client Client, err error)

NewClientWithAddress instantiates runtime using specific address (including port).

func NewClientWithConnection

func NewClientWithConnection(conn *grpc.ClientConn) Client

NewClientWithConnection instantiates runtime client using specific connection.

func NewClientWithPort

func NewClientWithPort(port string) (client Client, err error)

NewClientWithPort instantiates runtime using specific port.

type ConfigurationItem

type ConfigurationItem struct {
	// Required. The key of configuration item
	Key string
	// The content of configuration item
	// Empty if the configuration is not set, including the case that the configuration is changed from value-set to value-not-set.
	Content string
	// The group of configuration item.
	Group string
	// The label of configuration item.
	Label string
	// The tag list of configuration item.
	Tags map[string]string
	// The metadata which will be passed to configuration store component.
	Metadata map[string]string
}

type ConfigurationRequestItem

type ConfigurationRequestItem struct {
	// The name of configuration store.
	StoreName string
	// The application id which
	// Only used for admin, Ignored and reset for normal client
	AppId string
	// The group of keys.
	Group string
	// The label for keys.
	Label string
	// The keys to get.
	Keys []string
	// The metadata which will be sent to configuration store components.
	Metadata map[string]string
}

ConfigurationRequestItem used for GET,DEL,SUB request

type DataContent

type DataContent struct {
	// Data is the input data
	Data []byte
	// ContentType is the type of the data content
	ContentType string
}

DataContent the service invocation content

type DeleteStateItem

type DeleteStateItem SetStateItem

DeleteStateItem represents a single state to be deleted.

type ETag

type ETag struct {
	Value string
}

ETag represents an versioned record information

type GRPCClient

type GRPCClient struct {
	s3.ObjectStorageServiceClient
	// "mosn.io/layotto/spec/proto/extension/v1/cryption"
	cryption.CryptionServiceClient
	// "mosn.io/layotto/spec/proto/extension/v1/delay_queue"
	delay_queue.DelayQueueClient
	// "mosn.io/layotto/spec/proto/extension/v1/email"
	email.EmailServiceClient
	// "mosn.io/layotto/spec/proto/extension/v1/phone"
	phone.PhoneCallServiceClient
	// "mosn.io/layotto/spec/proto/extension/v1/sms"
	sms.SmsServiceClient
	// contains filtered or unexported fields
}

GRPCClient is the gRPC implementation of runtime client.

func (*GRPCClient) Close

func (c *GRPCClient) Close()

Close cleans up all resources created by the client.

func (*GRPCClient) DeleteBulkState

func (c *GRPCClient) DeleteBulkState(ctx context.Context, storeName string, keys []string) error

DeleteBulkState deletes content for multiple keys from store.

func (*GRPCClient) DeleteBulkStateItems

func (c *GRPCClient) DeleteBulkStateItems(ctx context.Context, storeName string, items []*DeleteStateItem) error

DeleteBulkState deletes content for multiple keys from store.

func (*GRPCClient) DeleteConfiguration

func (c *GRPCClient) DeleteConfiguration(ctx context.Context, in *ConfigurationRequestItem) error

DeleteConfiguration deletes configuration from configuration store.

func (*GRPCClient) DeleteState

func (c *GRPCClient) DeleteState(ctx context.Context, storeName, key string) error

DeleteState deletes content from store using default state options.

func (*GRPCClient) DeleteStateWithETag

func (c *GRPCClient) DeleteStateWithETag(ctx context.Context, storeName, key string, etag *ETag, meta map[string]string, opts *StateOptions) error

DeleteStateWithETag deletes content from store using provided state options and etag.

func (*GRPCClient) ExecuteStateTransaction

func (c *GRPCClient) ExecuteStateTransaction(ctx context.Context, storeName string, meta map[string]string, ops []*StateOperation) error

ExecuteStateTransaction provides way to execute multiple operations on a specified store.

func (*GRPCClient) GetBulkState

func (c *GRPCClient) GetBulkState(ctx context.Context, storeName string, keys []string, meta map[string]string, parallelism int32) ([]*BulkStateItem, error)

GetBulkState retrieves state for multiple keys from specific store.

func (*GRPCClient) GetConfiguration

func (c *GRPCClient) GetConfiguration(ctx context.Context, in *ConfigurationRequestItem) ([]*ConfigurationItem, error)

func (*GRPCClient) GetNextId

func (*GRPCClient) GetSecret

func (*GRPCClient) GetState

func (c *GRPCClient) GetState(ctx context.Context, storeName, key string) (item *StateItem, err error)

GetState retrieves state from specific store using default consistency option.

func (*GRPCClient) GetStateWithConsistency

func (c *GRPCClient) GetStateWithConsistency(ctx context.Context, storeName, key string, meta map[string]string, sc StateConsistency) (item *StateItem, err error)

GetStateWithConsistency retrieves state from specific store using provided state consistency.

func (*GRPCClient) InvokeMethod

func (c *GRPCClient) InvokeMethod(ctx context.Context, appID, methodName, verb string) (out []byte, err error)

InvokeMethod invokes service without raw data ([]byte).

func (*GRPCClient) InvokeMethodWithContent

func (c *GRPCClient) InvokeMethodWithContent(ctx context.Context, appID, methodName, verb string, content *DataContent) (out []byte, err error)

InvokeMethodWithContent invokes service without content (data + content type).

func (*GRPCClient) InvokeMethodWithCustomContent

func (c *GRPCClient) InvokeMethodWithCustomContent(ctx context.Context, appID, methodName, verb string, contentType string, content interface{}) (out []byte, err error)

InvokeMethodWithCustomContent invokes service with custom content (struct + content type).

func (*GRPCClient) PublishEvent

func (c *GRPCClient) PublishEvent(ctx context.Context, pubsubName, topicName string, data []byte) error

PublishEvent publishes data onto specific pubsub topic.

func (*GRPCClient) PublishEventfromCustomContent

func (c *GRPCClient) PublishEventfromCustomContent(ctx context.Context, pubsubName, topicName string, data interface{}) error

PublishEventfromCustomContent serializes an struct and publishes its contents as data (JSON) onto topic in specific pubsub component.

func (*GRPCClient) SaveBulkState

func (c *GRPCClient) SaveBulkState(ctx context.Context, storeName string, items ...*SetStateItem) error

SaveBulkState saves the multiple state item to store.

func (*GRPCClient) SaveConfiguration

func (c *GRPCClient) SaveConfiguration(ctx context.Context, in *SaveConfigurationRequest) error

SaveConfiguration saves configuration into configuration store.

func (*GRPCClient) SaveState

func (c *GRPCClient) SaveState(ctx context.Context, storeName, key string, data []byte, so ...StateOption) error

SaveState saves the raw data into store, default options: strong, last-write

func (*GRPCClient) SayHello

func (c *GRPCClient) SayHello(ctx context.Context, in *SayHelloRequest) (*SayHelloResp, error)

func (*GRPCClient) SubscribeConfiguration

func (c *GRPCClient) SubscribeConfiguration(ctx context.Context, in *ConfigurationRequestItem) WatchChan

SubscribeConfiguration gets configuration from configuration store and subscribe the updates.

func (*GRPCClient) TryLock

func (*GRPCClient) Unlock

type OperationType

type OperationType int

OperationType is the operation enum type.

func (OperationType) String

func (o OperationType) String() string

String returns the string value of the OperationType.

type SaveConfigurationRequest

type SaveConfigurationRequest struct {
	// The name of configuration store.
	StoreName string
	// The application id which
	// Only used for admin, ignored and reset for normal client
	AppId string
	// The list of configuration items to save.
	// To delete a exist item, set the key (also label) and let content to be empty
	Items []*ConfigurationItem
	// The metadata which will be sent to configuration store components.
	Metadata map[string]string
}

type SayHelloRequest

type SayHelloRequest struct {
	ServiceName string
}

type SayHelloResp

type SayHelloResp struct {
	Hello string
}

type SetStateItem

type SetStateItem struct {
	Key      string
	Value    []byte
	Etag     *ETag
	Metadata map[string]string
	Options  *StateOptions
}

SetStateItem represents a single state to be persisted.

type StateConcurrency

type StateConcurrency int

StateConcurrency is the concurrency enum type.

func (StateConcurrency) GetPBConcurrency

GetPBConcurrency get concurrency pb value

func (StateConcurrency) String

func (s StateConcurrency) String() string

String returns the string value of the StateConcurrency.

type StateConsistency

type StateConsistency int

StateConsistency is the consistency enum type.

func (StateConsistency) GetPBConsistency

GetPBConsistency get consistency pb value

func (StateConsistency) String

func (s StateConsistency) String() string

String returns the string value of the StateConsistency.

type StateItem

type StateItem struct {
	Key      string
	Value    []byte
	Etag     string
	Metadata map[string]string
}

StateItem represents a single state item.

type StateOperation

type StateOperation struct {
	Type OperationType
	Item *SetStateItem
}

StateOperation is a collection of StateItems with a store name.

type StateOption

type StateOption func(*StateOptions)

StateOption StateOptions's function type

func WithConcurrency

func WithConcurrency(concurrency StateConcurrency) StateOption

WithConcurrency set StateOptions's Concurrency

func WithConsistency

func WithConsistency(consistency StateConsistency) StateOption

WithConsistency set StateOptions's consistency

type StateOptions

type StateOptions struct {
	Concurrency StateConcurrency
	Consistency StateConsistency
}

StateOptions represents the state store persistence policy.

type SubConfigurationResp

type SubConfigurationResp struct {
	// The name of configuration store.
	StoreName string
	// The application id which
	// Only used for admin, ignored and reset for normal client
	AppId string
	// The list of configuration items to save.
	// To delete a exist item, set the key (also label) and let content to be empty
	Items []*ConfigurationItem
}

type WatchChan

type WatchChan <-chan WatchResponse

type WatchResponse

type WatchResponse struct {
	Item *SubConfigurationResp
	Err  error
}

Jump to

Keyboard shortcuts

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