gots

package module
v0.0.0-...-53f3f2d Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2014 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultEncoding 默认编码
	DefaultEncoding = "utf8"
	// DefaultSocketTimeout 默认socket链接过期时间
	DefaultSocketTimeout = 50
	// DefaultMaxConnection 默认链接池最大链接数
	DefaultMaxConnection = 50
)
View Source
const (
	HeaderOTSDate         = "x-ots-date"
	HeaderOTSAPIVersion   = "x-ots-apiversion"
	HeaderOTSAccessKeyID  = "x-ots-accesskeyid"
	HeaderOTSInstanceName = "x-ots-instancename"
	HeaderOTSContentMd5   = "x-ots-contentmd5"
	HeaderOTSSignature    = "x-ots-signature"
	HeaderOTSRequestID    = "x-ots-requestid"
	HeaderOTSContentType  = "x-ots-contenttype"

	DefaultAPIVersion = "2014-08-08"

	TimeFormat = "Mon, 02 Jan 2006 15:04:05 GMT"
)

Variables

View Source
var AllowedAPI = map[string]bool{
	"CreateTable":   true,
	"ListTable":     true,
	"DeleteTable":   true,
	"DescribeTable": true,
	"UpdateTable":   true,
	"GetRow":        true,
	"PutRow":        true,
	"UpdateRow":     true,
	"DeleteRow":     true,
	"BatchGetRow":   true,
	"BatchWriteRow": true,
	"GetRange":      true,
}
View Source
var ColumnTypeName = map[ColumnType]string{
	ColumnTypeINFMin:  "INF_MIN",
	ColumnTypeINFMax:  "INF_MAX",
	ColumnTypeInteger: "INTEGER",
	ColumnTypeString:  "STRING",
	ColumnTypeBoolean: "BOOLEAN",
	ColumnTypeDouble:  "DOUBLE",
	ColumnTypeBinary:  "BINARY",
}
View Source
var ColumnTypeValue = map[string]ColumnType{
	"INF_MIN": ColumnTypeINFMin,
	"INF_MAX": ColumnTypeINFMax,
	"INTEGER": ColumnTypeInteger,
	"STRING":  ColumnTypeString,
	"BOOLEAN": ColumnTypeBoolean,
	"DOUBLE":  ColumnTypeDouble,
	"BINARY":  ColumnTypeBinary,
}
View Source
var DirectionName = map[Direction]string{
	DirectionForward:  "FORWARD",
	DirectionBackward: "BACKWARD",
}
View Source
var DirectionValue = map[string]Direction{
	"FORWARD":  DirectionForward,
	"BACKWARD": DirectionBackward,
}
View Source
var OperationTypeName = map[OperationType]string{
	OperationTypePut:    "PUT",
	OperationTypeDelete: "DELETE",
}
View Source
var OperationTypeValue = map[string]OperationType{
	"PUT":    OperationTypePut,
	"DELETE": OperationTypeDelete,
}
View Source
var RowExistenceExpectationName = map[RowExistenceExpectation]string{
	RowExistenceExpectationIgnore:         "IGNORE",
	RowExistenceExpectationExpectExist:    "EXPECT_EXIST",
	RowExistenceExpectationExpectNotExist: "EXPECT_NOT_EXIST",
}
View Source
var RowExistenceExpectationValue = map[string]RowExistenceExpectation{
	"IGNORE":           RowExistenceExpectationIgnore,
	"EXPECT_EXIST":     RowExistenceExpectationExpectExist,
	"EXPECT_NOT_EXIST": RowExistenceExpectationExpectNotExist,
}

Functions

This section is empty.

Types

type BatchGetRowItem

type BatchGetRowItem struct {
	PrimaryKeys []map[string]interface{}
	ColumnNames []string
}

type BatchGetRowResponse

type BatchGetRowResponse struct {
	Tables []*TableInBatchGetRowResponse
}

func (*BatchGetRowResponse) Parse

type BatchWriteRowResponse

type BatchWriteRowResponse struct {
	Tables []*TableInBatchWriteRowResponse
}

type CapacityUnit

type CapacityUnit struct {
	Read  int32
	Write int32
}

func (*CapacityUnit) Parse

func (cu *CapacityUnit) Parse(pbCU *protobuf.CapacityUnit) *CapacityUnit

func (*CapacityUnit) Unparse

func (cu *CapacityUnit) Unparse() *protobuf.CapacityUnit

type Client

type Client struct {
	EndPoint      string
	AccessID      string
	AccessKey     string
	InstanceName  string
	Encoding      string
	SocketTimeout float32
	MaxConnection int
	Debug         bool
	Logger        *log.Logger
	// contains filtered or unexported fields
}

