core

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 20, 2016 License: Apache-2.0 Imports: 12 Imported by: 50

Documentation

Overview

Package core provides common utilities to be used throughout various Lever binaries and libraries. These utilities are very specific to Lever.

Package core is a generated protocol buffer package.

It is generated from these files:

leverrpc.proto

It has these top-level messages:

RPC
StreamMessage
RPCReply
JSON
JSONObject
JSONArray
JSONProperty

Index

Constants

View Source
const (
	// RPCMethodHandler represents the gRPC method handling Lever RPCs.
	RPCMethodHandler = "HandleRPC"
	// StreamingRPCMethodHandler represents the gRPC method handling streaming
	// Lever RPCs.
	StreamingRPCMethodHandler = "HandleStreamingRPC"
)
View Source
const PackageName = "core"

PackageName is the name of this package.

Variables

View Source
var (
	// InstanceListenPortFlag is the port Lever instances listen on for
	// Lever RPCs.
	InstanceListenPortFlag = config.DeclareString(
		PackageName, "instanceListenPort", "3837")
	// InternalEnvironmentSuffixFlag represents the ending of the environment
	// host name to which RPCs can be routed to directly (via internal proxies).
	InternalEnvironmentSuffixFlag = config.DeclareString(
		PackageName, "internalEnvSufix", ".lever")

	// DefaultDevAliasFlag is the actual address of the default Lever
	// environment used for local development.
	DefaultDevAliasFlag = config.DeclareString(
		PackageName, "defaultDevAlias", getDefaultLeverOSIPPort())
	// DefaultDevEnvFlag is the default Lever environment used for local
	// development.
	DefaultDevEnvFlag = config.DeclareString(
		PackageName, "defaultDevEnv", "dev.lever")
	// AdminEnvFlag is the admin Lever environment.
	AdminEnvFlag = config.DeclareString(
		PackageName, "adminEnv", "admin.lever")
)

Functions

func IsAdmin

func IsAdmin(leverURL *LeverURL) bool

IsAdmin returns true iff the env + service represent the admin service.

func IsInternalEnvironment

func IsInternalEnvironment(environment string) bool

IsInternalEnvironment returns true iff the provided environment is part of the same Lever deployment (RPCs can be routed internally).

func RegisterLeverRPCServer

func RegisterLeverRPCServer(s *grpc.Server, srv LeverRPCServer)

Types

type JSON

type JSON struct {
	// Note: If none are set then the value is null.
	//
	// Types that are valid to be assigned to JsonValueOneof:
	//	*JSON_JsonString
	//	*JSON_JsonNumber
	//	*JSON_JsonBool
	//	*JSON_JsonObject
	//	*JSON_JsonArray
	JsonValueOneof isJSON_JsonValueOneof `protobuf_oneof:"json_value_oneof"`
}

JSON represents a JSON-like value, which is represented as a proto message.

func (*JSON) Descriptor

func (*JSON) Descriptor() ([]byte, []int)

func (*JSON) GetJsonArray

func (m *JSON) GetJsonArray() *JSONArray

func (*JSON) GetJsonBool

func (m *JSON) GetJsonBool() bool

func (*JSON) GetJsonNumber

func (m *JSON) GetJsonNumber() float64

func (*JSON) GetJsonObject

func (m *JSON) GetJsonObject() *JSONObject

func (*JSON) GetJsonString

func (m *JSON) GetJsonString() string

func (*JSON) GetJsonValueOneof

func (m *JSON) GetJsonValueOneof() isJSON_JsonValueOneof

func (*JSON) ProtoMessage

func (*JSON) ProtoMessage()

func (*JSON) Reset

func (m *JSON) Reset()

func (*JSON) String

func (m *JSON) String() string

func (*JSON) XXX_OneofFuncs

func (*JSON) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{})

XXX_OneofFuncs is for the internal use of the proto package.

type JSONArray

type JSONArray struct {
	Element []*JSON `protobuf:"bytes,1,rep,name=element" json:"element,omitempty"`
}

func (*JSONArray) Descriptor

func (*JSONArray) Descriptor() ([]byte, []int)

