Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

検索系API #266

Merged
merged 12 commits into from
Jul 22, 2019
Merged

検索系API #266

merged 12 commits into from
Jul 22, 2019

Conversation

yamamoto-febc
Copy link
Member

fixes #264

@yamamoto-febc yamamoto-febc added this to the v2.0.0 milestone Jul 20, 2019
- Rename from Accessor to MethodDesc
- Supports arguments and results
- Generate method codes on models
@yamamoto-febc
Copy link
Member Author

(based on e6b3f15)

現時点では以下のようにメソッドを呼び出してフィルタを設定する。

	serverOp := sacloud.NewServerOp(singletonAPICaller())

	// 検索条件の組み立て
	condition := &sacloud.FindCondition{}
	condition.SetNumericFilter("ServerPlan.CPU", accessor.OpEqual, 2)

	searched, err := serverOp.Find(context.Background(), zone, condition)

これを宣言的に行いたい。

	// イメージ
	condition := &sacloud.FindCondition{
		Filters: []*sacloud.ServerFilter{
			{
				Key: sacloud.ServerFilters.CPU,
				Op: accessor.OpEqual,
			},
		},
	}

@yamamoto-febc
Copy link
Member Author

(based on 5372dac)

sacloud/searchパッケージを導入する。
これにより検索条件の指定を以下のように宣言的に行えるようになる。

// 以下の条件で検索
//   - 名称に"test"と"example"を含む
//   - ゾーンが"is1a"または"is1b"
//   - 作成日時が1週間以上前
condition := &sacloud.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)

@yamamoto-febc
Copy link
Member Author

検索時に指定するキーはひとまずsacloud/search/keys配下に定数として使いそうな項目のみ保持しておく。

@yamamoto-febc yamamoto-febc mentioned this pull request Jul 22, 2019
40 tasks
@yamamoto-febc yamamoto-febc marked this pull request as ready for review July 22, 2019 01:13
@yamamoto-febc yamamoto-febc merged commit ebee9a1 into sacloud:v2-dev Jul 22, 2019
@yamamoto-febc yamamoto-febc deleted the api/find branch July 22, 2019 01:17
yamamoto-febc added a commit that referenced this pull request Jul 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant