|
| 1 | +// |
| 2 | +// DISCLAIMER |
| 3 | +// |
| 4 | +// Copyright 2023 ArangoDB GmbH, Cologne, Germany |
| 5 | +// |
| 6 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +// you may not use this file except in compliance with the License. |
| 8 | +// You may obtain a copy of the License at |
| 9 | +// |
| 10 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +// |
| 12 | +// Unless required by applicable law or agreed to in writing, software |
| 13 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +// See the License for the specific language governing permissions and |
| 16 | +// limitations under the License. |
| 17 | +// |
| 18 | +// Copyright holder is ArangoDB GmbH, Cologne, Germany |
| 19 | + |
| 20 | +package arangodb |
| 21 | + |
| 22 | +import ( |
| 23 | + "context" |
| 24 | + "net/http" |
| 25 | + "strings" |
| 26 | + |
| 27 | + "github.com/pkg/errors" |
| 28 | + |
| 29 | + "github.com/arangodb/go-driver/v2/arangodb/shared" |
| 30 | + "github.com/arangodb/go-driver/v2/connection" |
| 31 | +) |
| 32 | + |
| 33 | +func newAnalyzer(db *database, def AnalyzerDefinition, modifiers ...connection.RequestModifier) *analyzer { |
| 34 | + d := &analyzer{db: db, definition: def, modifiers: append(db.modifiers, modifiers...)} |
| 35 | + |
| 36 | + return d |
| 37 | +} |
| 38 | + |
| 39 | +var _ Analyzer = &analyzer{} |
| 40 | + |
| 41 | +type analyzer struct { |
| 42 | + db *database |
| 43 | + |
| 44 | + definition AnalyzerDefinition |
| 45 | + |
| 46 | + modifiers []connection.RequestModifier |
| 47 | +} |
| 48 | + |
| 49 | +func (a analyzer) Name() string { |
| 50 | + split := strings.Split(a.definition.Name, "::") |
| 51 | + return split[len(split)-1] |
| 52 | +} |
| 53 | + |
| 54 | +func (a analyzer) UniqueName() string { |
| 55 | + return a.definition.Name |
| 56 | +} |
| 57 | + |
| 58 | +func (a analyzer) Type() ArangoSearchAnalyzerType { |
| 59 | + return a.definition.Type |
| 60 | +} |
| 61 | + |
| 62 | +func (a analyzer) Definition() AnalyzerDefinition { |
| 63 | + return a.definition |
| 64 | +} |
| 65 | + |
| 66 | +func (v analyzer) Database() Database { |
| 67 | + return v.db |
| 68 | +} |
| 69 | + |
| 70 | +func (v analyzer) Remove(ctx context.Context, force bool) error { |
| 71 | + url := v.db.url("_api", "analyzer", v.Name()) |
| 72 | + |
| 73 | + reqBody := struct { |
| 74 | + Force bool `json:"force,omitempty"` |
| 75 | + }{ |
| 76 | + Force: force, |
| 77 | + } |
| 78 | + var response struct { |
| 79 | + shared.ResponseStruct `json:",inline"` |
| 80 | + } |
| 81 | + resp, err := connection.CallDelete(ctx, v.db.connection(), url, &response, connection.WithBody(reqBody)) |
| 82 | + if err != nil { |
| 83 | + return errors.WithStack(err) |
| 84 | + } |
| 85 | + |
| 86 | + switch code := resp.Code(); code { |
| 87 | + case http.StatusOK: |
| 88 | + return nil |
| 89 | + default: |
| 90 | + return response.AsArangoErrorWithCode(code) |
| 91 | + } |
| 92 | +} |
0 commit comments