func (*JSONArray) GetElement

func (m *JSONArray) GetElement() []*JSON

func (*JSONArray) ProtoMessage

func (*JSONArray) ProtoMessage()

func (*JSONArray) Reset

func (m *JSONArray) Reset()

func (*JSONArray) String

func (m *JSONArray) String() string

type JSONObject

type JSONObject struct {
	Property []*JSONProperty `protobuf:"bytes,1,rep,name=property" json:"property,omitempty"`
}

func (*JSONObject) Descriptor

func (*JSONObject) Descriptor() ([]byte, []int)

func (*JSONObject) GetProperty

func (m *JSONObject) GetProperty() []*JSONProperty

func (*JSONObject) ProtoMessage

func (*JSONObject) ProtoMessage()

func (*JSONObject) Reset

func (m *JSONObject) Reset()

func (*JSONObject) String

func (m *JSONObject) String() string

type JSONProperty

type JSONProperty struct {
	Name  string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
	Value *JSON  `protobuf:"bytes,2,opt,name=value" json:"value,omitempty"`
}

func (*JSONProperty) Descriptor

func (*JSONProperty) Descriptor() ([]byte, []int)

func (*JSONProperty) GetValue

func (m *JSONProperty) GetValue() *JSON

func (*JSONProperty) ProtoMessage

func (*JSONProperty) ProtoMessage()

func (*JSONProperty) Reset

func (m *JSONProperty) Reset()

func (*JSONProperty) String

func (m *JSONProperty) String() string

type JSON_JsonArray

type JSON_JsonArray struct {
	JsonArray *JSONArray `protobuf:"bytes,5,opt,name=json_array,json=jsonArray,oneof"`
}

type JSON_JsonBool

type JSON_JsonBool struct {
	JsonBool bool `protobuf:"varint,3,opt,name=json_bool,json=jsonBool,oneof"`
}

type JSON_JsonNumber

type JSON_JsonNumber struct {
	JsonNumber float64 `protobuf:"fixed64,2,opt,name=json_number,json=jsonNumber,oneof"`
}

type JSON_JsonObject

type JSON_JsonObject struct {
	JsonObject *JSONObject `protobuf:"bytes,4,opt,name=json_object,json=jsonObject,oneof"`
}

type JSON_JsonString

type JSON_JsonString struct {
	JsonString string `protobuf:"bytes,1,opt,name=json_string,json=jsonString,oneof"`
}

type LeverConfig

type LeverConfig struct {
	Service     string `json:"name"`
	Description string `json:"description,omitempty"`

	// Only one may be specified.
	EntryPoint   []string `json:"entry,omitempty"`
	JSEntryPoint string   `json:"jsEntry,omitempty"`

	IsPrivate bool `json:"private,omitempty"`

	MaxInstanceLoad float64 `json:"maxInstanceLoad,omitempty"`
	MinInstances    int     `json:"minInstances,omitempty"`

	InstanceMemoryMB int `json:"ram,omitempty"`

	// TODO: Future: Allow cust to add own config which can be read from within
	//       the service. Changing just these would not cause service restart.
	//       Think feature flags.
	CustConfig map[string]interface{} `json:"config,omitempty"`
}

LeverConfig is the representation of the contents of lever.json.

func ReadLeverConfig

func ReadLeverConfig(dirPath string) (*LeverConfig, error)

ReadLeverConfig reads lever.json from the provided directory.

func (*LeverConfig) GeneralEntryPoint

func (leverConfig *LeverConfig) GeneralEntryPoint() []string

GeneralEntryPoint returns the entry point specified by the config. (Whether that is specified via entry, goEntry etc).

func (*LeverConfig) Write

func (leverConfig *LeverConfig) Write(dirPath string) error

Write writes lever.json to provied directory.

type LeverRPCClient

type LeverRPCClient interface {
	HandleRPC(ctx context.Context, in *RPC, opts ...grpc.CallOption) (*RPCReply, error)
	HandleStreamingRPC(ctx context.Context, opts ...grpc.CallOption) (LeverRPC_HandleStreamingRPCClient, error)
}

func NewLeverRPCClient