Client 实现了OTS服务的所有接口。用户可以通过NewClient方法创建Client实例

func NewClient

func NewClient(endPoint, accessID, accessKey, instanceName string) *Client

NewClient 方法返回一个Client实例 示例:

import "github.com/Xuyuanp/gots client := ots.NewClient("your_instance_endpoint", "your_user_id", "your_user_key", "your_instance_name") client.Init()

func (*Client) BatchGetRow

func (c *Client) BatchGetRow(items map[string]BatchGetRowItem) (*BatchGetRowResponse, error)

func (*Client) CreateTable

func (c *Client) CreateTable(name string, primaryKey []*ColumnSchema, rt *ReservedThroughput) (*CreateTableResponse, error)

CreateTable 方法用于创建新表。 name: 表名 primaryKey: 主键列表 rt: 预留读写吞吐量 示例:

primaryKey := []*gots.ColumnSchema{
     &gots.ColumnSchema{
             Name: "gid",
             Type: gots.ColumnTypeInteger,
     },
     &gots.ColumnSchema{
             Name: "uid",
             Type: gots.ColumnTypeInteger,
     },
}
rt := &gots.ReservedThroughput{
     CapacityUnit: &gots.CapacityUnit{
             Read:  100,
             Write: 100,
     },
}

resp, err := client.CreateTable("sample_table", primaryKey, rt)

func (*Client) DeleteRow

func (c *Client) DeleteRow(name string, condition *Condition, primaryKey map[string]interface{}) (*DeleteRowResponse, error)

func (*Client) DeleteTable

func (c *Client) DeleteTable(name string) (*DeleteTableResponse, error)

DeleteTable 方法用于删除表 name: 表名 示例:

resp, err := client.DeleteTable("sample_table")

func (*Client) DescribeTable

func (c *Client) DescribeTable(name string) (*TableMeta, *ReservedThoughputDetails, error)

DescribeTable 方法用于获取表描述信息 name: 表名 示例:

resp, err := client.DescribeTable("sample_table")

func (*Client) GetRow

func (c *Client) GetRow(name string, primaryKey map[string]interface{}, columnNames []string) (*GetRowResponse, error)

func (*Client) Init

func (c *Client) Init() error

Init 方法初始化Client,在创建Client实例之后,调用任何访问接口之前必须调用此方法

func (*Client) ListTable

func (c *Client) ListTable() (names []string, err error)

ListTable 方法用于获取所有表名。 示例:

names, err := client.ListTable()

func (*Client) PutRow

func (c *Client) PutRow(name string, condition *Condition, primaryKey map[string]interface{}, columns map[string]interface{}) (response *PutRowResponse, err error)

func (*Client) UpdateRow

func (c *Client) UpdateRow(name string, condition *Condition, primaryKey map[string]interface{}, columnsPut map[string]interface{}, columnsDelete []string) (*UpdateRowResponse, error)

func (*Client) UpdateTable

func (c *Client) UpdateTable(name string, reservedThroughput *ReservedThroughput) (*UpdateTableResponse, error)

UpdateTable 跟新表属性,目前只支持修改预留读写吞吐量 name: 表名 reservedThroughput: 预留读写吞吐量 示例:

rt := &gots.ReservedThroughput{
     CapacityUnit: &gots.CapacityUnit{
             Read:  150,
             Write: 150,
     },
}

resp, err := client.UpdateTable("sample_table", rt)

type Column

type Column struct {
	Name  string
	Value *ColumnValue
}

func ColumnsFromMap

func ColumnsFromMap(colMap map[string]interface{}) []*Column

func (*Column) Parse

func (col *Column) Parse(pbCol *protobuf.Column) *Column

func (*Column) Unparse

func (col *Column) Unparse() *protobuf.Column

type ColumnSchema

type ColumnSchema struct {
	Name string
	Type ColumnType
}

func (*ColumnSchema) Parse

func (cs *ColumnSchema) Parse(pbCS *protobuf.ColumnSchema) *ColumnSchema

func (*ColumnSchema) Unparse

func (cs *ColumnSchema) Unparse() *protobuf.ColumnSchema

type ColumnType

type ColumnType int32
const (
	ColumnTypeINFMin ColumnType = iota
	ColumnTypeINFMax
	ColumnTypeInteger
	ColumnTypeString
	ColumnTypeBoolean
	ColumnTypeDouble
	ColumnTypeBinary
)

func (ColumnType) String

func (t ColumnType) String() string

