goots

package module
v0.0.0-...-b363c71 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2017 License: MIT Imports: 23 Imported by: 1

README

goots

![Gitter](https://badges.gitter.im/Join Chat.svg)

Aliyun OTS (Open Table Service) golang SDK.

  • OTS现更名为表格存储(Table Store)

  • 此 golang SDK基于 阿里云表格存储服务 API构架,API兼容 Python SDK

  • 阿里云表格存储是构建在阿里云飞天分布式系统之上的NoSQL数据存储服务,提供海量结构化数据的存储和实时访问

Tips: 使用OTS前,请参考下OTS使用限制项

wercker status

Build Status GoDoc

Build Status Go Walker

Support API

Install

$ go get -u github.com/golang/protobuf/{proto,protoc-gen-go}
$ go get github.com/GiterLab/goots

Usage

package main

import (
	"fmt"
	"os"

	ots2 "github.com/GiterLab/goots"
	. "github.com/GiterLab/goots/otstype" // 为了代码干净
)

// modify it to yours
const (
	ENDPOINT     = "your_instance_address"
	ACCESSID     = "your_accessid"
	ACCESSKEY    = "your_accesskey"
	INSTANCENAME = "your_instance_name"
)

func main() {
	// set running environment
	ots2.OTSDebugEnable = true
	ots2.OTSLoggerEnable = true
	ots2.OTSErrorPanicMode = true // 默认为开启,如果不喜欢panic则设置此为false

	fmt.Println("Test goots start ...")

	// 用户可以使用 ots2.NewWithRetryPolicy 来创建带自定义重试策略的 ots_client 对象
	// 用户可以参考 DefaultRetryPolicy 的代码来自定义重试策略
	ots_client, err := ots2.New(ENDPOINT, ACCESSID, ACCESSKEY, INSTANCENAME)
	if err != nil {
		fmt.Println(err)
	}

	// delete a table
	ots_err := ots_client.DeleteTable("myTable")
	if ots_err != nil {
		fmt.Println(ots_err)
		// os.Exit(1)
	}
	fmt.Println("表已删除")

	// create a table
	// 注意:OTS是按设置的ReservedThroughput计量收费,即使没有读写也会产生费用。
	table_meta := &OTSTableMeta{
		TableName: "myTable",
		SchemaOfPrimaryKey: OTSSchemaOfPrimaryKey{
			{K: "gid", V: "INTEGER"},
			{K: "uid", V: "INTEGER"},
		},
	}
	
	// 容量型实例: 只能设置为0
	// 高性能实例: 可设置为其他值(0-5000)
	reserved_throughput := &OTSReservedThroughput{
		OTSCapacityUnit{0, 0},
	}

	ots_err = ots_client.CreateTable(table_meta, reserved_throughput)
	if ots_err != nil {
		fmt.Println(ots_err)
		os.Exit(1)
	}
	fmt.Println("表已创建")

	// list tables
	list_tables, ots_err := ots_client.ListTable()
	if ots_err != nil {
		fmt.Println(ots_err)
		os.Exit(1)
	}
	fmt.Println("表的列表如下:")
	fmt.Println("list_tables:", list_tables.TableNames)

	// insert a row
	primary_key := &OTSPrimaryKey{
		"gid": 1,
		"uid": 101,
	}
	attribute_columns := &OTSAttribute{
		"name":    "张三",
		"mobile":  111111111,
		"address": "中国A地",
		"age":     20,
	}
	condition := OTSCondition_EXPECT_NOT_EXIST
	put_row_response, ots_err := ots_client.PutRow("myTable", condition, primary_key, attribute_columns)
	if ots_err != nil {
		fmt.Println(ots_err)
		os.Exit(1)
	}
	fmt.Println("成功插入数据,消耗的写CapacityUnit为:", put_row_response.GetWriteConsumed())

	// get a row
	primary_key = &OTSPrimaryKey{
		"gid": 1,
		"uid": 101,
	}
	columns_to_get := &OTSColumnsToGet{
		"name", "address", "age",
	}
	// columns_to_get = nil // read all
	get_row_response, ots_err := ots_client.GetRow("myTable", primary_key, columns_to_get)
	if ots_err != nil {
		fmt.Println(ots_err)
		os.Exit(1)
	}
	fmt.Println("成功读取数据,消耗的读CapacityUnit为:", get_row_response.GetReadConsumed())
	if get_row_response.Row != nil {
		if attribute_columns := get_row_response.Row.GetAttributeColumns(); attribute_columns != nil {
			fmt.Println("name信息:", attribute_columns.Get("name"))
			fmt.Println("address信息:", attribute_columns.Get("address"))
			fmt.Println("age信息:", attribute_columns.Get("age"))
			fmt.Println("mobile信息:", attribute_columns.Get("mobile"))
		} else {
			fmt.Println("未查询到数据")
		}
	} else {
		fmt.Println("未查询到数据")
	}
}

More examples, please see example/interfaces.go.

License

This project is under the MIT License. See the LICENSE file for the full license text.

Documentation

Overview

ots2

errors for ots2

Logger for ots2

protocol for ots2

retry for ots2

Index

Constants

View Source
const (
	DEFAULT_ENCODING       = "utf8"
	DEFAULT_SOCKET_TIMEOUT = 50
	DEFAULT_MAX_CONNECTION = 50
	DEFAULT_LOGGER_NAME    = "ots2-client"
)
View Source
const VERSION string = "2.0.9"

Variables

View Source
var API_VERSION = "2014-08-08"
View Source
var OTSDebugEnable bool = false // OTS调试默认关闭
View Source
var OTSErrorPanicMode bool = true // 默认开启panic模式

如果用户不希望使用panic模式,则设置此为false

View Source
var OTSHttpDebugEnable bool = false // OTS HTTP调试记录
View Source
var OTSLoggerEnable bool = false // OTS运行logger记录

Functions

func LoggerInit

func LoggerInit() error

func SetDefaultSetting

func SetDefaultSetting(setting OTSClient)

Overwrite default settings

Types

type DefaultRetryPolicy

type DefaultRetryPolicy struct {
	// 最大重试次数
	MaxRetryTimes int

	// 最大重试间隔,单位为秒
	MaxRetryDelay float64

	// 每次重试间隔的递增倍数
	ScaleFactor float64

	// 两种错误的起始重试间隔,单位为秒
	ServerThrottlingExceptionDelayFactor float64
	StabilityExceptionDelayFactor        float64
}

默认重试策略 最大重试次数为3,最大重试间隔为2000毫秒,对流控类错误以及读操作相关的服务端内部错误进行了重试。

var OTSDefaultRetryPolicy DefaultRetryPolicy

默认重试策略 最大重试次数为3,最大重试间隔为2000毫秒,对流控类错误以及读操作相关的服务端内部错误进行了重试。

Methods defined here:

GetRetryDelay(retry_times int, exception *OTSServiceError, api_name string) float64

ShouldRetry(retry_times int, exception *OTSServiceError, api_name string) bool

---------------------------------------------------------------------- Data and other attributes defined here:

MaxRetryDelay = 2

MaxRetryTimes = 3

ScaleFactor = 2

ServerThrottlingExceptionDelayFactor = 0.5

StabilityExceptionDelayFactor = 0.2

func (DefaultRetryPolicy) GetRetryDelay

func (self DefaultRetryPolicy) GetRetryDelay(retry_times int, exception *OTSServiceError, api_name string) float64

func (DefaultRetryPolicy) ShouldRetry

func (self DefaultRetryPolicy) ShouldRetry(retry_times int, exception *OTSServiceError, api_name string) bool

type NoDelayRetryPolicy

type NoDelayRetryPolicy struct {
	// 最大重试次数
	MaxRetryTimes int
}

没有延时的重试策略

var OTSNoDelayRetryPolicy NoDelayRetryPolicy

没有延时的重试策略 最大重试次数为3

func (NoDelayRetryPolicy) GetRetryDelay

func (sels NoDelayRetryPolicy) GetRetryDelay(retry_times int, exception *OTSServiceError, api_name string) float64

func (NoDelayRetryPolicy) ShouldRetry

func (self NoDelayRetryPolicy) ShouldRetry(retry_times int, exception *OTSServiceError, api_name string) bool

type NoRetryPolicy

type NoRetryPolicy struct {
}

不进行任何重试的重试策略

var OTSNoRetryPolicy NoRetryPolicy

不进行任何重试的重试策略

func (NoRetryPolicy) GetRetryDelay

func (self NoRetryPolicy) GetRetryDelay(retry_times int, exception *OTSServiceError, api_name string) float64

func (NoRetryPolicy) ShouldRetry

func (self NoRetryPolicy) ShouldRetry(retry_times int, exception *OTSServiceError, api_name string) bool

type OTSClient

type OTSClient struct {
	// OTS服务的地址(例如 'http://instance.cn-hangzhou.ots.aliyun.com:80'),必须以'http://'开头
	EndPoint string
	// 访问OTS服务的accessid,通过官方网站申请或通过管理员获取
	AccessId string
	// 访问OTS服务的accesskey,通过官方网站申请或通过管理员获取
	AccessKey string
	// 访问的实例名,通过官方网站控制台创建或通过管理员获取
	InstanceName string

	// 连接池中每个连接的Socket超时,单位为秒,可以为int或float。默认值为50
	SocketTimeout int
	// 连接池的最大连接数。默认为50
	// golang http自带连接池管理,此参数留作以后扩展用
	MaxConnection int

	// 用来在请求中打DEBUG日志,或者在出错时打ERROR日志
	LoggerName string

	// 字符编码格式,此参数未用,兼容python
	Encoding string

	// 定义了重试策略,默认的重试策略为 DefaultRetryPolicy。
	// 你可以继承 RetryPolicy 来实现自己的重试策略,请参考 DefaultRetryPolicy 的代码。
	RetryPolicy RetryPolicyInterface
	// contains filtered or unexported fields
}

OTSClient实例

func New

func New(end_point, accessid, accesskey, instance_name string, kwargs ...interface{}) (o *OTSClient, err error)

创建一个新的OTSClient实例

func NewWithRetryPolicy

func NewWithRetryPolicy(end_point, accessid, accesskey, instance_name string, retry_policy RetryPolicyInterface, kwargs ...interface{}) (o *OTSClient, err error)

创建一个新的OTSClient实例

func (*OTSClient) BatchGetRow

func (o *OTSClient) BatchGetRow(batch_list *OTSBatchGetRowRequest) (response_rows_list *OTSBatchGetRowResponse, err *OTSError)

说明:批量获取多行数据。

``batch_list``表示获取多行的条件列表,格式如下:

batch_list := &OTSBatchGetRowRequest{
	{
		// TableName
		TableName: "table_name0",
		// PrimaryKey
		Rows: OTSPrimaryKeyRows{
			{"gid": 1, "uid": 101},
			{"gid": 2, "uid": 202},
			{"gid": 3, "uid": 303},
		},
		// ColumnsToGet
		ColumnsToGet: OTSColumnsToGet{"name", "address", "mobile", "age"},
	},
	{
		// TableName
		TableName: "table_name1",
		// PrimaryKey
		Rows: OTSPrimaryKeyRows{
			{"gid": 1, "uid": 101},
			{"gid": 2, "uid": 202},
			{"gid": 3, "uid": 303},
		},
		// ColumnsToGet
		ColumnsToGet: OTSColumnsToGet{"name", "address", "mobile", "age"},
	},
	...
}

其中,Rows 为主键,类型为``otstype.OTSPrimaryKeyRows``。

返回:对应行的结果列表。
      错误信息

``response_rows_list``为``otstype.OTSBatchGetRowResponse``的实例
``response_rows_list.Tables``为返回的结果列表,与请求的顺序一一对应,格式如下:
response_rows_list.Tables --> []*OTSTableInBatchGetRowResponseItem{
	{
		TableName: "table_name0",
		Rows : []*OTSRowInBatchGetRowResponseItem{
			row_data_item0, row_data_item1, ...
		},
	},
	{
		TableName: "table_name1",
		Rows : []*OTSRowInBatchGetRowResponseItem{
			row_data_item0, row_data_item1, ...
		},
	},
	...
}

其中,row_data_item0, row_data_item1为``otstype.OTSRowInBatchGetRowResponseItem``的实例。

示例:

batch_list_get := &OTSBatchGetRowRequest{
	{
		// TableName
		TableName: "myTable",
		// PrimaryKey
		Rows: OTSPrimaryKeyRows{
			{"gid": 1, "uid": 101},
			{"gid": 2, "uid": 202},
			{"gid": 3, "uid": 303},
		},
		// ColumnsToGet
		ColumnsToGet: OTSColumnsToGet{"name", "address", "mobile", "age"},
	},
	{
		// TableName
		TableName: "notExistTable",
		// PrimaryKey
		Rows: OTSPrimaryKeyRows{
			{"gid": 1, "uid": 101},
			{"gid": 2, "uid": 202},
			{"gid": 3, "uid": 303},
		},
		// ColumnsToGet
		ColumnsToGet: OTSColumnsToGet{"name", "address", "mobile", "age"},
	},
}
batch_get_response, ots_err := ots_client.BatchGetRow(batch_list_get)

func (*OTSClient) BatchWriteRow

func (o *OTSClient) BatchWriteRow(batch_list *OTSBatchWriteRowRequest) (response_item_list *OTSBatchWriteRowResponse, err *OTSError)

说明:批量修改多行数据。

``batch_list``表示获取多行的条件列表,格式如下:

batch_list := &OTSBatchWriteRowRequest{
	{
		TableName: "table_name0",
		PutRows: OTSPutRows{
			put_row_item, ...
		},
		UpdateRows: OTSUpdateRows{
			update_row_item, ...
		},
		DeleteRows: OTSDeleteRows{
			delete_row_item, ...
		},
	},
	{
		TableName: "table_name1",
		PutRows: OTSPutRows{
			put_row_item, ...
		},
		UpdateRows: OTSUpdateRows{
			update_row_item, ...
		},
		DeleteRows: OTSDeleteRows{
			delete_row_item, ...
		},
	},
	...
}

其中,put_row_item, 是``otstype.OTSPutRows``类的实例;
      update_row_item, 是``otstype.OTSUpdateRows``类的实例;
      delete_row_item, 是``otstype.OTSDeleteRows``类的实例。

返回:对应行的修改结果列表。
      错误信息。

``response_items_list``为``otstype.OTSBatchWriteRowResponse``的实例
``response_items_list.Tables``为返回的结果列表,与请求的顺序一一对应,格式如下:
response_items_list.Tables --> []*OTSTableInBatchWriteRowResponseItem{
	{
		TableName: "table_name0", // for table_name0
		PutRows: []*OTSRowInBatchWriteRowResponseItem{
			put_row_resp, ...
		},
		UpdateRows: []*OTSRowInBatchWriteRowResponseItem{
			update_row_resp, ...
		},
		DeleteRows: []*OTSRowInBatchWriteRowResponseItem{
			delete_row_resp, ...
		}
	},
	{
		TableName: "table_name1", // for table_name1
		PutRows: []*OTSRowInBatchWriteRowResponseItem{
			put_row_resp, ...
		},
		UpdateRows: []*OTSRowInBatchWriteRowResponseItem{
			update_row_resp, ...
		},
		DeleteRows: []*OTSRowInBatchWriteRowResponseItem{
			delete_row_resp, ...
		}
	},
	...
}

其中put_row_resp,update_row_resp和delete_row_resp都是``*otstype.OTSRowInBatchWriteRowResponseItem``类的实例。

示例:

put_row_item := OTSPutRowItem{
	Condition: OTSCondition_EXPECT_NOT_EXIST, // OTSCondition_IGNORE
	PrimaryKey: OTSPrimaryKey{
		"gid": 2,
		"uid": 202,
	},
	AttributeColumns: OTSAttribute{
		"name":    "李四",
		"address": "中国某地",
		"age":     20,
	},
}
// [2] update_row
update_row_item := OTSUpdateRowItem{
	Condition: OTSCondition_IGNORE,
	PrimaryKey: OTSPrimaryKey{
		"gid": 3,
		"uid": 303,
	},
	UpdateOfAttributeColumns: OTSUpdateOfAttribute{
		OTSOperationType_PUT: OTSColumnsToPut{
			"name":    "李三",
			"address": "中国某地",
		},
		OTSOperationType_DELETE: OTSColumnsToDelete{
			"mobile", "age",
		},
	},
}
// [3] delete_row
delete_row_item := OTSDeleteRowItem{
	Condition: OTSCondition_IGNORE,
	PrimaryKey: OTSPrimaryKey{
		"gid": 4,
		"uid": 404,
	},
}
batch_list := &OTSBatchWriteRowRequest{
	{
		TableName: "myTable",
		PutRows: OTSPutRows{
			put_row_item,
		},
		UpdateRows: OTSUpdateRows{
			update_row_item,
		},
		DeleteRows: OTSDeleteRows{
			delete_row_item,
		},
	},
	{
		TableName: "notExistTable",
		PutRows: OTSPutRows{
			put_row_item,
		},
		UpdateRows: OTSUpdateRows{
			update_row_item,
		},
		DeleteRows: OTSDeleteRows{
			delete_row_item,
		},
	},
}
batch_write_response, ots_err := ots_client.BatchWriteRow(batch_list)

func (*OTSClient) CreateTable

func (o *OTSClient) CreateTable(table_meta *OTSTableMeta, reserved_throughput *OTSReservedThroughput) (err *OTSError)

说明:根据表信息创建表。

``table_meta``是``otstype.OTSTableMeta``类的实例,它包含表名和PrimaryKey的schema,
请参考``OTSTableMeta``类的文档。当创建了一个表之后,通常要等待1分钟时间使partition load
完成,才能进行各种操作。
``reserved_throughput``是``otstype.ReservedThroughput``类的实例,表示预留读写吞吐量。

返回:无。
      错误信息。

示例:

table_meta := &OTSTableMeta{
	TableName: "myTable",
	SchemaOfPrimaryKey: OTSSchemaOfPrimaryKey{
		{K: "gid", V: "INTEGER"},
		{K: "uid", V: "INTEGER"},
	},
}

reserved_throughput := &OTSReservedThroughput{
	OTSCapacityUnit{0, 0},
}

ots_err := ots_client.CreateTable(table_meta, reserved_throughput)

func (*OTSClient) DeleteRow

func (o *OTSClient) DeleteRow(table_name string, condition string, primary_key *OTSPrimaryKey) (delete_row_response *OTSDeleteRowResponse, err *OTSError)

说明:删除一行数据。

``table_name``是对应的表名。
``condition``表示执行操作前做条件检查,满足条件才执行,是string的实例。
目前只支持对行的存在性进行检查,检查条件包括:'IGNORE','EXPECT_EXIST'和'EXPECT_NOT_EXIST'。
``primary_key``表示主键,类型为``otstype.OTSPrimaryKey``的实例。

返回:本次操作消耗的CapacityUnit。
      错误信息。

``delete_row_response``为``otstype.OTSDeleteRowResponse``类的实例包含了:
``Consumed``表示消耗的CapacityUnit,是``otstype.OTSCapacityUnit``类的实例。

示例:

primary_key := &OTSPrimaryKey{
	"gid": 1,
	"uid": 101,
}
condition := OTSCondition_IGNORE
delete_row_response, ots_err := ots_client.DeleteRow("myTable", condition, primary_key)

func (*OTSClient) DeleteTable

func (o *OTSClient) DeleteTable(table_name string) (err *OTSError)

说明:根据表名删除表。

``table_name``是对应的表名。

返回:无。
      错误信息。

示例:

ots_client.DeleteTable("myTable")

func (*OTSClient) DescribeTable

func (o *OTSClient) DescribeTable(table_name string) (describe_table_response *OTSDescribeTableResponse, err *OTSError)

说明:获取表的描述信息。

``table_name``是对应的表名。

返回:表的描述信息。
      错误信息。

``describe_table_response``表示表的描述信息,是``otstype.OTSDescribeTableResponse``类的实例。

示例:

describe_response, ots_err := ots_client.DescribeTable("myTable")

func (*OTSClient) GetRange

func (o *OTSClient) GetRange(table_name string, direction string,
	inclusive_start_primary_key *OTSPrimaryKey,
	exclusive_end_primary_key *OTSPrimaryKey,
	columns_to_get *OTSColumnsToGet,
	limit int32) (response_row_list *OTSGetRangeResponse, err *OTSError)

说明:根据范围条件获取多行数据(限制条数5000)。

``table_name``是对应的表名。
``direction``表示范围的方向,字符串格式,取值包括'FORWARD'和'BACKWARD'。
``inclusive_start_primary_key``表示范围的起始主键(在范围内)。
``exclusive_end_primary_key``表示范围的结束主键(不在范围内)。
``columns_to_get``是可选参数,表示要获取的列的名称列表,类型为``otstype.OTSColumnsToGet``;如果为nil,表示获取所有列。
``limit``是可选参数,表示最多读取多少行;如果为0,则没有限制。

返回:符合条件的结果列表。
      错误信息。

``response_row_list``为``otstype.OTSGetRangeResponse``类的实例包含了:
``Consumed``表示消耗的CapacityUnit,是``otstype.OTSCapacityUnit``类的实例。
``NextStartPrimaryKey``表示下次get_range操作的起始点的主健列,类型为``otstype.OTSPrimaryKey``。
``Rows``表示本次操作返回的行数据列表,是``otstype.OTSRows``类的实例。

示例:

// get_range
// 查询区间:[(1, INF_MIN), (4, INF_MAX)),左闭右开。
inclusive_start_primary_key := &OTSPrimaryKey{
	"gid": 1,
	"uid": OTSColumnType_INF_MIN,
}
exclusive_end_primary_key := &OTSPrimaryKey{
	"gid": 4,
	"uid": OTSColumnType_INF_MAX,
}
columns_to_get := &OTSColumnsToGet{
	"gid", "uid", "name", "address", "mobile", "age",
}

// 选择方向
// OTSDirection_FORWARD
// OTSDirection_BACKWARD
response_row_list, ots_err := ots_client.GetRange("myTable", OTSDirection_FORWARD,
	inclusive_start_primary_key, exclusive_end_primary_key, columns_to_get, 100)

func (*OTSClient) GetRow

func (o *OTSClient) GetRow(table_name string, primary_key *OTSPrimaryKey, columns_to_get *OTSColumnsToGet) (get_row_response *OTSGetRowResponse, err *OTSError)

说明:获取一行数据。

``table_name``是对应的表名。
``primary_key``是主键,类型为``otstype.OTSPrimaryKey``。
``columns_to_get``是可选参数,表示要获取的列的名称列表,类型为``otstype.OTSColumnsToGet``;如果填nil,表示获取所有列。

返回:本次操作消耗的CapacityUnit、行数据(包含主键列和属性列)。
      错误信息。

``get_row_response``为``otstype.OTSGetRowResponse``类的实例包含了:
``Consumed``表示消耗的CapacityUnit,是``otstype.OTSCapacityUnit``类的实例。
``Row``表示一行的数据,是``otstype.OTSRow``的实例,也包含了:
``PrimaryKeyColumns``表示主键列,类型为``otstype.OTSPrimaryKey``,如:{"PK0":value0, "PK1":value1}。
``AttributeColumns``表示属性列,类型为``otstype.OTSAttribute``,如:{"COL0":value0, "COL1":value1}。

示例:

primary_key := &OTSPrimaryKey{
	"gid": 1,
	"uid": 101,
}
columns_to_get := &OTSColumnsToGet{
	"name", "address", "age",
}
// columns_to_get = nil // read all
get_row_response, ots_err := ots_client.GetRow("myTable", primary_key, columns_to_get)

func (*OTSClient) ListTable

func (o *OTSClient) ListTable() (table_list *OTSListTableResponse, err *OTSError)

说明:获取所有表名的列表。

返回:表名列表。
      错误信息。

``table_list``表示获取的表名列表,类型为``otstype.OTSListTableResponse``。

示例:

table_list, ots_err := ots_client.ListTable()

func (*OTSClient) PutRow

func (o *OTSClient) PutRow(table_name string, condition string, primary_key *OTSPrimaryKey, attribute_columns *OTSAttribute) (put_row_response *OTSPutRowResponse, err *OTSError)

说明:写入一行数据。返回本次操作消耗的CapacityUnit。

``table_name``是对应的表名。
``condition``表示执行操作前做条件检查,满足条件才执行,是string的实例。
目前只支持对行的存在性进行检查,检查条件包括:'IGNORE','EXPECT_EXIST'和'EXPECT_NOT_EXIST'。
``primary_key``表示主键,类型为``otstype.OTSPrimaryKey``的实例。
``attribute_columns``表示属性列,类型为``otstype.OTSAttribute``的实例。

返回:本次操作消耗的CapacityUnit。
      错误信息。

``put_row_response``为``otstype.OTSGetRowResponse``类的实例包含了:
``Consumed``表示消耗的CapacityUnit,是``otstype.OTSCapacityUnit``类的实例。

示例:

primary_key := &OTSPrimaryKey{
	"gid": 1,
	"uid": 101,
}
attribute_columns := &OTSAttribute{
	"name":    "张三",
	"mobile":  111111111,
	"address": "中国A地",
	"age":     20,
}
condition := OTSCondition_EXPECT_NOT_EXIST
put_row_response, ots_err := ots_client.PutRow("myTable", condition, primary_key, attribute_columns)

func (*OTSClient) Set

func (o *OTSClient) Set(kwargs DictString) *OTSClient

在OTSClinet创建后(既调用了New函数),需要重新修改OTSClinet的参数时 可以调用此函数进行设置,参数使用字典方式,可以使用的字典如下: Debug --> bool EndPoint --> string AccessId --> string AccessKey --> string InstanceName --> string SocketTimeout --> int MaxConnection --> int LoggerName --> string Encoding --> string 注:具体参数意义请查看OTSClinet定义处的注释

func (*OTSClient) String

func (o *OTSClient) String() string

func (*OTSClient) UpdateRow

func (o *OTSClient) UpdateRow(table_name string, condition string, primary_key *OTSPrimaryKey, update_of_attribute_columns *OTSUpdateOfAttribute) (update_row_response *OTSUpdateRowResponse, err *OTSError)

说明:更新一行数据。

``table_name``是对应的表名。
``condition``表示执行操作前做条件检查,满足条件才执行,是string的实例。
目前只支持对行的存在性进行检查,检查条件包括:'IGNORE','EXPECT_EXIST'和'EXPECT_NOT_EXIST'。
``primary_key``表示主键,类型为``otstype.OTSPrimaryKey``的实例。
``update_of_attribute_columns``表示属性列,类型为``otstype.OTSUpdateOfAttribute``的实例,可以包含put和delete操作。其中put是
``otstype.OTSColumnsToPut`` 表示属性列的写入;delete是``otstype.OTSColumnsToDelete``,表示要删除的属性列的列名,
见示例。

返回:本次操作消耗的CapacityUnit。
      错误信息。

``update_row_response``为``otstype.OTSUpdateRowResponse``类的实例包含了:
``Consumed``表示消耗的CapacityUnit,是``otstype.OTSCapacityUnit``类的实例。

示例:

primary_key := &OTSPrimaryKey{
	"gid": 1,
	"uid": 101,
}
update_of_attribute_columns := &OTSUpdateOfAttribute{
	OTSOperationType_PUT: OTSColumnsToPut{
		"name":    "张三丰",
		"address": "中国B地",
	},

	OTSOperationType_DELETE: OTSColumnsToDelete{
		"mobile", "age",
	},
}
condition := OTSCondition_EXPECT_EXIST
update_row_response, ots_err := ots_client.UpdateRow("myTable", condition, primary_key, update_of_attribute_columns)

func (*OTSClient) UpdateTable

func (o *OTSClient) UpdateTable(table_name string, reserved_throughput *OTSReservedThroughput) (update_table_response *OTSUpdateTableResponse, err *OTSError)

说明:更新表属性,目前只支持修改预留读写吞吐量。

``table_name``是对应的表名。
``reserved_throughput``是``otstype.ReservedThroughput``类的实例,表示预留读写吞吐量。

返回:针对该表的预留读写吞吐量的最近上调时间、最近下调时间和当天下调次数。
      错误信息。

``update_table_response``表示更新的结果,是``otstype.OTSUpdateTableResponse``类的实例。

示例:
reserved_throughput := &OTSReservedThroughput{
 OTSCapacityUnit{0, 0},
}

// 每次调整操作的间隔应大于10分钟
// 如果是刚创建表,需要10分钟之后才能调整表的预留读写吞吐量。
update_response, ots_err := ots_client.UpdateTable("myTable", reserved_throughput)

func (*OTSClient) Version

func (o *OTSClient) Version() string

func (*OTSClient) XGetRange

func (o *OTSClient) XGetRange(table_name string, direction string,
	inclusive_start_primary_key *OTSPrimaryKey,
	exclusive_end_primary_key *OTSPrimaryKey,
	columns_to_get *OTSColumnsToGet,
	limit int32) (response_row_lists *OTSGetRangeResponse, err *OTSError)

说明:根据范围条件获取多行数据(无限制)。

``table_name``是对应的表名。
``direction``表示范围的方向,字符串格式,取值包括'FORWARD'和'BACKWARD'。
``inclusive_start_primary_key``表示范围的起始主键(在范围内)。
``exclusive_end_primary_key``表示范围的结束主键(不在范围内)。
``columns_to_get``是可选参数,表示要获取的列的名称列表,类型为``otstype.OTSColumnsToGet``;如果为nil,表示获取所有列。
``limit``是可选参数,表示最多读取多少行;如果为0,则没有限制(limit类型为int32,最大能传值2147483647,调用时最好手动进行限制)。

返回:符合条件的结果列表。
      错误信息。

``response_row_list``为``otstype.OTSGetRangeResponse``类的实例包含了:
``Consumed``表示消耗的CapacityUnit,是``otstype.OTSCapacityUnit``类的实例。
``NextStartPrimaryKey``表示下次get_range操作的起始点的主健列,类型为``otstype.OTSPrimaryKey``。
``Rows``表示本次操作返回的行数据列表,是``otstype.OTSRows``类的实例。

示例:

// x_get_range
// 查询区间:[(1, INF_MIN), (4, INF_MAX)),左闭右开。
inclusive_start_primary_key := &OTSPrimaryKey{
	"gid": 1,
	"uid": OTSColumnType_INF_MIN,
}
exclusive_end_primary_key := &OTSPrimaryKey{
	"gid": 4,
	"uid": OTSColumnType_INF_MAX,
}
columns_to_get := &OTSColumnsToGet{
	"gid", "uid", "name", "address", "mobile", "age",
}

// 选择方向
// OTSDirection_FORWARD
// OTSDirection_BACKWARD
response_row_list, ots_err := ots_client.XGetRange("myTable", OTSDirection_FORWARD,
	inclusive_start_primary_key, exclusive_end_primary_key, columns_to_get, 100)

type OTSClientError

type OTSClientError struct {
	Message    string
	HttpStatus int
}

func (*OTSClientError) Error

func (o *OTSClientError) Error() string

func (*OTSClientError) GetErrorMessage

func (o *OTSClientError) GetErrorMessage() string

func (*OTSClientError) GetHttpStatus

func (o *OTSClientError) GetHttpStatus() int

func (OTSClientError) Log

func (o OTSClientError) Log(enable bool, format string, a ...interface{}) (e error)

func (OTSClientError) Set

func (o OTSClientError) Set(format string, a ...interface{}) (e error)

func (*OTSClientError) SetErrorMessage

func (o *OTSClientError) SetErrorMessage(format string, a ...interface{}) *OTSClientError

func (*OTSClientError) SetHttpStatus

func (o *OTSClientError) SetHttpStatus(status int) *OTSClientError

func (*OTSClientError) String

func (o *OTSClientError) String() string

type OTSError

type OTSError struct {
	ClientError  *OTSClientError
	ServiceError *OTSServiceError
}

func (*OTSError) Error

func (o *OTSError) Error() string

func (OTSError) Log

func (o OTSError) Log(enable bool, format string, a ...interface{}) (e error)

func (OTSError) Set

func (o OTSError) Set(format string, a ...interface{}) (e error)

func (*OTSError) SetClientError

func (o *OTSError) SetClientError(client_err *OTSClientError) *OTSError

func (*OTSError) SetClientMessage

func (o *OTSError) SetClientMessage(format string, a ...interface{}) *OTSError

func (*OTSError) SetServiceError

func (o *OTSError) SetServiceError(service_err *OTSServiceError) *OTSError

func (*OTSError) SetServiceMessage

func (o *OTSError) SetServiceMessage(format string, a ...interface{}) *OTSError

func (*OTSError) String

func (o *OTSError) String() string

type OTSServiceError

type OTSServiceError struct {
	HttpStatus int
	Code       string
	Message    string
	RequestId  string
}

func (*OTSServiceError) Error

func (o *OTSServiceError) Error() string

func (*OTSServiceError) GetErrorCode

func (o *OTSServiceError) GetErrorCode() string

func (*OTSServiceError) GetErrorMessage

func (o *OTSServiceError) GetErrorMessage() string

func (*OTSServiceError) GetHttpStatus

func (o *OTSServiceError) GetHttpStatus() int

func (*OTSServiceError) GetRequestId

func (o *OTSServiceError) GetRequestId() string

func (OTSServiceError) Log

func (o OTSServiceError) Log(enable bool, format string, a ...interface{}) (e error)

func (OTSServiceError) Set

func (o OTSServiceError) Set(format string, a ...interface{}) (e error)

func (*OTSServiceError) SetErrorCode

func (o *OTSServiceError) SetErrorCode(code string) *OTSServiceError

func (*OTSServiceError) SetErrorMessage

func (o *OTSServiceError) SetErrorMessage(format string, a ...interface{}) *OTSServiceError

func (*OTSServiceError) SetHttpStatus

func (o *OTSServiceError) SetHttpStatus(status int) *OTSServiceError

func (*OTSServiceError) SetRequestId

func (o *OTSServiceError) SetRequestId(request_id string) *OTSServiceError

func (*OTSServiceError) String

func (o *OTSServiceError) String() string

type RetryPolicyInterface

type RetryPolicyInterface interface {
	GetRetryDelay(retry_times int, exception *OTSServiceError, api_name string) float64
	ShouldRetry(retry_times int, exception *OTSServiceError, api_name string) bool
}

RetryPolicy 是重试策略的接口,包含2个未实现的方法和它们的参数列表。要实现一个重试策略, 继承这个类并实现它的2个方法。

Directories

Path Synopsis
example for ots2 example for ots2 example for ots2 example for ots2 example for ots2 example for ots2 example for ots2 example for ots2 example for ots2 example for ots2 example for ots2 example for ots2 example for ots2 example for ots2
example for ots2 example for ots2 example for ots2 example for ots2 example for ots2 example for ots2 example for ots2 example for ots2 example for ots2 example for ots2 example for ots2 example for ots2 example for ots2 example for ots2
Base type for golang int,rune int8 ,int16 ,int32 ,int64 byte ,uint8 ,uint16 ,uint32 ,uint64 float32 ,float64 bool string complex128,complex64 metadata for ots2 like python's type, but it's simple
Base type for golang int,rune int8 ,int16 ,int32 ,int64 byte ,uint8 ,uint16 ,uint32 ,uint64 float32 ,float64 bool string complex128,complex64 metadata for ots2 like python's type, but it's simple
Package protobuf is a generated protocol buffer package.
Package protobuf is a generated protocol buffer package.
coder
encoder for ots2 encoder for ots2 encoder for ots2 Implement call func by name of function
encoder for ots2 encoder for ots2 encoder for ots2 Implement call func by name of function
Package urllib is a httplib for ots2
Package urllib is a httplib for ots2

Jump to

Keyboard shortcuts

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