func NewLeverRPCClient(cc *grpc.ClientConn) LeverRPCClient

type LeverRPCServer

type LeverRPCServer interface {
	HandleRPC(context.Context, *RPC) (*RPCReply, error)
	HandleStreamingRPC(LeverRPC_HandleStreamingRPCServer) error
}

type LeverRPC_HandleStreamingRPCClient

type LeverRPC_HandleStreamingRPCClient interface {
	Send(*StreamMessage) error
	Recv() (*StreamMessage, error)
	grpc.ClientStream
}

func SendStreamingLeverRPC

func SendStreamingLeverRPC(
	conn *grpc.ClientConn, ctx context.Context, leverURL *LeverURL,
	opts ...grpc.CallOption) (
	LeverRPC_HandleStreamingRPCClient, error)

SendStreamingLeverRPC sends a Lever streaming RPC to a certain resource within the service being contacted.

type LeverRPC_HandleStreamingRPCServer

type LeverRPC_HandleStreamingRPCServer interface {
	Send(*StreamMessage) error
	Recv() (*StreamMessage, error)
	grpc.ServerStream
}

type LeverURL

type LeverURL struct {
	Environment string
	Service     string
	Resource    string
	Method      string
}

LeverURL holds information about a Lever RPC destination.

func ParseLeverURL

func ParseLeverURL(urlStr string) (*LeverURL, error)

ParseLeverURL parses a URL into a LeverURL. Formats accepted are

Absolute:

lever://<host>[:<port>]/<service>[/<resource>]/<method>

or

Relative (within same environment):

/<service>[/<resource>]/method

func (*LeverURL) String

func (leverURL *LeverURL) String() string

String returns the URL string representation of the LeverURL. If Environment is "" then the URL will be relative.

type RPC

type RPC struct {
	// Types that are valid to be assigned to ArgsOneof:
	//	*RPC_Args
	//	*RPC_ByteArgs
	ArgsOneof isRPC_ArgsOneof `protobuf_oneof:"args_oneof"`
}

RPC is the message used to invoke a Lever service's method.

func (*RPC) Descriptor

func (*RPC) Descriptor() ([]byte, []int)

func (*RPC) GetArgs

func (m *RPC) GetArgs() *JSONArray

func (*RPC) GetArgsOneof

func (m *RPC) GetArgsOneof() isRPC_ArgsOneof

func (*RPC) GetByteArgs

func (m *RPC) GetByteArgs() []byte

func (*RPC) ProtoMessage

func (*RPC) ProtoMessage()

func (*RPC) Reset

func (m *RPC) Reset()

func (*RPC) String

func (m *RPC) String() string

func (*RPC) XXX_OneofFuncs

func (*RPC) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{})

XXX_OneofFuncs is for the internal use of the proto package.

type RPCReply

type RPCReply struct {
	// Types that are valid to be assigned to ResultOneof:
	//	*RPCReply_Result
	//	*RPCReply_ByteResult
	//	*RPCReply_Error
	//	*RPCReply_ByteError
	ResultOneof isRPCReply_ResultOneof `protobuf_oneof:"result_oneof"`
}

RPCReply is used as a return value for a Lever RPC method invokation.

func SendLeverRPC

func SendLeverRPC(
	conn *grpc.ClientConn, ctx context.Context, leverURL *LeverURL, in *RPC,
	opts ...grpc.CallOption) (*RPCReply, error)

SendLeverRPC sends a Lever RPC to a certain resource within the service being contacted.

func (*RPCReply) Descriptor

func (*RPCReply) Descriptor() ([]byte, []int)

func (*RPCReply) GetByteError

func (m *RPCReply) GetByteError() []byte

func (*RPCReply) GetByteResult

func (m *RPCReply) GetByteResult() []byte

func (*RPCReply) GetError

func (m *RPCReply) GetError() *JSON

func (*RPCReply) GetResult

func (m *RPCReply) GetResult() *JSON

func (*RPCReply) GetResultOneof

func (m *RPCReply) GetResultOneof() isRPCReply_ResultOneof

func (*RPCReply) ProtoMessage

func (*RPCReply) ProtoMessage()