func (ColumnType) Unparse

func (t ColumnType) Unparse() *protobuf.ColumnType

type ColumnUpdate

type ColumnUpdate struct {
	Type  OperationType
	Name  string
	Value ColumnValue
}

type ColumnValue

type ColumnValue struct {
	Type    ColumnType
	VInt    int64
	VString string
	VBool   bool
	VDouble float64
	VBinary []byte
}

func NewColumnValue

func NewColumnValue(v interface{}) *ColumnValue

func (*ColumnValue) Parse

func (cv *ColumnValue) Parse(pbCV *protobuf.ColumnValue) *ColumnValue

func (*ColumnValue) Unparse

func (cv *ColumnValue) Unparse() *protobuf.ColumnValue

func (*ColumnValue) Value

func (cv *ColumnValue) Value() interface{}

type Condition

type Condition struct {
	RowExistence RowExistenceExpectation
}

func (*Condition) Unparse

func (c *Condition) Unparse() *protobuf.Condition

type ConsumedCapacity

type ConsumedCapacity struct {
	CapacityUnit *CapacityUnit
}

func (*ConsumedCapacity) Parse

type CreateTableResponse

type CreateTableResponse struct {
}

func (*CreateTableResponse) Parse

type Decoder

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

func (*Decoder) DecodeBatchGetRow

func (d *Decoder) DecodeBatchGetRow(data []byte) (*BatchGetRowResponse, error)

func (*Decoder) DecodeCreateTable

func (d *Decoder) DecodeCreateTable(data []byte) (*CreateTableResponse, error)

func (*Decoder) DecodeDeleteRow

func (d *Decoder) DecodeDeleteRow(data []byte) (*DeleteRowResponse, error)

func (*Decoder) DecodeDeleteTable

func (d *Decoder) DecodeDeleteTable(data []byte) (*DeleteTableResponse, error)

func (*Decoder) DecodeDescribeTable

func (d *Decoder) DecodeDescribeTable(data []byte) (*TableMeta, *ReservedThoughputDetails, error)

func (*Decoder) DecodeGetRow

func (d *Decoder) DecodeGetRow(data []byte) (*GetRowResponse, error)

func (*Decoder) DecodeListTable

func (d *Decoder) DecodeListTable(data []byte) ([]string, error)

func (*Decoder) DecodePutRow

func (d *Decoder) DecodePutRow(data []byte) (*PutRowResponse, error)

func (*Decoder) DecodeUpdateRow

func (d *Decoder) DecodeUpdateRow(data []byte) (*UpdateRowResponse, error)

func (*Decoder) DecodeUpdateTable

func (d *Decoder) DecodeUpdateTable(data []byte) (*UpdateTableResponse, error)

type DeleteRowResponse

type DeleteRowResponse struct {
	Consumed *ConsumedCapacity
}

func (*DeleteRowResponse) Parse

type DeleteTableResponse

type DeleteTableResponse struct {
}

func (*DeleteTableResponse) Parse

type DescribeTableResponse

type DescribeTableResponse struct {
	TableMeta                *TableMeta
	ReservedThoughputDetails *ReservedThoughputDetails
}

type Direction

type Direction int32
const (
	DirectionForward Direction = iota
	DirectionBackward
)

type Encoder

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

func (*Encoder) EncodeBatchGetRow

func (e *Encoder) EncodeBatchGetRow(items map[string]BatchGetRowItem) (proto.Message, error)

func (*Encoder) EncodeCreateTable

func (e *Encoder) EncodeCreateTable(name string, primaryKey []*ColumnSchema, rt *ReservedThroughput) (proto.Message, error)

func (*Encoder) EncodeDeleteRow

func (e *Encoder) EncodeDeleteRow(name string, condition *Condition, primaryKey map[string]interface{}) (proto.Message, error)

func (*Encoder) EncodeDeleteTable

func (e *Encoder) EncodeDeleteTable(name string) (proto.Message, error)

func (*Encoder) EncodeDescribeTable

func (e *Encoder) EncodeDescribeTable(name string) (proto.Message, error)

func (*Encoder) EncodeGetRow

func (e *Encoder) EncodeGetRow(name string, primaryKey map[string]interface{}, columnNames []string) (proto.Message, error)

func (*Encoder) EncodeListTable

func (e *Encoder) EncodeListTable() (proto.Message, error)

func (*Encoder) EncodePutRow

func (e *Encoder) EncodePutRow(name string, condition *Condition, primaryKey map[string]interface{}, columns map[string]interface{}) (proto.Message, error)

func (*Encoder) EncodeUpdateRow

