|
| 1 | +// |
| 2 | +// DISCLAIMER |
| 3 | +// |
| 4 | +// Copyright 2024 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 | + |
| 21 | +package examples |
| 22 | + |
| 23 | +import ( |
| 24 | + "context" |
| 25 | + "log" |
| 26 | + |
| 27 | + "github.com/arangodb/go-driver/v2/arangodb" |
| 28 | + "github.com/arangodb/go-driver/v2/connection" |
| 29 | +) |
| 30 | + |
| 31 | +// Example503Retry shows how to create a client with round-robin endpoint list and retry on 503 |
| 32 | +func Example503Retry() { |
| 33 | + // Create an HTTP connection to the database |
| 34 | + endpoint := connection.NewRoundRobinEndpoints([]string{"http://localhost:8529"}) |
| 35 | + conn := connection.NewHttp2Connection(connection.DefaultHTTP2ConfigurationWrapper(endpoint, true)) |
| 36 | + |
| 37 | + // Add authentication |
| 38 | + auth := connection.NewBasicAuth("root", "") |
| 39 | + err := conn.SetAuthentication(auth) |
| 40 | + if err != nil { |
| 41 | + log.Fatalf("Failed to set authentication: %v", err) |
| 42 | + } |
| 43 | + |
| 44 | + // Add retry on 503 |
| 45 | + retries := 5 |
| 46 | + conn = connection.RetryOn503(conn, retries) |
| 47 | + |
| 48 | + // Create a client |
| 49 | + client := arangodb.NewClient(conn) |
| 50 | + |
| 51 | + // Ask the version of the server |
| 52 | + versionInfo, err := client.Version(context.Background()) |
| 53 | + if err != nil { |
| 54 | + log.Printf("Failed to get version info: %v", err) |
| 55 | + } |
| 56 | + log.Printf("Database has version '%s' and license '%s'\n", versionInfo.Version, versionInfo.License) |
| 57 | +} |
0 commit comments