-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jakob Hahn <[email protected]>
- Loading branch information
Showing
10 changed files
with
783 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// The OpenSearch Contributors require contributions made to | ||
// this file be licensed under the Apache-2.0 license or a | ||
// compatible open source license. | ||
// | ||
// Modifications Copyright OpenSearch Contributors. See | ||
// GitHub history for details. | ||
|
||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package opensearchapi | ||
|
||
import ( | ||
"strconv" | ||
"time" | ||
) | ||
|
||
// TemplateCreateParams represents possible parameters for the TemplateCreateReq | ||
type TemplateCreateParams struct { | ||
Create *bool | ||
MasterTimeout time.Duration | ||
ClusterManagerTimeout time.Duration | ||
Order *int | ||
|
||
Pretty bool | ||
Human bool | ||
ErrorTrace bool | ||
} | ||
|
||
func (r TemplateCreateParams) get() map[string]string { | ||
params := make(map[string]string) | ||
|
||
if r.Create != nil { | ||
params["create"] = strconv.FormatBool(*r.Create) | ||
} | ||
|
||
if r.MasterTimeout != 0 { | ||
params["master_timeout"] = formatDuration(r.MasterTimeout) | ||
} | ||
|
||
if r.ClusterManagerTimeout != 0 { | ||
params["cluster_manager_timeout"] = formatDuration(r.ClusterManagerTimeout) | ||
} | ||
|
||
if r.Order != nil { | ||
params["order"] = strconv.FormatInt(int64(*r.Order), 10) | ||
} | ||
|
||
if r.Pretty { | ||
params["pretty"] = "true" | ||
} | ||
|
||
if r.Human { | ||
params["human"] = "true" | ||
} | ||
|
||
if r.ErrorTrace { | ||
params["error_trace"] = "true" | ||
} | ||
|
||
return params | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// The OpenSearch Contributors require contributions made to | ||
// this file be licensed under the Apache-2.0 license or a | ||
// compatible open source license. | ||
// | ||
// Modifications Copyright OpenSearch Contributors. See | ||
// GitHub history for details. | ||
|
||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package opensearchapi | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"net/http" | ||
|
||
"github.com/opensearch-project/opensearch-go/v2" | ||
) | ||
|
||
// TemplateCreateReq represents possible options for the index create request | ||
type TemplateCreateReq struct { | ||
Template string | ||
|
||
Body io.Reader | ||
|
||
Header http.Header | ||
Params TemplateCreateParams | ||
} | ||
|
||
// GetRequest returns the *http.Request that gets executed by the client | ||
func (r TemplateCreateReq) GetRequest() (*http.Request, error) { | ||
return opensearch.BuildRequest( | ||
"PUT", | ||
fmt.Sprintf("/_template/%s", r.Template), | ||
r.Body, | ||
r.Params.get(), | ||
r.Header, | ||
) | ||
} | ||
|
||
// TemplateCreateResp represents the returned struct of the index create response | ||
type TemplateCreateResp struct { | ||
Acknowledged bool `json:"acknowledged"` | ||
response *opensearch.Response | ||
} | ||
|
||
// Inspect returns the Inspect type containing the raw *opensearch.Reponse | ||
func (r TemplateCreateResp) Inspect() Inspect { | ||
return Inspect{Response: r.response} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// The OpenSearch Contributors require contributions made to | ||
// this file be licensed under the Apache-2.0 license or a | ||
// compatible open source license. | ||
// | ||
// Modifications Copyright OpenSearch Contributors. See | ||
// GitHub history for details. | ||
|
||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package opensearchapi | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
// TemplateDeleteParams represents possible parameters for the TemplateDeleteReq | ||
type TemplateDeleteParams struct { | ||
MasterTimeout time.Duration | ||
ClusterManagerTimeout time.Duration | ||
Timeout time.Duration | ||
|
||
Pretty bool | ||
Human bool | ||
ErrorTrace bool | ||
} | ||
|
||
func (r TemplateDeleteParams) get() map[string]string { | ||
params := make(map[string]string) | ||
|
||
if r.MasterTimeout != 0 { | ||
params["master_timeout"] = formatDuration(r.MasterTimeout) | ||
} | ||
|
||
if r.ClusterManagerTimeout != 0 { | ||
params["cluster_manager_timeout"] = formatDuration(r.ClusterManagerTimeout) | ||
} | ||
|
||
if r.Timeout != 0 { | ||
params["timeout"] = formatDuration(r.Timeout) | ||
} | ||
|
||
if r.Pretty { | ||
params["pretty"] = "true" | ||
} | ||
|
||
if r.Human { | ||
params["human"] = "true" | ||
} | ||
|
||
if r.ErrorTrace { | ||
params["error_trace"] = "true" | ||
} | ||
|
||
return params | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// The OpenSearch Contributors require contributions made to | ||
// this file be licensed under the Apache-2.0 license or a | ||
// compatible open source license. | ||
// | ||
// Modifications Copyright OpenSearch Contributors. See | ||
// GitHub history for details. | ||
|
||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package opensearchapi | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/opensearch-project/opensearch-go/v2" | ||
) | ||
|
||
// TemplateDeleteReq represents possible options for the index create request | ||
type TemplateDeleteReq struct { | ||
Template string | ||
|
||
Header http.Header | ||
Params TemplateDeleteParams | ||
} | ||
|
||
// GetRequest returns the *http.Request that gets executed by the client | ||
func (r TemplateDeleteReq) GetRequest() (*http.Request, error) { | ||
return opensearch.BuildRequest( | ||
"DELETE", | ||
fmt.Sprintf("/_template/%s", r.Template), | ||
nil, | ||
r.Params.get(), | ||
r.Header, | ||
) | ||
} | ||
|
||
// TemplateDeleteResp represents the returned struct of the index create response | ||
type TemplateDeleteResp struct { | ||
Acknowledged bool `json:"acknowledged"` | ||
response *opensearch.Response | ||
} | ||
|
||
// Inspect returns the Inspect type containing the raw *opensearch.Reponse | ||
func (r TemplateDeleteResp) Inspect() Inspect { | ||
return Inspect{Response: r.response} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// The OpenSearch Contributors require contributions made to | ||
// this file be licensed under the Apache-2.0 license or a | ||
// compatible open source license. | ||
// | ||
// Modifications Copyright OpenSearch Contributors. See | ||
// GitHub history for details. | ||
|
||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package opensearchapi | ||
|
||
import ( | ||
"strconv" | ||
"time" | ||
) | ||
|
||
// TemplateExistsParams represents possible parameters for the TemplateExistsReq | ||
type TemplateExistsParams struct { | ||
FlatSettings *bool | ||
Local *bool | ||
MasterTimeout time.Duration | ||
ClusterManagerTimeout time.Duration | ||
|
||
Pretty bool | ||
Human bool | ||
ErrorTrace bool | ||
} | ||
|
||
func (r TemplateExistsParams) get() map[string]string { | ||
params := make(map[string]string) | ||
|
||
if r.FlatSettings != nil { | ||
params["flat_settings"] = strconv.FormatBool(*r.FlatSettings) | ||
} | ||
|
||
if r.Local != nil { | ||
params["local"] = strconv.FormatBool(*r.Local) | ||
} | ||
|
||
if r.MasterTimeout != 0 { | ||
params["master_timeout"] = formatDuration(r.MasterTimeout) | ||
} | ||
|
||
if r.ClusterManagerTimeout != 0 { | ||
params["cluster_manager_timeout"] = formatDuration(r.ClusterManagerTimeout) | ||
} | ||
|
||
if r.Pretty { | ||
params["pretty"] = "true" | ||
} | ||
|
||
if r.Human { | ||
params["human"] = "true" | ||
} | ||
|
||
if r.ErrorTrace { | ||
params["error_trace"] = "true" | ||
} | ||
|
||
return params | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// The OpenSearch Contributors require contributions made to | ||
// this file be licensed under the Apache-2.0 license or a | ||
// compatible open source license. | ||
// | ||
// Modifications Copyright OpenSearch Contributors. See | ||
// GitHub history for details. | ||
|
||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package opensearchapi | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/opensearch-project/opensearch-go/v2" | ||
) | ||
|
||
// TemplateExistsReq represents possible options for the index create request | ||
type TemplateExistsReq struct { | ||
Template string | ||
|
||
Header http.Header | ||
Params TemplateExistsParams | ||
} | ||
|
||
// GetRequest returns the *http.Request that gets executed by the client | ||
func (r TemplateExistsReq) GetRequest() (*http.Request, error) { | ||
return opensearch.BuildRequest( | ||
"HEAD", | ||
fmt.Sprintf("/_template/%s", r.Template), | ||
nil, | ||
r.Params.get(), | ||
r.Header, | ||
) | ||
} |
Oops, something went wrong.