func (e *Encoder) EncodeUpdateRow(name string, condition *Condition, primaryKey map[string]interface{}, columnsPut map[string]interface{}, columnsDelete []string) (proto.Message, error)

func (*Encoder) EncodeUpdateTable

func (e *Encoder) EncodeUpdateTable(name string, rt *ReservedThroughput) (proto.Message, error)

type Error

type Error struct {
	Code    string
	Message string
}

func (*Error) Parse

func (e *Error) Parse(pbE *protobuf.Error) *Error

func (*Error) Unparse

func (e *Error) Unparse() *protobuf.Error

type GetRangeResponse

type GetRangeResponse struct {
	Consumed            *ConsumedCapacity
	NextStartPrimaryKey []*Column
	Rows                []*Row
}

type GetRowResponse

type GetRowResponse struct {
	Consumed *ConsumedCapacity
	Row      *Row
}

func (*GetRowResponse) Parse

type ListTableResponse

type ListTableResponse struct {
	TableNames []string
}

type OTSClientError

type OTSClientError struct {
	Status  int
	Message string
}

func (*OTSClientError) Error

func (e *OTSClientError) Error() string

type OTSServiceError

type OTSServiceError struct {
	Status    int
	Code      string
	Message   string
	RequestID string
}

func (*OTSServiceError) Error

func (e *OTSServiceError) Error() string

type OperationType

type OperationType int32
const (
	OperationTypePut    OperationType = 1
	OperationTypeDelete OperationType = 2
)

type Protocol

type Protocol struct {
	EndPoint     string
	AccessID     string
	AccessKey    string
	InstanceName string
}

func (*Protocol) MakeRequest

func (p *Protocol) MakeRequest(apiName string, body []byte) (*http.Request, error)

func (*Protocol) ParseResponse

func (p *Protocol) ParseResponse(apiName string, status int, headers map[string]string, data []byte) error

type PutRowResponse

type PutRowResponse struct {
	Consumed *ConsumedCapacity
}

func (*PutRowResponse) Parse

type ReservedThoughputDetails

type ReservedThoughputDetails struct {
	CapacityUnit         *CapacityUnit
	LastIncreaseTime     int64
	LastDescreaseTime    int64
	NumOfDescreasesToday int32
}

func (*ReservedThoughputDetails) Parse

type ReservedThroughput

type ReservedThroughput struct {
	CapacityUnit *CapacityUnit
}

func (*ReservedThroughput) Unparse

type Row

type Row struct {
	PrimaryKeyColumns []*Column
	AttributeColumns  []*Column
}

func (*Row) Parse

func (r *Row) Parse(pbRow *protobuf.Row) *Row

type RowExistenceExpectation

type RowExistenceExpectation int32
const (
	RowExistenceExpectationIgnore RowExistenceExpectation = iota
	RowExistenceExpectationExpectExist
	RowExistenceExpectationExpectNotExist
)

type RowInBatchGetRowResponse

type RowInBatchGetRowResponse struct {
	IsOk     bool
	Error    *Error
	Consumed *ConsumedCapacity
	Row      *Row
}

func (*RowInBatchGetRowResponse) Parse

type RowInBatchWriteRowResponse

type RowInBatchWriteRowResponse struct {
	IsOk     bool
	Error    *Error
	Consumed *ConsumedCapacity
}

type TableInBatchGetRowResponse

type TableInBatchGetRowResponse struct {
	TableName string
	Rows      []*RowInBatchGetRowResponse
}

func (*TableInBatchGetRowResponse) Parse

type TableInBatchWriteRowResponse

type TableInBatchWriteRowResponse struct {
	TableName  string
	PutRows    []*RowInBatchWriteRowResponse
	UpdateRows []*RowInBatchWriteRowResponse
	DeleteRows []*RowInBatchWriteRowResponse
}

type TableMeta

type TableMeta struct {
	TableName  string
	PrimaryKey []*ColumnSchema
}

func (*TableMeta) Parse

func (tm *TableMeta) Parse(pbTM *protobuf.TableMeta) *TableMeta

func (*TableMeta) Unparse

func (tm *TableMeta) Unparse() *protobuf.TableMeta

type UpdateRowResponse

type UpdateRowResponse struct {
	Consumed *ConsumedCapacity
}

func (*UpdateRowResponse) Parse

type UpdateTableResponse

type UpdateTableResponse struct {
	ReservedThoughputDetails *ReservedThoughputDetails
}

func (*UpdateTableResponse) Parse

Directories

Path Synopsis
Package protobuf is a generated protocol buffer package.
Package protobuf is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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