search

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: Apache-2.0 Imports: 5 Imported by: 56

Documentation

Overview

Example
// API Keys
token := os.Getenv("SAKURACLOUD_ACCESS_TOKEN")
secret := os.Getenv("SAKURACLOUD_ACCESS_TOKEN_SECRET")
zone := os.Getenv("SAKURACLOUD_ZONE")

// API Client
caller := iaas.NewClient(token, secret)
serverOp := iaas.NewArchiveOp(caller)

// ******************************************
// Find
// ******************************************

// 名称に"Example"を含むサーバを検索
condition := &iaas.FindCondition{
	Filter: search.Filter{
		search.Key("Name"): search.PartialMatch("Example"),
	},
}
searched, err := serverOp.Find(context.Background(), zone, condition)
if err != nil {
	panic(err)
}

fmt.Printf("searched: %#v", searched)

// 以下の条件で検索
//   - 名称に"test"と"example"を含む
//   - ゾーンが"is1a"または"is1b"
//   - 作成日時が1週間以上前
condition = &iaas.FindCondition{
	Filter: search.Filter{
		search.Key("Name"):                               search.AndEqual("test", "example"),
		search.Key("Zone.Name"):                          search.OrEqual("is1a", "is1b"),
		search.KeyWithOp("CreatedAt", search.OpLessThan): time.Now().Add(-7 * 24 * time.Hour),
	},
}
searched, err = serverOp.Find(context.Background(), zone, condition)
if err != nil {
	panic(err)
}

fmt.Printf("searched: %#v", searched)
Output:

Index

Examples

Constants

View Source
const (
	// OpEqual =
	OpEqual = ComparisonOperator("")
	// OpGreaterThan >
	OpGreaterThan = ComparisonOperator(">")
	// OpGreaterEqual >=
	OpGreaterEqual = ComparisonOperator(">=")
	// OpLessThan <
	OpLessThan = ComparisonOperator("<")
	// OpLessEqual <=
	OpLessEqual = ComparisonOperator("<=")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ComparisonOperator

type ComparisonOperator string

ComparisonOperator フィルター比較演算子

type EqualExpression

type EqualExpression struct {
	Op         LogicalOperator
	Conditions []interface{}
}

EqualExpression Equalで比較する際の条件

func AndEqual

func AndEqual(conditions ...string) *EqualExpression

AndEqual 部分一致(Partial Match)かつAND条件を示すEqualFilterを作成

func ExactMatch

func ExactMatch(conditions ...string) *EqualExpression

ExactMatch 完全一致(Partial Match)かつOR条件を示すEqualFilterを作成

OrEqualのエイリアス

func OrEqual

func OrEqual(conditions ...interface{}) *EqualExpression

OrEqual 完全一致(Exact Match)かつOR条件を示すEqualFilterを作成

func PartialMatch

func PartialMatch(conditions ...string) *EqualExpression

PartialMatch 部分一致(Partial Match)かつAND条件を示すEqualFilterを作成

AndEqualのエイリアス

func TagsAndEqual

func TagsAndEqual(tags ...string) *EqualExpression

TagsAndEqual タグのAND検索

func (*EqualExpression) MarshalJSON

func (eq *EqualExpression) MarshalJSON() ([]byte, error)

MarshalJSON .

type Filter

type Filter map[FilterKey]interface{}

Filter 検索系APIでの検索条件

Note: libsacloudではリクエスト時に`X-Sakura-Bigint-As-Int`ヘッダを指定することで 文字列で表されているBitintをintとして取得している。 このため、libsacloud側では数値型に見える項目でもさくらのクラウド側では文字列となっている場合がある。 これらの項目ではOpEqual以外の演算子は利用できない。 また、これらの項目でスカラ値を検索条件に与えた場合は部分一致ではなく完全一致となるため注意。

func (Filter) MarshalJSON

func (f Filter) MarshalJSON() ([]byte, error)

MarshalJSON 検索系APIコール時のGETパラメータを出力するためのjson.Marshaler実装

type FilterKey

type FilterKey struct {
	// フィールド名
	Field string
	// 演算子
	Op ComparisonOperator
}

FilterKey 検索条件(Filter)のキー

func Key

func Key(field string) FilterKey

Key キーの作成

func KeyWithOp

func KeyWithOp(field string, op ComparisonOperator) FilterKey

KeyWithOp 演算子を指定してキーを作成

func (*FilterKey) String

func (k *FilterKey) String() string

String Keyの文字列表現

type LogicalOperator

type LogicalOperator int

LogicalOperator フィルター論理演算子

const (
	// OpAnd AND
	OpAnd LogicalOperator = iota
	// OpOr OR
	OpOr
)

type SortKey

type SortKey struct {
	Key   string
	Order SortOrder
}

SortKey ソート順指定対象のフィールド名

func SortKeyAsc

func SortKeyAsc(key string) SortKey

SortKeyAsc 昇順ソートキー

func SortKeyDesc

func SortKeyDesc(key string) SortKey

SortKeyDesc 降順ソートキー

func (SortKey) MarshalJSON

func (k SortKey) MarshalJSON() ([]byte, error)

MarshalJSON キーの文字列表現

type SortKeys

type SortKeys []SortKey

SortKeys ソート順指定

type SortOrder

type SortOrder int

SortOrder ソート順

const (
	// SortAsc 昇順(デフォルト)
	SortAsc SortOrder = iota
	// SortDesc 降順
	SortDesc
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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