func (*RPCReply) Reset

func (m *RPCReply) Reset()

func (*RPCReply) String

func (m *RPCReply) String() string

func (*RPCReply) XXX_OneofFuncs

func (*RPCReply) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{})

XXX_OneofFuncs is for the internal use of the proto package.

type RPCReply_ByteError

type RPCReply_ByteError struct {
	ByteError []byte `protobuf:"bytes,4,opt,name=byte_error,json=byteError,proto3,oneof"`
}

type RPCReply_ByteResult

type RPCReply_ByteResult struct {
	ByteResult []byte `protobuf:"bytes,2,opt,name=byte_result,json=byteResult,proto3,oneof"`
}

type RPCReply_Error

type RPCReply_Error struct {
	Error *JSON `protobuf:"bytes,3,opt,name=error,oneof"`
}

type RPCReply_Result

type RPCReply_Result struct {
	Result *JSON `protobuf:"bytes,1,opt,name=result,oneof"`
}

type RPC_Args

type RPC_Args struct {
	Args *JSONArray `protobuf:"bytes,1,opt,name=args,oneof"`
}

type RPC_ByteArgs

type RPC_ByteArgs struct {
	ByteArgs []byte `protobuf:"bytes,2,opt,name=byte_args,json=byteArgs,proto3,oneof"`
}

type StreamMessage

type StreamMessage struct {
	// Note that the invokation details (rpc field) are part of the very first
	// message sent by the client. It is an error for any other message to have
	// that field set.
	// Also, the very first message sent by the server must be an empty
	// message. This is a workaround for some reverse-proxies which do funny
	// things if there's no data frame.
	//
	// Types that are valid to be assigned to MessageOneof:
	//	*StreamMessage_Rpc
	//	*StreamMessage_Message
	//	*StreamMessage_ByteMessage
	//	*StreamMessage_Error
	//	*StreamMessage_ByteError
	MessageOneof isStreamMessage_MessageOneof `protobuf_oneof:"message_oneof"`
}

StreamMessage represents individual messages sent in a streaming RPC call. These may be either sent or received.

func (*StreamMessage) Descriptor

func (*StreamMessage) Descriptor() ([]byte, []int)

func (*StreamMessage) GetByteError

func (m *StreamMessage) GetByteError() []byte

func (*StreamMessage) GetByteMessage

func (m *StreamMessage) GetByteMessage() []byte

func (*StreamMessage) GetError

func (m *StreamMessage) GetError() *JSON

func (*StreamMessage) GetMessage

func (m *StreamMessage) GetMessage() *JSON

func (*StreamMessage) GetMessageOneof

func (m *StreamMessage) GetMessageOneof() isStreamMessage_MessageOneof

func (*StreamMessage) GetRpc

func (m *StreamMessage) GetRpc() *RPC

func (*StreamMessage) ProtoMessage

func (*StreamMessage) ProtoMessage()

func (*StreamMessage) Reset

func (m *StreamMessage) Reset()

func (*StreamMessage) String

func (m *StreamMessage) String() string

func (*StreamMessage) XXX_OneofFuncs

func (*StreamMessage) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{})

XXX_OneofFuncs is for the internal use of the proto package.

type StreamMessage_ByteError

type StreamMessage_ByteError struct {
	ByteError []byte `protobuf:"bytes,5,opt,name=byte_error,json=byteError,proto3,oneof"`
}

type StreamMessage_ByteMessage

type StreamMessage_ByteMessage struct {
	ByteMessage []byte `protobuf:"bytes,3,opt,name=byte_message,json=byteMessage,proto3,oneof"`
}

type StreamMessage_Error

type StreamMessage_Error struct {
	Error *JSON `protobuf:"bytes,4,opt,name=error,oneof"`
}

type StreamMessage_Message

type StreamMessage_Message struct {
	Message *JSON `protobuf:"bytes,2,opt,name=message,oneof"`
}

type StreamMessage_Rpc

type StreamMessage_Rpc struct {
	Rpc *RPC `protobuf:"bytes,1,opt,name=rpc,oneof"`
}

Jump to

Keyboard shortcuts

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