├── v2 ├── Makefile ├── version │ ├── VERSION │ └── version-driver.go ├── arangodb │ ├── server_mode.go │ ├── graph_collection.go │ ├── transaction.go │ ├── client.go │ ├── collection_documents.go │ ├── database_analyzer.go │ ├── database.go │ ├── collection_opts_schema.go │ ├── database_transaction.go │ ├── analyzer.go │ ├── client_server_info_impl_test.go │ ├── client_impl.go │ ├── database_opts.go │ ├── database_collection.go │ ├── database_view.go │ └── asyncjob.go ├── utils │ ├── jwt │ │ └── doc.go │ ├── endpoints.go │ └── type.go ├── connection │ ├── auth.go │ ├── auth_basic_impl.go │ ├── connection_http_content-type.go │ ├── data_stream.go │ ├── auth_header_impl.go │ ├── endpoint.go │ ├── endpoints_round_robin.go │ ├── connection_http.go │ ├── connection_http_response.go │ ├── data_array.go │ ├── error.go │ ├── connection_http2.go │ ├── connection_http_response_test.go │ ├── decoder_test.go │ ├── modifiers.go │ └── context.go ├── go.mod ├── tests │ ├── main_test.go │ ├── errors_test.go │ ├── decoder_test.go │ ├── pool_test.go │ ├── context_test.go │ ├── client_server_info_test.go │ ├── admin_license_test.go │ ├── utils_retry_test.go │ ├── documents_def_test.go │ ├── utils_client_test.go │ └── graph_helper_test.go ├── log │ ├── log.go │ ├── local.go │ ├── zerolog.go │ └── stdout.go ├── README.md └── examples │ ├── example_client_basic_test.go │ ├── example_client_roundrobin_test.go │ ├── example_client_retry_on_503_test.go │ └── example_client_maglev_test.go ├── VERSION ├── CODEOWNERS ├── .gitignore ├── Dockerfile.debug ├── HEADER ├── util ├── type.go ├── doc.go ├── connection │ └── wrappers │ │ ├── connection_logger_id.go │ │ └── async │ │ └── async_errors.go └── endpoints.go ├── go.mod ├── test ├── jwt.sh ├── clean.go ├── client_connection_http2_test.go ├── timestamp_output │ └── timestamp_output.go ├── doc.go ├── client_connection_http_test.go ├── server_info_test.go ├── server_license_test.go ├── check_test.go ├── json_agency_config_parse_leader_id │ └── json_agency_config_parse_leader_id.go ├── server_metrics_test.go ├── types.go ├── context_test.go ├── on_failure.sh └── wrapper_test.go ├── vst ├── protocol │ ├── doc.go │ ├── protocol_version.go │ └── message_store.go └── doc.go ├── version-driver.go ├── client_foxx_impl.go ├── cluster └── doc.go ├── client_replication_impl.go ├── client_replication.go ├── edge.go ├── encode.go ├── encode-go_1_8.go ├── encode_test.go ├── client_cluster.go ├── doc.go ├── content_type.go ├── client_foxx.go ├── agency ├── doc.go ├── lock_errors.go ├── error.go └── operation_test.go ├── examples ├── example_error_test.go ├── main_test.go ├── example_context_test.go ├── example_create_documents_test.go └── example_create_document_test.go ├── protocol.go ├── .golangci.yaml ├── client_cluster_impl.go ├── jwt └── doc.go ├── database_collections_schema.go ├── MAINTAINERS.md ├── .vscode └── settings.json ├── view_arangosearch_alias.go ├── view.go ├── client_test.go ├── README.md ├── meta.go ├── http ├── doc.go ├── mergeObject.go └── authentication_test.go ├── context_read.go ├── client_users.go ├── foxx.go ├── view_arangosearch_impl.go ├── asyncjob.go └── database_views.go /v2/Makefile: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /VERSION: -------------------------------------------------------------------------------- 1 | 1.6.9+git -------------------------------------------------------------------------------- /v2/version/VERSION: -------------------------------------------------------------------------------- 1 | 2.1.6+git -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | # This team will own the entire repository 2 | * @arangodb/team-golang 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | #Go packages 2 | .gobuild 3 | 4 | #Temporary tests files 5 | .tmp 6 | 7 | #IDE's files 8 | .idea 9 | 10 | #Vendor files 11 | vendor 12 | 13 | # Helper files 14 | debug/ 15 | *.log 16 | 17 | # direnv files 18 | .envrc 19 | 20 | # vim files 21 | .DS_Store -------------------------------------------------------------------------------- /Dockerfile.debug: -------------------------------------------------------------------------------- 1 | ARG GOVERSION 2 | FROM golang:${GOVERSION} as builder 3 | 4 | ARG GOTOOLCHAIN=local 5 | ENV GOTOOLCHAIN=${GOTOOLCHAIN} 6 | ARG TESTS_DIRECTORY 7 | ARG TESTS_ROOT_PATH="." 8 | 9 | RUN go install github.com/go-delve/delve/cmd/dlv@latest 10 | 11 | WORKDIR /go/src/github.com/arangodb/go-driver 12 | ADD . /go/src/github.com/arangodb/go-driver/ 13 | 14 | RUN cd $TESTS_ROOT_PATH && go test -gcflags "all=-N -l" -c -o /test_debug.test $TESTS_DIRECTORY 15 | -------------------------------------------------------------------------------- /HEADER: -------------------------------------------------------------------------------- 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 -------------------------------------------------------------------------------- /v2/arangodb/server_mode.go: -------------------------------------------------------------------------------- 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 | 21 | package arangodb 22 | -------------------------------------------------------------------------------- /v2/utils/jwt/doc.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2018 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 | // Author Ewout Prangsma 21 | // 22 | 23 | package jwt 24 | -------------------------------------------------------------------------------- /util/type.go: -------------------------------------------------------------------------------- 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 util 22 | 23 | func NewType[T any](val T) *T { 24 | return &val 25 | } 26 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/arangodb/go-driver 2 | 3 | go 1.24.0 4 | 5 | toolchain go1.24.9 6 | 7 | require ( 8 | github.com/arangodb/go-velocypack v0.0.0-20200318135517-5af53c29c67e 9 | github.com/coreos/go-iptables v0.8.0 10 | github.com/coreos/go-semver v0.3.1 11 | github.com/dchest/uniuri v1.2.0 12 | github.com/golang-jwt/jwt/v5 v5.3.0 13 | github.com/google/uuid v1.6.0 14 | github.com/pkg/errors v0.9.1 15 | github.com/rs/zerolog v1.34.0 16 | github.com/stretchr/testify v1.11.1 17 | golang.org/x/net v0.46.0 18 | golang.org/x/text v0.30.0 19 | ) 20 | 21 | require ( 22 | github.com/davecgh/go-spew v1.1.1 // indirect 23 | github.com/mattn/go-colorable v0.1.13 // indirect 24 | github.com/mattn/go-isatty v0.0.20 // indirect 25 | github.com/pmezard/go-difflib v1.0.0 // indirect 26 | golang.org/x/sys v0.37.0 // indirect 27 | gopkg.in/yaml.v3 v3.0.1 // indirect 28 | ) 29 | -------------------------------------------------------------------------------- /test/jwt.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | IAT=$(date -u +%s) 4 | EXP=$(($IAT+36000)) 5 | 6 | HEADER='{"alg":"HS256","typ":"JWT"}' 7 | PAYLOAD1='{"exp": ' 8 | PAYLOAD2=', "iat":' 9 | PAYLOAD3=', "iss":"arangodb","server_id":"arangodb"}' 10 | PAYLOAD="$PAYLOAD1$EXP$PAYLOAD2$IAT$PAYLOAD3" 11 | 12 | PAYLOAD='{"iss":"arangodb","server_id":"arangodb"}' 13 | 14 | jwt_header=$(echo $(echo -n '{"alg":"HS256","typ":"JWT"}' | base64) | sed 's/ /_/g' | sed 's/+/-/g' | sed -E s/=+$//) 15 | payload=$(echo $(echo -n "${PAYLOAD}" | base64) | sed 's/ /_/g' | sed 's/+/-/g' | sed -E s/=+$//) 16 | 17 | hexsecret=$(echo -n "$JWTSECRET" | xxd -p | paste -sd "") 18 | hmac_signature=$(echo $(echo -n "${jwt_header}.${payload}" | openssl dgst -sha256 -mac HMAC -macopt hexkey:$hexsecret -binary | base64 ) | sed 's/\//_/g' | sed 's/+/-/g' | sed -E s/=+$//) 19 | 20 | # Create the full token 21 | jwt="${jwt_header}.${payload}.${hmac_signature}" 22 | echo $jwt -------------------------------------------------------------------------------- /v2/connection/auth.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2020 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 | // Author Adam Janikowski 21 | // 22 | 23 | package connection 24 | 25 | type Authentication interface { 26 | RequestModifier(r Request) error 27 | } 28 | -------------------------------------------------------------------------------- /vst/protocol/doc.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2018 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 | // Author Ewout Prangsma 21 | // 22 | 23 | /* 24 | Package protocol implements the VelocyStream protocol (it is not intended to be used directly). 25 | */ 26 | package protocol 27 | -------------------------------------------------------------------------------- /version-driver.go: -------------------------------------------------------------------------------- 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 | 21 | package driver 22 | 23 | import _ "embed" 24 | 25 | //go:embed VERSION 26 | var versionString string 27 | 28 | func DriverVersion() string { 29 | return versionString 30 | } 31 | -------------------------------------------------------------------------------- /util/doc.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2018 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 | // Author Ewout Prangsma 21 | // 22 | 23 | /* 24 | Package util provides some helper methods for the go-driver (it is unlikely that you need this package directly). 25 | */ 26 | package util 27 | -------------------------------------------------------------------------------- /client_foxx_impl.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2020 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 | // Author Tomasz Mielech 21 | // 22 | 23 | package driver 24 | 25 | // Foxx provides access to foxx services specific operations. 26 | func (c *client) Foxx() FoxxService { 27 | return c 28 | } 29 | -------------------------------------------------------------------------------- /v2/version/version-driver.go: -------------------------------------------------------------------------------- 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 | 21 | package version 22 | 23 | import _ "embed" 24 | 25 | //go:embed VERSION 26 | var versionString string 27 | 28 | func DriverVersion() string { 29 | return versionString 30 | } 31 | -------------------------------------------------------------------------------- /cluster/doc.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2018 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 | // Author Ewout Prangsma 21 | // 22 | 23 | /* 24 | Package cluster implements a driver.Connection that provides cluster failover support (it is not intended to be used directly). 25 | */ 26 | package cluster 27 | -------------------------------------------------------------------------------- /client_replication_impl.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2018 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 | // Author Ewout Prangsma 21 | // 22 | 23 | package driver 24 | 25 | // Replication provides access to replication specific operations. 26 | func (c *client) Replication() Replication { 27 | return c 28 | } 29 | -------------------------------------------------------------------------------- /v2/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/arangodb/go-driver/v2 2 | 3 | go 1.24.0 4 | 5 | toolchain go1.24.9 6 | 7 | require ( 8 | github.com/arangodb/go-velocypack v0.0.0-20200318135517-5af53c29c67e 9 | github.com/golang-jwt/jwt/v5 v5.3.0 10 | github.com/google/uuid v1.6.0 11 | github.com/kkdai/maglev v0.2.0 12 | github.com/pkg/errors v0.9.1 13 | github.com/rs/zerolog v1.34.0 14 | github.com/stretchr/testify v1.11.1 15 | golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546 16 | golang.org/x/net v0.46.0 17 | golang.org/x/text v0.30.0 18 | ) 19 | 20 | require ( 21 | github.com/davecgh/go-spew v1.1.1 // indirect 22 | github.com/dchest/siphash v1.2.3 // indirect 23 | github.com/kr/pretty v0.2.0 // indirect 24 | github.com/mattn/go-colorable v0.1.13 // indirect 25 | github.com/mattn/go-isatty v0.0.20 // indirect 26 | github.com/pmezard/go-difflib v1.0.0 // indirect 27 | golang.org/x/sys v0.37.0 // indirect 28 | gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect 29 | gopkg.in/yaml.v3 v3.0.1 // indirect 30 | ) 31 | -------------------------------------------------------------------------------- /vst/protocol/protocol_version.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2017 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 | // Author Ewout Prangsma 21 | // 22 | 23 | package protocol 24 | 25 | // Version indicates the version of the Velocystream protocol 26 | type Version int 27 | 28 | const ( 29 | Version1_0 Version = iota // VST 1.0 30 | Version1_1 // VST 1.1 31 | ) 32 | -------------------------------------------------------------------------------- /util/connection/wrappers/connection_logger_id.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2021 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 | // Author Adam Janikowski 21 | // 22 | 23 | package wrappers 24 | 25 | import "github.com/google/uuid" 26 | 27 | type ID string 28 | 29 | func NewID() ID { 30 | return ID(uuid.New().String()) 31 | } 32 | 33 | func (i ID) String() string { 34 | return string(i) 35 | } 36 | -------------------------------------------------------------------------------- /client_replication.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2018 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 | // Author Ewout Prangsma 21 | // 22 | 23 | package driver 24 | 25 | // ClientReplication provides methods needed to access replication functionality from a client. 26 | type ClientReplication interface { 27 | // Replication provides access to replication specific operations. 28 | Replication() Replication 29 | } 30 | -------------------------------------------------------------------------------- /v2/tests/main_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2020 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 | // Author Adam Janikowski 21 | // 22 | 23 | package tests 24 | 25 | import ( 26 | "github.com/rs/zerolog" 27 | "github.com/rs/zerolog/log" 28 | 29 | log2 "github.com/arangodb/go-driver/v2/log" 30 | ) 31 | 32 | func init() { 33 | log.Logger = log.Logger.Level(zerolog.WarnLevel) 34 | 35 | log2.SetZeroLogLogger(log.Logger) 36 | } 37 | -------------------------------------------------------------------------------- /v2/arangodb/graph_collection.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2025 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 arangodb 22 | 23 | import ( 24 | "context" 25 | ) 26 | 27 | type GraphCollection interface { 28 | Name() string 29 | Database() Database 30 | 31 | // Count fetches the number of document in the collection. 32 | Count(ctx context.Context) (int64, error) 33 | 34 | CollectionDocuments 35 | CollectionIndexes 36 | } 37 | -------------------------------------------------------------------------------- /v2/tests/errors_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2020 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 | // Author Adam Janikowski 21 | // 22 | 23 | package tests 24 | 25 | import ( 26 | "testing" 27 | 28 | "github.com/stretchr/testify/require" 29 | ) 30 | 31 | func ExpectPanic(t testing.TB, f func(), expected interface{}) { 32 | defer func() { 33 | o := recover() 34 | require.NotNil(t, o, "Panic did not occur") 35 | require.Equal(t, expected, o) 36 | }() 37 | f() 38 | } 39 | -------------------------------------------------------------------------------- /v2/log/log.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2020 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 | // Author Adam Janikowski 21 | // 22 | 23 | package log 24 | 25 | type Log interface { 26 | Trace(msg string) 27 | Tracef(msg string, args ...interface{}) 28 | 29 | Debug(msg string) 30 | Debugf(msg string, args ...interface{}) 31 | 32 | Info(msg string) 33 | Infof(msg string, args ...interface{}) 34 | 35 | Error(err error, msg string) 36 | Errorf(err error, msg string, args ...interface{}) 37 | } 38 | -------------------------------------------------------------------------------- /test/clean.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2018 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 | // Author Ewout Prangsma 21 | // 22 | 23 | package test 24 | 25 | import ( 26 | "context" 27 | "testing" 28 | 29 | "github.com/stretchr/testify/require" 30 | ) 31 | 32 | type remove interface { 33 | Remove(ctx context.Context) error 34 | } 35 | 36 | func clean(t *testing.T, ctx context.Context, col remove) { 37 | if col == nil { 38 | return 39 | } 40 | 41 | require.NoError(t, col.Remove(ctx)) 42 | } 43 | -------------------------------------------------------------------------------- /v2/connection/auth_basic_impl.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2020 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 | // Author Adam Janikowski 21 | // 22 | 23 | package connection 24 | 25 | import ( 26 | "encoding/base64" 27 | "fmt" 28 | ) 29 | 30 | func NewBasicAuth(username, password string) Authentication { 31 | auth := fmt.Sprintf("%s:%s", username, password) 32 | encoded := base64.StdEncoding.EncodeToString([]byte(auth)) 33 | 34 | return NewHeaderAuth("Authorization", "Basic %s", encoded) 35 | } 36 | -------------------------------------------------------------------------------- /edge.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2017 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 | // Author Ewout Prangsma 21 | // 22 | 23 | package driver 24 | 25 | // EdgeDocument is a minimal document for use in edge collection. 26 | // You can use this in your own edge document structures completely use your own. 27 | // If you use your own, make sure to include a `_from` and `_to` field. 28 | type EdgeDocument struct { 29 | From DocumentID `json:"_from,omitempty"` 30 | To DocumentID `json:"_to,omitempty"` 31 | } 32 | -------------------------------------------------------------------------------- /test/client_connection_http2_test.go: -------------------------------------------------------------------------------- 1 | //go:build http2 2 | // +build http2 3 | 4 | // 5 | // DISCLAIMER 6 | // 7 | // Copyright 2017 ArangoDB GmbH, Cologne, Germany 8 | // 9 | // Licensed under the Apache License, Version 2.0 (the "License"); 10 | // you may not use this file except in compliance with the License. 11 | // You may obtain a copy of the License at 12 | // 13 | // http://www.apache.org/licenses/LICENSE-2.0 14 | // 15 | // Unless required by applicable law or agreed to in writing, software 16 | // distributed under the License is distributed on an "AS IS" BASIS, 17 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | // See the License for the specific language governing permissions and 19 | // limitations under the License. 20 | // 21 | // Copyright holder is ArangoDB GmbH, Cologne, Germany 22 | // 23 | // Author Adam Janikowski 24 | // 25 | 26 | package test 27 | 28 | import ( 29 | "crypto/tls" 30 | "net/http" 31 | 32 | "golang.org/x/net/http2" 33 | ) 34 | 35 | func NewConnectionTransport() http.RoundTripper { 36 | return &http2.Transport{ 37 | TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, 38 | AllowHTTP: true, 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /v2/utils/endpoints.go: -------------------------------------------------------------------------------- 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 utils 22 | 23 | import "strings" 24 | 25 | var ( 26 | urlFixer = strings.NewReplacer( 27 | "tcp://", "http://", 28 | "ssl://", "https://", 29 | ) 30 | ) 31 | 32 | // FixupEndpointURLScheme changes endpoint URL schemes used by arangod to ones used by go. 33 | // E.g. "tcp://localhost:8529" -> "http://localhost:8529" 34 | func FixupEndpointURLScheme(u string) string { 35 | return urlFixer.Replace(u) 36 | } 37 | -------------------------------------------------------------------------------- /encode.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2017 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 | // Author Ewout Prangsma 21 | // 22 | 23 | //go:build !go1.8 24 | // +build !go1.8 25 | 26 | package driver 27 | 28 | import "net/url" 29 | 30 | // Escape the given value for use in a URL path. 31 | func pathEscape(s string) string { 32 | return url.QueryEscape(s) 33 | } 34 | 35 | // pathUnescape unescapes the given value for use in a URL path. 36 | func pathUnescape(s string) string { 37 | r, _ := url.QueryUnescape(s) 38 | return r 39 | } 40 | -------------------------------------------------------------------------------- /encode-go_1_8.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2017 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 | // Author Ewout Prangsma 21 | // 22 | 23 | //go:build go1.8 24 | // +build go1.8 25 | 26 | package driver 27 | 28 | import "net/url" 29 | 30 | // pathEscape the given value for use in a URL path. 31 | func pathEscape(s string) string { 32 | return url.PathEscape(s) 33 | } 34 | 35 | // pathUnescape unescapes the given value for use in a URL path. 36 | func pathUnescape(s string) string { 37 | r, _ := url.PathUnescape(s) 38 | return r 39 | } 40 | -------------------------------------------------------------------------------- /v2/arangodb/transaction.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2020 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 | // Author Adam Janikowski 21 | // 22 | 23 | package arangodb 24 | 25 | import ( 26 | "context" 27 | ) 28 | 29 | type Transaction interface { 30 | ID() TransactionID 31 | 32 | Status(ctx context.Context) (TransactionStatusRecord, error) 33 | Commit(ctx context.Context, opts *CommitTransactionOptions) error 34 | Abort(ctx context.Context, opts *AbortTransactionOptions) error 35 | 36 | DatabaseCollection 37 | DatabaseQuery 38 | } 39 | -------------------------------------------------------------------------------- /v2/connection/connection_http_content-type.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2021-2025 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 connection 22 | 23 | const ( 24 | PlainText = "text/plain" 25 | ApplicationOctetStream = "application/octet-stream" 26 | ApplicationZip = "application/zip" 27 | 28 | ApplicationJSON = "application/json" 29 | 30 | // ApplicationVPack is the content type for VelocyPack 31 | // 32 | // Deprecated: Use JSON instead 33 | // ApplicationVPack = "application/x-velocypack" 34 | ) 35 | -------------------------------------------------------------------------------- /v2/arangodb/client.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2020-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 | 21 | package arangodb 22 | 23 | import ( 24 | "github.com/arangodb/go-driver/v2/connection" 25 | ) 26 | 27 | type Client interface { 28 | // Connection returns current Driver Connection 29 | Connection() connection.Connection 30 | 31 | Requests 32 | 33 | ClientDatabase 34 | ClientUsers 35 | ClientServerInfo 36 | ClientAdmin 37 | ClientAsyncJob 38 | ClientFoxx 39 | ClientTasks 40 | ClientReplication 41 | ClientAccessTokens 42 | } 43 | -------------------------------------------------------------------------------- /util/endpoints.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2017 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 | // Author Ewout Prangsma 21 | // 22 | 23 | package util 24 | 25 | import "strings" 26 | 27 | var ( 28 | urlFixer = strings.NewReplacer( 29 | "tcp://", "http://", 30 | "ssl://", "https://", 31 | ) 32 | ) 33 | 34 | // FixupEndpointURLScheme changes endpoint URL schemes used by arangod to ones used by go. 35 | // E.g. "tcp://localhost:8529" -> "http://localhost:8529" 36 | func FixupEndpointURLScheme(u string) string { 37 | return urlFixer.Replace(u) 38 | } 39 | -------------------------------------------------------------------------------- /v2/arangodb/collection_documents.go: -------------------------------------------------------------------------------- 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 | 21 | package arangodb 22 | 23 | import ( 24 | "context" 25 | ) 26 | 27 | type CollectionDocuments interface { 28 | // DocumentExists checks if a document with given key exists in the collection. 29 | DocumentExists(ctx context.Context, key string) (bool, error) 30 | 31 | CollectionDocumentCreate 32 | CollectionDocumentRead 33 | CollectionDocumentUpdate 34 | CollectionDocumentReplace 35 | CollectionDocumentDelete 36 | 37 | CollectionDocumentImport 38 | } 39 | -------------------------------------------------------------------------------- /encode_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2017 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 | // Author Ewout Prangsma 21 | // 22 | 23 | package driver 24 | 25 | import "testing" 26 | 27 | func TestPathEscape(t *testing.T) { 28 | tests := map[string]string{ // Input : Expected-Output 29 | "abc": "abc", 30 | "The Donald": "The%20Donald", 31 | } 32 | for input, expected := range tests { 33 | result := pathEscape(input) 34 | if result != expected { 35 | t.Errorf("pathEscapse failed for '%s': Expected '%s', got '%s'", input, expected, result) 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /v2/connection/data_stream.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2020 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 | // Author Adam Janikowski 21 | // 22 | 23 | package connection 24 | 25 | import ( 26 | "io" 27 | ) 28 | 29 | func deferCloser(closer io.ReadCloser) error { 30 | return closer.Close() 31 | } 32 | 33 | func dropBodyData(closer io.ReadCloser) error { 34 | defer deferCloser(closer) 35 | 36 | b := make([]byte, 1024) 37 | for { 38 | _, err := closer.Read(b) 39 | if err != nil { 40 | if err == io.EOF { 41 | return nil 42 | } 43 | 44 | return err 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /client_cluster.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2017 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 | // Author Ewout Prangsma 21 | // 22 | 23 | package driver 24 | 25 | import "context" 26 | 27 | // ClientCluster provides methods needed to access cluster functionality from a client. 28 | type ClientCluster interface { 29 | // Cluster provides access to cluster wide specific operations. 30 | // To use this interface, an ArangoDB cluster is required. 31 | // If this method is a called without a cluster, a PreconditionFailed error is returned. 32 | Cluster(ctx context.Context) (Cluster, error) 33 | } 34 | -------------------------------------------------------------------------------- /test/timestamp_output/timestamp_output.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2025 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 main 22 | 23 | import ( 24 | "bufio" 25 | "fmt" 26 | "os" 27 | "time" 28 | ) 29 | 30 | func main() { 31 | scanner := bufio.NewScanner(os.Stdin) 32 | for scanner.Scan() { 33 | now := time.Now() 34 | nsec := now.Nanosecond() 35 | 36 | // Format only once at compile-time and reuse 37 | fmt.Printf("%d-%02d-%02d %02d:%02d:%02d.%09d| %s\n", 38 | now.Year(), now.Month(), now.Day(), 39 | now.Hour(), now.Minute(), now.Second(), 40 | nsec, scanner.Text(), 41 | ) 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /doc.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2017 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 | // Author Ewout Prangsma 21 | // 22 | 23 | /* 24 | Package driver implements a Go driver for the ArangoDB database. 25 | 26 | To get started, create a connection to the database and wrap a client around it. 27 | 28 | // Create an HTTP connection to the database 29 | conn, err := http.NewConnection(http.ConnectionConfig{ 30 | Endpoints: []string{"http://localhost:8529"}, 31 | }) 32 | if err != nil { 33 | // Handle error 34 | } 35 | // Create a client 36 | c, err := driver.NewClient(driver.ClientConfig{ 37 | Connection: conn, 38 | }) 39 | if err != nil { 40 | // Handle error 41 | } 42 | */ 43 | package driver 44 | -------------------------------------------------------------------------------- /content_type.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2017 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 | // Author Ewout Prangsma 21 | // 22 | 23 | package driver 24 | 25 | import "fmt" 26 | 27 | // ContentType identifies the type of encoding to use for the data. 28 | type ContentType int 29 | 30 | const ( 31 | // ContentTypeJSON encodes data as json 32 | ContentTypeJSON ContentType = iota 33 | // ContentTypeVelocypack encodes data as Velocypack 34 | ContentTypeVelocypack 35 | ) 36 | 37 | func (ct ContentType) String() string { 38 | switch ct { 39 | case ContentTypeJSON: 40 | return "application/json" 41 | case ContentTypeVelocypack: 42 | return "application/x-velocypack" 43 | default: 44 | panic(fmt.Sprintf("Unknown content type %d", int(ct))) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /client_foxx.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2020 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 | // Author Tomasz Mielech 21 | // 22 | 23 | package driver 24 | 25 | import ( 26 | "context" 27 | ) 28 | 29 | type FoxxCreateOptions struct { 30 | Mount string 31 | } 32 | 33 | type FoxxDeleteOptions struct { 34 | Mount string 35 | Teardown bool 36 | } 37 | 38 | type ClientFoxx interface { 39 | Foxx() FoxxService 40 | } 41 | 42 | type FoxxService interface { 43 | // InstallFoxxService installs a new service at a given mount path. 44 | InstallFoxxService(ctx context.Context, zipFile string, options FoxxCreateOptions) error 45 | // UninstallFoxxService uninstalls service at a given mount path. 46 | UninstallFoxxService(ctx context.Context, options FoxxDeleteOptions) error 47 | } 48 | -------------------------------------------------------------------------------- /agency/doc.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2018 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 | // Author Ewout Prangsma 21 | // 22 | 23 | /* 24 | Package agency provides an API to access the ArangoDB agency (it is unlikely that you need this package directly). 25 | 26 | The Agency is fault-tolerant and highly-available key-value store 27 | that is used to store critical, low-level information about 28 | an ArangoDB cluster. 29 | 30 | THIS API IS NOT USED FOR NORMAL DATABASE ACCESS. 31 | 32 | Reasons for using this API are: 33 | - You want to make use of an indepent Agency as your own HA key-value store. 34 | - You want access to low-level information of your database. USE WITH GREAT CARE! 35 | 36 | WARNING: Messing around in the Agency can quickly lead to a corrupt database! 37 | */ 38 | package agency 39 | -------------------------------------------------------------------------------- /util/connection/wrappers/async/async_errors.go: -------------------------------------------------------------------------------- 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 | 21 | package async 22 | 23 | import ( 24 | "errors" 25 | "fmt" 26 | ) 27 | 28 | func IsAsyncJobInProgress(err error) (string, bool) { 29 | if err == nil { 30 | return "", false 31 | } 32 | 33 | var v ErrorAsyncJobInProgress 34 | if errors.As(err, &v) { 35 | return v.jobID, true 36 | } 37 | return "", false 38 | } 39 | 40 | type ErrorAsyncJobInProgress struct { 41 | jobID string 42 | } 43 | 44 | func NewErrorAsyncJobInProgress(jobID string) ErrorAsyncJobInProgress { 45 | return ErrorAsyncJobInProgress{ 46 | jobID: jobID, 47 | } 48 | } 49 | 50 | func (a ErrorAsyncJobInProgress) Error() string { 51 | return fmt.Sprintf("Job with ID %s in progress", a.jobID) 52 | } 53 | -------------------------------------------------------------------------------- /v2/connection/auth_header_impl.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2020-2025 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 connection 22 | 23 | import ( 24 | "context" 25 | "fmt" 26 | ) 27 | 28 | func NewHeaderAuth(key, value string, args ...interface{}) Authentication { 29 | if len(args) > 0 { 30 | value = fmt.Sprintf(value, args...) 31 | } 32 | 33 | return &headerAuth{ 34 | key: key, 35 | value: value, 36 | } 37 | } 38 | 39 | type headerAuth struct { 40 | key, value string 41 | } 42 | 43 | func (b headerAuth) Init(ctx context.Context, c Connection) error { 44 | return nil 45 | } 46 | 47 | func (b headerAuth) Refresh(c Connection) error { 48 | return nil 49 | } 50 | 51 | func (b headerAuth) RequestModifier(r Request) error { 52 | r.AddHeader(b.key, b.value) 53 | 54 | return nil 55 | } 56 | -------------------------------------------------------------------------------- /test/doc.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2018-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 | 21 | package test 22 | 23 | import ( 24 | "context" 25 | "errors" 26 | 27 | "github.com/arangodb/go-driver" 28 | ) 29 | 30 | // CreateDocuments creates given number of documents for the provided collection. 31 | func CreateDocuments(ctx context.Context, col driver.Collection, docCount int, generator func(i int) any) error { 32 | if generator == nil { 33 | return errors.New("document generator can not be nil") 34 | } 35 | if col == nil { 36 | return errors.New("collection can not be nil") 37 | } 38 | if ctx == nil { 39 | ctx = context.Background() 40 | } 41 | 42 | docs := make([]any, 0, docCount) 43 | for i := 0; i < docCount; i++ { 44 | docs = append(docs, generator(i)) 45 | } 46 | 47 | _, _, err := col.CreateDocuments(ctx, docs) 48 | return err 49 | } 50 | -------------------------------------------------------------------------------- /v2/tests/decoder_test.go: -------------------------------------------------------------------------------- 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 | 21 | package tests 22 | 23 | import ( 24 | "context" 25 | "testing" 26 | 27 | "github.com/stretchr/testify/assert" 28 | "github.com/stretchr/testify/require" 29 | 30 | "github.com/arangodb/go-driver/v2/arangodb" 31 | "github.com/arangodb/go-driver/v2/connection" 32 | ) 33 | 34 | // Test_DecoderBytes gets plain text response from the server 35 | func Test_DecoderBytes(t *testing.T) { 36 | Wrap(t, func(t *testing.T, client arangodb.Client) { 37 | var output []byte 38 | 39 | url := connection.NewUrl("_admin", "metrics", "v2") 40 | _, err := connection.CallGet(context.Background(), client.Connection(), url, &output) 41 | 42 | require.NoError(t, err) 43 | require.NotNil(t, output) 44 | assert.Contains(t, string(output), "arangodb_connection_pool") 45 | }) 46 | } 47 | -------------------------------------------------------------------------------- /v2/utils/type.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2020-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 utils 22 | 23 | import ( 24 | "encoding/json" 25 | "reflect" 26 | ) 27 | 28 | func IsListPtr(i interface{}) bool { 29 | t := reflect.ValueOf(i) 30 | switch t.Kind() { 31 | case reflect.Ptr: 32 | return IsList(t.Elem().Interface()) 33 | default: 34 | return false 35 | } 36 | } 37 | 38 | func IsList(i interface{}) bool { 39 | switch reflect.ValueOf(i).Kind() { 40 | case reflect.Slice: 41 | fallthrough 42 | case reflect.Array: 43 | return true 44 | default: 45 | return false 46 | } 47 | } 48 | 49 | func NewType[T any](val T) *T { 50 | return &val 51 | } 52 | 53 | func ToJSONString(i interface{}) (string, error) { 54 | data, err := json.MarshalIndent(i, "", " ") 55 | if err != nil { 56 | return "", err 57 | } 58 | return string(data), nil 59 | } 60 | -------------------------------------------------------------------------------- /examples/example_error_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2017-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 | 21 | //go:build !auth 22 | 23 | package examples 24 | 25 | import ( 26 | "context" 27 | 28 | driver "github.com/arangodb/go-driver" 29 | ) 30 | 31 | func ExampleIsNotFound() { 32 | var sampleCollection driver.Collection 33 | var result Book 34 | 35 | if _, err := sampleCollection.ReadDocument(nil, "keyDoesNotExist", &result); driver.IsNotFound(err) { 36 | // No document with given key exists 37 | } 38 | } 39 | 40 | func ExampleIsPreconditionFailed() { 41 | var sampleCollection driver.Collection 42 | var result Book 43 | 44 | ctx := driver.WithRevision(context.Background(), "an-old-revision") 45 | if _, err := sampleCollection.ReadDocument(ctx, "someValidKey", &result); driver.IsPreconditionFailed(err) { 46 | // The Document is found, but its revision is incorrect 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /test/client_connection_http_test.go: -------------------------------------------------------------------------------- 1 | //go:build !http2 2 | // +build !http2 3 | 4 | // 5 | // DISCLAIMER 6 | // 7 | // Copyright 2017 ArangoDB GmbH, Cologne, Germany 8 | // 9 | // Licensed under the Apache License, Version 2.0 (the "License"); 10 | // you may not use this file except in compliance with the License. 11 | // You may obtain a copy of the License at 12 | // 13 | // http://www.apache.org/licenses/LICENSE-2.0 14 | // 15 | // Unless required by applicable law or agreed to in writing, software 16 | // distributed under the License is distributed on an "AS IS" BASIS, 17 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | // See the License for the specific language governing permissions and 19 | // limitations under the License. 20 | // 21 | // Copyright holder is ArangoDB GmbH, Cologne, Germany 22 | // 23 | // Author Adam Janikowski 24 | // 25 | 26 | package test 27 | 28 | import ( 29 | "crypto/tls" 30 | "net" 31 | "net/http" 32 | "time" 33 | ) 34 | 35 | func NewConnectionTransport() http.RoundTripper { 36 | return &http.Transport{ 37 | // Copy default values from http.DefaultTransport 38 | Proxy: http.ProxyFromEnvironment, 39 | TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, 40 | DialContext: (&net.Dialer{ 41 | Timeout: 30 * time.Second, 42 | KeepAlive: 30 * time.Second, 43 | DualStack: true, 44 | }).DialContext, 45 | MaxIdleConns: 100, 46 | IdleConnTimeout: 90 * time.Second, 47 | TLSHandshakeTimeout: 10 * time.Second, 48 | ExpectContinueTimeout: 1 * time.Second, 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /agency/lock_errors.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2018 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 | // Author Ewout Prangsma 21 | // 22 | 23 | package agency 24 | 25 | import ( 26 | "errors" 27 | 28 | driver "github.com/arangodb/go-driver" 29 | ) 30 | 31 | var ( 32 | // AlreadyLockedError indicates that the lock is already locked. 33 | AlreadyLockedError = errors.New("already locked") 34 | // NotLockedError indicates that the lock is not locked when trying to unlock. 35 | NotLockedError = errors.New("not locked") 36 | ) 37 | 38 | // IsAlreadyLocked returns true if the given error is or is caused by an AlreadyLockedError. 39 | func IsAlreadyLocked(err error) bool { 40 | return driver.Cause(err) == AlreadyLockedError 41 | } 42 | 43 | // IsNotLocked returns true if the given error is or is caused by an NotLockedError. 44 | func IsNotLocked(err error) bool { 45 | return driver.Cause(err) == NotLockedError 46 | } 47 | -------------------------------------------------------------------------------- /v2/connection/endpoint.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2020-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 | 21 | package connection 22 | 23 | import ( 24 | "strings" 25 | ) 26 | 27 | type Endpoint interface { 28 | // Get returns provided endpoint if it is known, otherwise chooses one endpoint from existing list 29 | // Endpoint implementation might use the Request method and path values to determine which endpoint to return 30 | Get(endpoint, method, path string) (string, error) 31 | // List returns known endpoints 32 | List() []string 33 | } 34 | 35 | var ( 36 | urlFixer = strings.NewReplacer( 37 | "tcp://", "http://", 38 | "ssl://", "https://", 39 | ) 40 | ) 41 | 42 | // FixupEndpointURLScheme changes endpoint URL schemes used by arangod to ones used by go. 43 | // E.g. "tcp://localhost:8529" -> "http://localhost:8529" 44 | func FixupEndpointURLScheme(u string) string { 45 | return urlFixer.Replace(u) 46 | } 47 | -------------------------------------------------------------------------------- /protocol.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2017 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 | // Author Ewout Prangsma 21 | // 22 | 23 | package driver 24 | 25 | type Protocol int 26 | 27 | const ( 28 | ProtocolHTTP Protocol = iota 29 | ProtocolVST1_0 30 | ProtocolVST1_1 31 | ) 32 | 33 | // ProtocolSet is a set of protocols. 34 | type ProtocolSet []Protocol 35 | 36 | // Contains returns true if the given protocol is contained in the given set, false otherwise. 37 | func (ps ProtocolSet) Contains(p Protocol) bool { 38 | for _, x := range ps { 39 | if x == p { 40 | return true 41 | } 42 | } 43 | return false 44 | } 45 | 46 | // ContainsAny returns true if any of the given protocols is contained in the given set, false otherwise. 47 | func (ps ProtocolSet) ContainsAny(p ...Protocol) bool { 48 | for _, x := range ps { 49 | for _, y := range p { 50 | if x == y { 51 | return true 52 | } 53 | } 54 | } 55 | return false 56 | } 57 | -------------------------------------------------------------------------------- /.golangci.yaml: -------------------------------------------------------------------------------- 1 | version: 2 2 | run: 3 | issues-exit-code: 3 4 | linters: 5 | enable: 6 | - asasalint 7 | - asciicheck 8 | - bidichk 9 | - bodyclose 10 | - durationcheck 11 | - fatcontext 12 | - gocheckcompilerdirectives 13 | - gochecksumtype 14 | - gosmopolitan 15 | - loggercheck 16 | - makezero 17 | - nilerr 18 | - nilnesserr 19 | - perfsprint 20 | - protogetter 21 | - reassign 22 | - recvcheck 23 | - rowserrcheck 24 | - spancheck 25 | - sqlclosecheck 26 | # - testifylint 27 | # - zerologlint 28 | disable: 29 | - contextcheck 30 | - cyclop 31 | - errcheck 32 | - errchkjson 33 | - errorlint 34 | - exhaustive 35 | - funlen 36 | - gocognit 37 | - gocyclo 38 | - gosec 39 | - govet 40 | - ineffassign 41 | - maintidx 42 | - musttag 43 | - nestif 44 | - noctx 45 | - prealloc 46 | - staticcheck 47 | - unparam 48 | - unused 49 | exclusions: 50 | generated: lax 51 | presets: 52 | - comments 53 | - common-false-positives 54 | - legacy 55 | - std-error-handling 56 | paths: 57 | - third_party$ 58 | - builtin$ 59 | - examples$ 60 | formatters: 61 | enable: 62 | - gci 63 | - gofmt 64 | - goimports 65 | settings: 66 | gci: 67 | sections: 68 | - standard 69 | - default 70 | - prefix(github.com/arangodb) 71 | - prefix(github.com/arangodb/go-driver) 72 | exclusions: 73 | generated: lax 74 | paths: 75 | - third_party$ 76 | - builtin$ 77 | - examples$ 78 | -------------------------------------------------------------------------------- /client_cluster_impl.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2017 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 | // Author Ewout Prangsma 21 | // 22 | 23 | package driver 24 | 25 | import ( 26 | "context" 27 | ) 28 | 29 | // Cluster provides access to cluster wide specific operations. 30 | // To use this interface, an ArangoDB cluster is required. 31 | // If this method is a called without a cluster, a PreconditionFailed error is returned. 32 | func (c *client) Cluster(ctx context.Context) (Cluster, error) { 33 | role, err := c.ServerRole(ctx) 34 | if err != nil { 35 | return nil, WithStack(err) 36 | } 37 | if role == ServerRoleSingle || role == ServerRoleSingleActive || role == ServerRoleSinglePassive { 38 | // Standalone server, this is wrong 39 | return nil, WithStack(newArangoError(412, 0, "Cluster expected, found SINGLE server")) 40 | } 41 | cl, err := newCluster(c.conn) 42 | if err != nil { 43 | return nil, WithStack(err) 44 | } 45 | return cl, nil 46 | } 47 | -------------------------------------------------------------------------------- /test/server_info_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2018-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 | 21 | package test 22 | 23 | import ( 24 | "context" 25 | "testing" 26 | 27 | driver "github.com/arangodb/go-driver" 28 | ) 29 | 30 | // TestServerID tests ClientServerInfo.ServerID. 31 | func TestServerID(t *testing.T) { 32 | c := createClient(t, nil) 33 | ctx := context.Background() 34 | 35 | var isCluster bool 36 | if _, err := c.Cluster(ctx); driver.IsPreconditionFailed(err) { 37 | isCluster = false 38 | } else if err != nil { 39 | t.Fatalf("Health failed: %s", describe(err)) 40 | } else { 41 | isCluster = true 42 | } 43 | 44 | if isCluster { 45 | id, err := c.ServerID(ctx) 46 | if err != nil { 47 | t.Fatalf("ServerID failed: %s", describe(err)) 48 | } 49 | if id == "" { 50 | t.Error("Expected ID to be non-empty") 51 | } 52 | } else { 53 | if _, err := c.ServerID(ctx); err == nil { 54 | t.Fatalf("ServerID succeeded, expected error") 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /v2/arangodb/database_analyzer.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2024-2025 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 arangodb 22 | 23 | import ( 24 | "context" 25 | ) 26 | 27 | type DatabaseAnalyzer interface { 28 | // EnsureCreatedAnalyzer creates an Analyzer for the database, if it does not already exist. 29 | // It returns the Analyser object together with a boolean indicating if the Analyzer was newly created (true) or pre-existing (false). 30 | EnsureCreatedAnalyzer(ctx context.Context, analyzer *AnalyzerDefinition) (Analyzer, bool, error) 31 | 32 | // Analyzer returns the analyzer definition for the given analyzer 33 | Analyzer(ctx context.Context, name string) (Analyzer, error) 34 | 35 | // Analyzers return an iterator to read all analyzers 36 | Analyzers(ctx context.Context) (AnalyzersResponseReader, error) 37 | } 38 | 39 | type AnalyzersResponseReader interface { 40 | // Read returns next Analyzer. If no Analyzers left, shared.NoMoreDocumentsError returned 41 | Read() (Analyzer, error) 42 | } 43 | -------------------------------------------------------------------------------- /v2/arangodb/database.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2020-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 | 21 | package arangodb 22 | 23 | import ( 24 | "context" 25 | ) 26 | 27 | type Database interface { 28 | // Name returns the name of the database. 29 | Name() string 30 | 31 | // Info fetches information about the database. 32 | Info(ctx context.Context) (DatabaseInfo, error) 33 | 34 | // Remove removes the entire database. 35 | // If the database does not exist, a NotFoundError is returned. 36 | Remove(ctx context.Context) error 37 | 38 | // TransactionJS performs a javascript transaction. The result of the transaction function is returned. 39 | TransactionJS(ctx context.Context, options TransactionJSOptions) (interface{}, error) 40 | 41 | // Returns the available key generators for collections. 42 | KeyGenerators(ctx context.Context) (KeyGeneratorsResponse, error) 43 | 44 | DatabaseCollection 45 | DatabaseTransaction 46 | DatabaseQuery 47 | DatabaseView 48 | DatabaseAnalyzer 49 | DatabaseGraph 50 | } 51 | -------------------------------------------------------------------------------- /v2/arangodb/collection_opts_schema.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2020 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 | // Author Adam Janikowski 21 | // 22 | 23 | package arangodb 24 | 25 | import ( 26 | "encoding/json" 27 | ) 28 | 29 | type CollectionSchemaLevel string 30 | 31 | const ( 32 | CollectionSchemaLevelNone CollectionSchemaLevel = "none" 33 | CollectionSchemaLevelNew CollectionSchemaLevel = "new" 34 | CollectionSchemaLevelModerate CollectionSchemaLevel = "moderate" 35 | CollectionSchemaLevelStrict CollectionSchemaLevel = "strict" 36 | ) 37 | 38 | type CollectionSchemaOptions struct { 39 | Rule interface{} `json:"rule,omitempty"` 40 | Level CollectionSchemaLevel `json:"level,omitempty"` 41 | Message string `json:"message,omitempty"` 42 | } 43 | 44 | func (d *CollectionSchemaOptions) LoadRule(data []byte) error { 45 | var rule interface{} 46 | 47 | if err := json.Unmarshal(data, &rule); err != nil { 48 | return err 49 | } 50 | 51 | d.Rule = rule 52 | return nil 53 | } 54 | -------------------------------------------------------------------------------- /agency/error.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2018 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 | // Author Ewout Prangsma 21 | // 22 | 23 | package agency 24 | 25 | import ( 26 | "fmt" 27 | "net/http" 28 | "strings" 29 | 30 | driver "github.com/arangodb/go-driver" 31 | ) 32 | 33 | var ( 34 | // preconditionFailedError indicates that a precondition for the request is not existing. 35 | preconditionFailedError = driver.ArangoError{ 36 | HasError: true, 37 | Code: http.StatusPreconditionFailed, 38 | } 39 | ) 40 | 41 | // KeyNotFoundError indicates that a key was not found. 42 | type KeyNotFoundError struct { 43 | Key []string 44 | } 45 | 46 | // Error returns a human readable error string 47 | func (e KeyNotFoundError) Error() string { 48 | return fmt.Sprintf("Key '%s' not found", strings.Join(e.Key, "/")) 49 | } 50 | 51 | // IsKeyNotFound returns true if the given error is (or is caused by) a KeyNotFoundError. 52 | func IsKeyNotFound(err error) bool { 53 | _, ok := driver.Cause(err).(KeyNotFoundError) 54 | return ok 55 | } 56 | -------------------------------------------------------------------------------- /v2/tests/pool_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2021 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 | // Author Adam Janikowski 21 | // 22 | 23 | package tests 24 | 25 | import ( 26 | "context" 27 | "sync" 28 | "testing" 29 | 30 | "github.com/stretchr/testify/require" 31 | 32 | "github.com/arangodb/go-driver/v2/arangodb" 33 | "github.com/arangodb/go-driver/v2/connection" 34 | ) 35 | 36 | func Test_Pool(t *testing.T) { 37 | WrapConnectionFactory(t, func(t *testing.T, connFactory ConnectionFactory) { 38 | conn, err := connection.NewPool(5, func() (connection.Connection, error) { 39 | return connFactory(t), nil 40 | }) 41 | require.NoError(t, err) 42 | 43 | client := arangodb.NewClient(conn) 44 | 45 | var wg sync.WaitGroup 46 | ctx := context.Background() 47 | 48 | for i := 0; i < 8; i++ { 49 | wg.Add(1) 50 | 51 | go func() { 52 | defer wg.Done() 53 | for j := 0; j < 16; j++ { 54 | _, err := client.Version(ctx) 55 | require.NoError(t, err) 56 | } 57 | }() 58 | } 59 | 60 | wg.Wait() 61 | }) 62 | } 63 | -------------------------------------------------------------------------------- /v2/README.md: -------------------------------------------------------------------------------- 1 | # ArangoDB Go Driver Version 2 2 | 3 | The implementation of the v2 driver makes use of runtime JSON serialization, 4 | reducing memory and CPU usage. The combination of JSON serialization and HTTP/2 5 | support makes the driver more efficient and faster. 6 | 7 | To get started, see the 8 | [Tutorial](https://docs.arangodb.com/stable/develop/drivers/go/). 9 | 10 | ## Deprecation Notice 11 | 12 | From ArangoDB v3.12 onward, the VelocyStream (VST) protocol is not supported 13 | any longer. The v2 driver does not support VelocyStream. VelocyPack support in 14 | the driver is not developed and maintained anymore and will removed in a 15 | future version. 16 | 17 | The v1 driver is deprecated and will not receive any new features. 18 | Please use v2 instead, which uses a new way of handling requests and responses 19 | that is more efficient and easier to use. 20 | 21 | ## Benchmarks 22 | 23 | V2 driver shows significant performance improvements over V1, with 16-44% faster execution times and 89-94% less memory usage across all operations. 24 | 25 | For detailed benchmark results, analysis, and instructions on running benchmarks, 26 | see [BENCHMARKS.md](./BENCHMARKS.md). 27 | 28 | ### go-driver v2 vs v1 Summary 29 | 30 | - **Protocol**: v2 supports both HTTP/1.1 and HTTP/2, with HTTP/2 providing multiplexing, header compression, and binary framing for higher efficiency. 31 | - **Performance**: v2 shows major gains in write-heavy workloads; reads improve less since they're I/O-bound and limited by network latency. 32 | - **Memory**: v2 uses 89–94% less memory and cuts allocations by 13–99%, greatly reducing GC overhead. 33 | - **Overall**: v2 is faster, more memory-efficient, and better suited for high-throughput, long-running applications. -------------------------------------------------------------------------------- /v2/arangodb/database_transaction.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2020-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 | 21 | package arangodb 22 | 23 | import ( 24 | "context" 25 | ) 26 | 27 | // DatabaseTransaction contains Streaming Transactions functions 28 | // https://docs.arangodb.com/stable/develop/http-api/transactions/stream-transactions/ 29 | type DatabaseTransaction interface { 30 | ListTransactions(ctx context.Context) ([]Transaction, error) 31 | ListTransactionsWithStatuses(ctx context.Context, statuses ...TransactionStatus) ([]Transaction, error) 32 | 33 | BeginTransaction(ctx context.Context, cols TransactionCollections, opts *BeginTransactionOptions) (Transaction, error) 34 | 35 | Transaction(ctx context.Context, id TransactionID) (Transaction, error) 36 | 37 | WithTransaction(ctx context.Context, cols TransactionCollections, opts *BeginTransactionOptions, commitOptions *CommitTransactionOptions, abortOptions *AbortTransactionOptions, w TransactionWrap) error 38 | } 39 | 40 | type TransactionWrap func(ctx context.Context, t Transaction) error 41 | -------------------------------------------------------------------------------- /v2/tests/context_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2017-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 tests 22 | 23 | import ( 24 | "context" 25 | "testing" 26 | 27 | "github.com/stretchr/testify/require" 28 | 29 | "github.com/arangodb/go-driver/v2/arangodb" 30 | ) 31 | 32 | func TestContextWithArangoQueueTimeoutParams(t *testing.T) { 33 | Wrap(t, func(t *testing.T, client arangodb.Client) { 34 | withContextT(t, defaultTestTimeout, func(ctx context.Context, _ testing.TB) { 35 | skipBelowVersion(client, ctx, "3.9", t) 36 | t.Run("without timout", func(t *testing.T) { 37 | _, err := client.Version(context.Background()) 38 | require.NoError(t, err) 39 | }) 40 | 41 | t.Run("without timeout - if no queue timeout and no context deadline set", func(t *testing.T) { 42 | cfg := client.Connection().GetConfiguration() 43 | cfg.ArangoQueueTimeoutEnabled = true 44 | client.Connection().SetConfiguration(cfg) 45 | 46 | _, err := client.Version(ctx) 47 | require.NoError(t, err) 48 | }) 49 | }) 50 | }) 51 | } 52 | -------------------------------------------------------------------------------- /v2/tests/client_server_info_test.go: -------------------------------------------------------------------------------- 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 | 21 | package tests 22 | 23 | import ( 24 | "context" 25 | "testing" 26 | 27 | "github.com/stretchr/testify/require" 28 | 29 | "github.com/arangodb/go-driver/v2/arangodb" 30 | ) 31 | 32 | // Test_ServerRole tests a server role for all instances. 33 | func Test_ServerRole(t *testing.T) { 34 | Wrap(t, func(t *testing.T, client arangodb.Client) { 35 | withContextT(t, defaultTestTimeout, func(ctx context.Context, _ testing.TB) { 36 | testMode := getTestMode() 37 | 38 | t.Run("user endpoint", func(t *testing.T) { 39 | role, err := client.ServerRole(ctx) 40 | require.NoError(t, err) 41 | 42 | if testMode == string(testModeCluster) { 43 | require.Equal(t, role, arangodb.ServerRoleCoordinator) 44 | } else if testMode == string(testModeSingle) { 45 | require.Equal(t, role, arangodb.ServerRoleSingle) 46 | } else { 47 | require.Equal(t, role, arangodb.ServerRoleSingleActive) 48 | } 49 | }) 50 | }) 51 | }) 52 | } 53 | -------------------------------------------------------------------------------- /jwt/doc.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2018 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 | // Author Ewout Prangsma 21 | // 22 | 23 | /* 24 | Package jwt provides a helper function used to access ArangoDB 25 | servers using a JWT secret. 26 | 27 | Authenticating with a JWT secret results in "super-user" access 28 | to the database. 29 | 30 | To use a JWT secret to access your database, use code like this: 31 | 32 | // Create an HTTP connection to the database 33 | conn, err := http.NewConnection(http.ConnectionConfig{ 34 | Endpoints: []string{"http://localhost:8529"}, 35 | }) 36 | if err != nil { 37 | // Handle error 38 | } 39 | 40 | // Prepare authentication 41 | hdr, err := CreateArangodJwtAuthorizationHeader("yourJWTSecret", "yourUniqueServerID") 42 | if err != nil { 43 | // Handle error 44 | } 45 | auth := driver.RawAuthentication(hdr) 46 | 47 | // Create a client 48 | c, err := driver.NewClient(driver.ClientConfig{ 49 | Connection: conn, 50 | Authentication: auth, 51 | }) 52 | if err != nil { 53 | // Handle error 54 | } 55 | */ 56 | package jwt 57 | -------------------------------------------------------------------------------- /v2/connection/endpoints_round_robin.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2020-2025 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 connection 22 | 23 | import ( 24 | "errors" 25 | "sync" 26 | ) 27 | 28 | // NewRoundRobinEndpoints returns Endpoint manager which runs round-robin 29 | func NewRoundRobinEndpoints(e []string) Endpoint { 30 | return &roundRobinEndpoints{ 31 | endpoints: e, 32 | } 33 | } 34 | 35 | type roundRobinEndpoints struct { 36 | lock sync.Mutex 37 | endpoints []string 38 | index int 39 | } 40 | 41 | func (e *roundRobinEndpoints) List() []string { 42 | return e.endpoints 43 | } 44 | 45 | func (e *roundRobinEndpoints) Get(providedEp, _, _ string) (string, error) { 46 | e.lock.Lock() 47 | defer e.lock.Unlock() 48 | 49 | if providedEp != "" { 50 | return providedEp, nil 51 | } 52 | 53 | if len(e.endpoints) == 0 { 54 | return "", errors.New("no endpoints known") 55 | } 56 | 57 | if e.index >= len(e.endpoints) { 58 | e.index = 0 59 | } 60 | 61 | r := e.endpoints[e.index] 62 | 63 | e.index++ 64 | 65 | return r, nil 66 | } 67 | -------------------------------------------------------------------------------- /database_collections_schema.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2020 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 | // Author Adam Janikowski 21 | // 22 | 23 | package driver 24 | 25 | import ( 26 | "encoding/json" 27 | ) 28 | 29 | type CollectionSchemaLevel string 30 | 31 | const ( 32 | CollectionSchemaLevelNone CollectionSchemaLevel = "none" 33 | CollectionSchemaLevelNew CollectionSchemaLevel = "new" 34 | CollectionSchemaLevelModerate CollectionSchemaLevel = "moderate" 35 | CollectionSchemaLevelStrict CollectionSchemaLevel = "strict" 36 | ) 37 | 38 | type CollectionSchemaOptions struct { 39 | Rule interface{} `json:"rule,omitempty"` 40 | Level CollectionSchemaLevel `json:"level,omitempty"` 41 | Message string `json:"message,omitempty"` 42 | Type string `json:"type,omitempty"` 43 | } 44 | 45 | func (d *CollectionSchemaOptions) LoadRule(data []byte) error { 46 | var rule interface{} 47 | 48 | if err := json.Unmarshal(data, &rule); err != nil { 49 | return err 50 | } 51 | 52 | d.Rule = rule 53 | return nil 54 | } 55 | -------------------------------------------------------------------------------- /test/server_license_test.go: -------------------------------------------------------------------------------- 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 | 21 | package test 22 | 23 | import ( 24 | "context" 25 | "testing" 26 | 27 | "github.com/stretchr/testify/assert" 28 | "github.com/stretchr/testify/require" 29 | 30 | "github.com/arangodb/go-driver" 31 | ) 32 | 33 | // Test_License tests ArangoDB license. 34 | func Test_License(t *testing.T) { 35 | c := createClient(t, nil) 36 | ctx := context.Background() 37 | skipVersionNotInRange(c, "3.10.0", "3.12.4", t) 38 | 39 | version, err := c.Version(ctx) 40 | require.NoError(t, err) 41 | 42 | license, err := c.GetLicense(ctx) 43 | require.NoError(t, err) 44 | 45 | if version.IsEnterprise() { 46 | assert.Equalf(t, driver.LicenseStatusExpiring, license.Status, "by default status should be expiring") 47 | assert.EqualValuesf(t, 1, license.Version, "excpected version should be 1") 48 | } else { 49 | assert.Equalf(t, driver.LicenseStatus(""), license.Status, "license status should be empty") 50 | assert.Equalf(t, 0, license.Version, "license version should be empty") 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /v2/connection/connection_http.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2020-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 connection 22 | 23 | import "net/http" 24 | 25 | type HttpConfiguration struct { 26 | Authentication Authentication 27 | Endpoint Endpoint 28 | 29 | ContentType string 30 | 31 | ArangoDBConfig ArangoDBConfiguration 32 | 33 | Transport http.RoundTripper 34 | } 35 | 36 | func (h HttpConfiguration) getTransport() http.RoundTripper { 37 | if h.Transport != nil { 38 | return h.Transport 39 | } 40 | 41 | return &http.Transport{ 42 | MaxIdleConns: 100, 43 | } 44 | } 45 | 46 | func (h HttpConfiguration) GetContentType() string { 47 | if h.ContentType == "" { 48 | return ApplicationJSON 49 | } 50 | 51 | return h.ContentType 52 | } 53 | 54 | func NewHttpConnection(config HttpConfiguration) Connection { 55 | c := newHttpConnection(config.getTransport(), config.ContentType, config.Endpoint, config.ArangoDBConfig) 56 | 57 | if a := config.Authentication; a != nil { 58 | c.authentication = a 59 | } 60 | 61 | c.streamSender = false 62 | 63 | return c 64 | } 65 | -------------------------------------------------------------------------------- /v2/tests/admin_license_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2023-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 tests 22 | 23 | import ( 24 | "context" 25 | "testing" 26 | 27 | "github.com/stretchr/testify/assert" 28 | "github.com/stretchr/testify/require" 29 | 30 | "github.com/arangodb/go-driver/v2/arangodb" 31 | ) 32 | 33 | func Test_License(t *testing.T) { 34 | Wrap(t, func(t *testing.T, client arangodb.Client) { 35 | withContextT(t, defaultTestTimeout, func(ctx context.Context, t testing.TB) { 36 | version := skipVersionNotInRange(client, ctx, "3.10.0", "3.12.4", t) 37 | 38 | license, err := client.GetLicense(ctx) 39 | require.NoError(t, err) 40 | if version.IsEnterprise() { 41 | assert.Equalf(t, arangodb.LicenseStatusExpiring, license.Status, "by default status should be expiring") 42 | assert.Equalf(t, 1, license.Version, "excpected version should be 1") 43 | } else { 44 | assert.Equalf(t, arangodb.LicenseStatus(""), license.Status, "license status should be empty") 45 | assert.Equalf(t, 0, license.Version, "license version should be empty") 46 | } 47 | }) 48 | }) 49 | } 50 | -------------------------------------------------------------------------------- /MAINTAINERS.md: -------------------------------------------------------------------------------- 1 | # Maintainer Instructions 2 | 3 | - Always preserve backward compatibility 4 | - Build using `make clean && make` 5 | - After merging PR, always run `make changelog` and commit changes 6 | - Set ArangoDB docker container (used for testing) using `export ARANGODB=` 7 | - Run tests using: 8 | - `make run-tests-single` 9 | - `make run-tests-resilientsingle` 10 | - `make run-tests-cluster`. 11 | - The test can be launched with the flag `RACE=on` which means that test will be performed with the race detector, e.g: 12 | - `RACE=on make run-tests-single` 13 | - Always create changes in a PR 14 | 15 | 16 | # Change Golang version 17 | 18 | - Edit the [.circleci/config.yml](.circleci/config.yml) file and change ALL occurrences of `gcr.io/gcr-for-testing/golang` to the appropriate version. 19 | - Edit the [Makefile](Makefile) and change the `GOVERSION` to the appropriate version. 20 | - For minor Golang version update, bump the Go version in [go.mod](go.mod) and [v2/go.mod](v2/go.mod) and run `go mod tidy`. 21 | 22 | ## Debugging with DLV 23 | 24 | To attach DLV debugger run tests with `DEBUG=true` flag e.g.: 25 | ```shell 26 | DEBUG=true TESTOPTIONS="-test.run TestResponseHeader -test.v" make run-tests-single-json-with-auth 27 | ``` 28 | 29 | # Release Instructions 30 | 31 | 1. Update CHANGELOG.md 32 | 2. Make sure that GitHub access token exist in `~/.arangodb/github-token` and has read/write access for this repo. 33 | 3. Make sure you have the `~/go-driver/.tmp/bin/github-release` file. If not run `make tools`. 34 | 4. Make sure you have admin access to `go-driver` repository. 35 | 5. Run `make release-patch|minor|major` to create a release. 36 | - To release v2 version, use `make release-v2-patch|minor|major`. 37 | 6. Go To GitHub and fill the description with the content of CHANGELOG.md 38 | -------------------------------------------------------------------------------- /v2/connection/connection_http_response.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2020-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 | 21 | package connection 22 | 23 | import ( 24 | "net/http" 25 | "strings" 26 | ) 27 | 28 | type httpResponse struct { 29 | response *http.Response 30 | request *httpRequest 31 | } 32 | 33 | func (j *httpResponse) Endpoint() string { 34 | return j.request.Endpoint() 35 | } 36 | 37 | func (j *httpResponse) Response() interface{} { 38 | return j.response 39 | } 40 | 41 | func (j *httpResponse) Code() int { 42 | return j.response.StatusCode 43 | } 44 | 45 | func (j *httpResponse) Content() string { 46 | value := strings.Split(j.response.Header.Get(ContentType), ";") 47 | if len(value) > 0 { 48 | // The header can be returned with arguments, e.g.: "Content-Type: text/html; charset=UTF-8". 49 | return value[0] 50 | } 51 | 52 | return "" 53 | } 54 | 55 | func (j *httpResponse) Header(name string) string { 56 | if j.response.Header == nil { 57 | return "" 58 | } 59 | return j.response.Header.Get(name) 60 | } 61 | 62 | func (j *httpResponse) RawResponse() *http.Response { 63 | return j.response 64 | } 65 | -------------------------------------------------------------------------------- /v2/connection/data_array.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2020 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 | // Author Adam Janikowski 21 | // 22 | 23 | package connection 24 | 25 | import ( 26 | "bytes" 27 | "encoding/json" 28 | "io" 29 | "sync" 30 | ) 31 | 32 | var _ json.Unmarshaler = &Array{} 33 | 34 | type Array struct { 35 | decoder *json.Decoder 36 | 37 | lock sync.Mutex 38 | } 39 | 40 | func (a *Array) UnmarshalJSON(d []byte) error { 41 | a.lock.Lock() 42 | defer a.lock.Unlock() 43 | 44 | data := make([]byte, len(d)) 45 | for id, b := range d { 46 | data[id] = b 47 | } 48 | 49 | in := bytes.NewReader(data) 50 | 51 | decoder := json.NewDecoder(in) 52 | 53 | if _, err := decoder.Token(); err != nil { 54 | return err 55 | } 56 | 57 | a.decoder = decoder 58 | 59 | return nil 60 | } 61 | 62 | func (a *Array) Unmarshal(i interface{}) error { 63 | a.lock.Lock() 64 | defer a.lock.Unlock() 65 | 66 | if a == nil { 67 | return io.EOF 68 | } 69 | 70 | return a.decoder.Decode(i) 71 | } 72 | 73 | func (a *Array) More() bool { 74 | a.lock.Lock() 75 | defer a.lock.Unlock() 76 | 77 | return a.decoder.More() 78 | } 79 | -------------------------------------------------------------------------------- /v2/arangodb/analyzer.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2023-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 arangodb 22 | 23 | import "context" 24 | 25 | type Analyzer interface { 26 | Name() string 27 | Database() Database 28 | 29 | // Type returns the analyzer type 30 | Type() ArangoSearchAnalyzerType 31 | 32 | // UniqueName returns the unique name: :: 33 | UniqueName() string 34 | 35 | // Definition returns the analyzer definition 36 | Definition() AnalyzerDefinition 37 | 38 | // Remove the analyzer 39 | Remove(ctx context.Context, force bool) error 40 | } 41 | 42 | type AnalyzerDefinition struct { 43 | // The Analyzer name. 44 | Name string `json:"name,omitempty"` 45 | 46 | // The Analyzer type. 47 | Type ArangoSearchAnalyzerType `json:"type,omitempty"` 48 | 49 | // The properties used to configure the specified Analyzer type. 50 | Properties ArangoSearchAnalyzerProperties `json:"properties,omitempty"` 51 | 52 | // The set of features to set on the Analyzer generated fields. 53 | // The default value is an empty array. 54 | Features []ArangoSearchFeature `json:"features,omitempty"` 55 | } 56 | -------------------------------------------------------------------------------- /v2/log/local.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2020 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 | // Author Adam Janikowski 21 | // 22 | 23 | package log 24 | 25 | var logger Log 26 | 27 | func SetLogger(l Log) { 28 | logger = l 29 | } 30 | 31 | func Trace(msg string) { 32 | if logger != nil { 33 | logger.Trace(msg) 34 | } 35 | } 36 | 37 | func Tracef(msg string, args ...interface{}) { 38 | if logger != nil { 39 | logger.Tracef(msg, args...) 40 | } 41 | } 42 | 43 | func Debug(msg string) { 44 | if logger != nil { 45 | logger.Debug(msg) 46 | } 47 | } 48 | 49 | func Debugf(msg string, args ...interface{}) { 50 | if logger != nil { 51 | logger.Debugf(msg, args...) 52 | } 53 | } 54 | 55 | func Info(msg string) { 56 | if logger != nil { 57 | logger.Info(msg) 58 | } 59 | } 60 | 61 | func Infof(msg string, args ...interface{}) { 62 | if logger != nil { 63 | logger.Infof(msg, args...) 64 | } 65 | } 66 | 67 | func Error(err error, msg string) { 68 | if logger != nil { 69 | logger.Error(err, msg) 70 | } 71 | } 72 | 73 | func Errorf(err error, msg string, args ...interface{}) { 74 | if logger != nil { 75 | logger.Errorf(err, msg, args...) 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | // Place your settings in this file to overwrite default and user settings. 2 | { 3 | "fileHeaderComment.parameter":{ 4 | "*":{ 5 | "commentprefix": "//", 6 | "company": "ArangoDB GmbH, Cologne, Germany", 7 | "author": "Ewout Prangsma" 8 | } 9 | }, 10 | "fileHeaderComment.template":{ 11 | "*":[ 12 | "${commentprefix} ", 13 | "${commentprefix} DISCLAIMER", 14 | "${commentprefix} ", 15 | "${commentprefix} Copyright ${year} ArangoDB GmbH, Cologne, Germany", 16 | "${commentprefix} ", 17 | "${commentprefix} Licensed under the Apache License, Version 2.0 (the \"License\");", 18 | "${commentprefix} you may not use this file except in compliance with the License.", 19 | "${commentprefix} You may obtain a copy of the License at", 20 | "${commentprefix} ", 21 | "${commentprefix} http://www.apache.org/licenses/LICENSE-2.0", 22 | "${commentprefix} ", 23 | "${commentprefix} Unless required by applicable law or agreed to in writing, software", 24 | "${commentprefix} distributed under the License is distributed on an \"AS IS\" BASIS,", 25 | "${commentprefix} WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", 26 | "${commentprefix} See the License for the specific language governing permissions and", 27 | "${commentprefix} limitations under the License.", 28 | "${commentprefix} ", 29 | "${commentprefix} Copyright holder is ArangoDB GmbH, Cologne, Germany", 30 | "${commentprefix} ", 31 | "${commentprefix} Author ${author}", 32 | "${commentprefix} ", 33 | "" 34 | ] 35 | }, 36 | "go.gopath": "${workspaceRoot}/.gobuild" 37 | } -------------------------------------------------------------------------------- /v2/connection/error.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2020-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 connection 22 | 23 | import ( 24 | "errors" 25 | "fmt" 26 | "net/http" 27 | ) 28 | 29 | func NewErrorf(code int, message string, args ...interface{}) error { 30 | return NewError(code, fmt.Sprintf(message, args...)) 31 | } 32 | 33 | func NewError(code int, message string) error { 34 | return Error{ 35 | Code: code, 36 | Message: message, 37 | } 38 | } 39 | 40 | type Error struct { 41 | Code int 42 | Message string 43 | } 44 | 45 | func (e Error) Error() string { 46 | return fmt.Sprintf("Code %d, Error: %s", e.Code, e.Message) 47 | } 48 | 49 | type cause interface { 50 | Cause() error 51 | } 52 | 53 | func IsCodeError(err error, code int) bool { 54 | var codeErr Error 55 | if errors.As(err, &codeErr) { 56 | return codeErr.Code == code 57 | } 58 | 59 | if c, ok := err.(cause); ok { 60 | return IsCodeError(c.Cause(), code) 61 | } 62 | 63 | return false 64 | } 65 | 66 | func NewNotFoundError(msg string) error { 67 | return NewError(http.StatusNotFound, msg) 68 | } 69 | 70 | func IsNotFoundError(err error) bool { 71 | return IsCodeError(err, http.StatusNotFound) 72 | } 73 | -------------------------------------------------------------------------------- /v2/connection/connection_http2.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2020-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 connection 22 | 23 | import ( 24 | "golang.org/x/net/http2" 25 | ) 26 | 27 | type Http2Configuration struct { 28 | Authentication Authentication 29 | Endpoint Endpoint 30 | 31 | ContentType string 32 | 33 | ArangoDBConfig ArangoDBConfiguration 34 | 35 | Transport *http2.Transport 36 | } 37 | 38 | func (h Http2Configuration) getTransport() *http2.Transport { 39 | if h.Transport != nil { 40 | return h.Transport 41 | } 42 | 43 | return &http2.Transport{AllowHTTP: true} 44 | } 45 | 46 | func (h Http2Configuration) GetContentType() string { 47 | if h.ContentType == "" { 48 | return ApplicationJSON 49 | } 50 | 51 | return h.ContentType 52 | } 53 | 54 | // NewHttp2Connection 55 | // Warning: Ensure that VST is not enabled to avoid performance issues 56 | func NewHttp2Connection(config Http2Configuration) Connection { 57 | c := newHttpConnection(config.getTransport(), config.ContentType, config.Endpoint, config.ArangoDBConfig) 58 | 59 | if a := config.Authentication; a != nil { 60 | c.authentication = a 61 | } 62 | 63 | c.streamSender = true 64 | 65 | return c 66 | } 67 | -------------------------------------------------------------------------------- /v2/examples/example_client_basic_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2023-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 | // ExampleNewClient shows how to create the simple client with a single endpoint 32 | func ExampleNewClient() { 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 | // Create a client 44 | client := arangodb.NewClient(conn) 45 | 46 | // Ask the version of the server 47 | versionInfo, err := client.Version(context.Background()) 48 | if err != nil { 49 | log.Printf("Failed to get version info: %v", err) 50 | } 51 | log.Printf("Database has version '%s' and license '%s'\n", versionInfo.Version, versionInfo.License) 52 | } 53 | -------------------------------------------------------------------------------- /v2/log/zerolog.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2020 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 | // Author Adam Janikowski 21 | // 22 | 23 | package log 24 | 25 | import "github.com/rs/zerolog" 26 | 27 | func SetZeroLogLogger(logger zerolog.Logger) { 28 | SetLogger(&ZeroLogLogger{log: logger}) 29 | } 30 | 31 | type ZeroLogLogger struct { 32 | log zerolog.Logger 33 | } 34 | 35 | func (z ZeroLogLogger) Trace(msg string) { 36 | z.log.Trace().Msgf(msg) 37 | } 38 | 39 | func (z ZeroLogLogger) Tracef(msg string, args ...interface{}) { 40 | z.log.Trace().Msgf(msg, args...) 41 | } 42 | 43 | func (z ZeroLogLogger) Debug(msg string) { 44 | z.log.Debug().Msgf(msg) 45 | } 46 | 47 | func (z ZeroLogLogger) Debugf(msg string, args ...interface{}) { 48 | z.log.Debug().Msgf(msg, args...) 49 | } 50 | 51 | func (z ZeroLogLogger) Info(msg string) { 52 | z.log.Info().Msgf(msg) 53 | } 54 | 55 | func (z ZeroLogLogger) Infof(msg string, args ...interface{}) { 56 | z.log.Info().Msgf(msg, args...) 57 | } 58 | 59 | func (z ZeroLogLogger) Error(err error, msg string) { 60 | z.log.Error().Err(err).Msgf(msg) 61 | } 62 | 63 | func (z ZeroLogLogger) Errorf(err error, msg string, args ...interface{}) { 64 | z.log.Error().Err(err).Msgf(msg, args...) 65 | } 66 | -------------------------------------------------------------------------------- /test/check_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2021 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 | // Author Adam Janikowski 21 | // 22 | 23 | package test 24 | 25 | import ( 26 | "context" 27 | "net/http" 28 | 29 | "github.com/arangodb/go-driver" 30 | ) 31 | 32 | type driverErrorCheckFunc func(err error) (bool, error) 33 | type driverErrorChecker func(ctx context.Context, client driver.Client) error 34 | 35 | func driverErrorCheck(ctx context.Context, c driver.Client, checker driverErrorChecker, checks ...driverErrorCheckFunc) retryFunc { 36 | return func() error { 37 | err := checker(ctx, c) 38 | 39 | for _, check := range checks { 40 | if valid, err := check(err); err != nil { 41 | return err 42 | } else if !valid { 43 | return nil 44 | } 45 | } 46 | 47 | return interrupt{} 48 | } 49 | } 50 | 51 | func driverErrorCheckRetry503(err error) (bool, error) { 52 | if err == nil { 53 | return true, nil 54 | } 55 | 56 | if ae, ok := driver.AsArangoError(err); !ok { 57 | return false, err 58 | } else { 59 | if !ae.HasError { 60 | return true, nil 61 | } 62 | switch ae.Code { 63 | case http.StatusServiceUnavailable: 64 | return false, nil 65 | default: 66 | return true, err 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /view_arangosearch_alias.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2018 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 | // Author Ewout Prangsma 21 | // 22 | 23 | package driver 24 | 25 | import ( 26 | "context" 27 | ) 28 | 29 | // ArangoSearchViewAlias provides access to the information of a view alias 30 | // Views aliases are only available in ArangoDB 3.10 and higher. 31 | type ArangoSearchViewAlias interface { 32 | // View Includes generic View functions 33 | View 34 | 35 | // Properties fetches extended information about the view. 36 | Properties(ctx context.Context) (ArangoSearchAliasViewProperties, error) 37 | 38 | // SetProperties changes properties of the view. 39 | SetProperties(ctx context.Context, options ArangoSearchAliasViewProperties) (ArangoSearchAliasViewProperties, error) 40 | } 41 | 42 | type ArangoSearchAliasViewProperties struct { 43 | ArangoSearchViewBase 44 | 45 | // Indexes A list of inverted indexes to add to the View. 46 | Indexes []ArangoSearchAliasIndex `json:"indexes,omitempty"` 47 | } 48 | 49 | type ArangoSearchAliasIndex struct { 50 | // Collection The name of a collection. 51 | Collection string `json:"collection"` 52 | // Index The name of an inverted index of the collection. 53 | Index string `json:"index"` 54 | } 55 | -------------------------------------------------------------------------------- /v2/log/stdout.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2020 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 | // Author Adam Janikowski 21 | // 22 | 23 | package log 24 | 25 | import "fmt" 26 | 27 | func SetStdOutLogger() { 28 | SetLogger(&StdOutLogger{}) 29 | } 30 | 31 | type StdOutLogger struct { 32 | } 33 | 34 | func (s StdOutLogger) log(level, msg string, args ...interface{}) { 35 | println(fmt.Sprintf(fmt.Sprintf("%s: %s", level, msg), args...)) 36 | } 37 | 38 | func (s StdOutLogger) Trace(msg string) { 39 | s.log("TRACE", msg) 40 | } 41 | 42 | func (s StdOutLogger) Tracef(msg string, args ...interface{}) { 43 | s.log("TRACE", msg, args...) 44 | } 45 | 46 | func (s StdOutLogger) Debug(msg string) { 47 | s.log("DEBUG", msg) 48 | } 49 | 50 | func (s StdOutLogger) Debugf(msg string, args ...interface{}) { 51 | s.log("DEBUG", msg, args...) 52 | } 53 | 54 | func (s StdOutLogger) Info(msg string) { 55 | s.log("INFO", msg) 56 | } 57 | 58 | func (s StdOutLogger) Infof(msg string, args ...interface{}) { 59 | s.log("INFO", msg, args...) 60 | } 61 | 62 | func (s StdOutLogger) Error(err error, msg string) { 63 | s.log("ERROR", msg) 64 | } 65 | 66 | func (s StdOutLogger) Errorf(err error, msg string, args ...interface{}) { 67 | s.log("ERROR", msg, args...) 68 | } 69 | -------------------------------------------------------------------------------- /view.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2018 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 | // Author Ewout Prangsma 21 | // 22 | 23 | package driver 24 | 25 | import ( 26 | "context" 27 | ) 28 | 29 | // View provides access to the information of a view. 30 | // Views are only available in ArangoDB 3.4 and higher. 31 | type View interface { 32 | // Name returns the name of the view. 33 | Name() string 34 | 35 | // Type returns the type of this view. 36 | Type() ViewType 37 | 38 | // ArangoSearchView returns this view as an ArangoSearch view. 39 | // When the type of the view is not ArangoSearch, an error is returned. 40 | ArangoSearchView() (ArangoSearchView, error) 41 | 42 | // ArangoSearchViewAlias returns this view as an ArangoSearch view alias. 43 | // When the type of the view is not ArangoSearch alias, an error is returned. 44 | ArangoSearchViewAlias() (ArangoSearchViewAlias, error) 45 | 46 | // Database returns the database containing the view. 47 | Database() Database 48 | 49 | // Rename renames the view (SINGLE server only). 50 | Rename(ctx context.Context, newName string) error 51 | 52 | // Remove removes the entire view. 53 | // If the view does not exist, a NotFoundError is returned. 54 | Remove(ctx context.Context) error 55 | } 56 | -------------------------------------------------------------------------------- /client_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2023-2025 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 driver_test 22 | 23 | import ( 24 | "runtime" 25 | "testing" 26 | "time" 27 | 28 | "github.com/stretchr/testify/require" 29 | 30 | "github.com/arangodb/go-driver" 31 | "github.com/arangodb/go-driver/http" 32 | ) 33 | 34 | func TestNewClient(t *testing.T) { 35 | mockConn, err := http.NewConnection(http.ConnectionConfig{ 36 | Endpoints: []string{"localhost"}, 37 | }) 38 | require.NoError(t, err) 39 | 40 | cfg := driver.ClientConfig{ 41 | Connection: mockConn, 42 | SynchronizeEndpointsInterval: time.Second * 20, 43 | } 44 | 45 | var clients = make(map[int]driver.Client) 46 | 47 | before := runtime.NumGoroutine() 48 | const iterations = 30 49 | for i := 0; i < iterations; i++ { 50 | c, err := driver.NewClient(cfg) 51 | require.NoError(t, err, "iter %d", i) 52 | 53 | clients[i] = c 54 | } 55 | 56 | after := runtime.NumGoroutine() 57 | 58 | // SynchronizeEndpointsInterval feature has a bug where new go-routine would be created per each call to NewClient 59 | // This feature should not be used. The test is present here only to document this behaviour. 60 | require.Equal(t, iterations, after-before) 61 | } 62 | -------------------------------------------------------------------------------- /v2/arangodb/client_server_info_impl_test.go: -------------------------------------------------------------------------------- 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 | 21 | package arangodb 22 | 23 | import ( 24 | "testing" 25 | 26 | "github.com/stretchr/testify/assert" 27 | ) 28 | 29 | func TestConvertServerRole(t *testing.T) { 30 | type args struct { 31 | arangoDBRole string 32 | } 33 | tests := map[string]struct { 34 | args args 35 | want ServerRole 36 | }{ 37 | "coordinator": { 38 | args: args{ 39 | arangoDBRole: "COORDINATOR", 40 | }, 41 | want: ServerRoleCoordinator, 42 | }, 43 | "single": { 44 | args: args{ 45 | arangoDBRole: "SINGLE", 46 | }, 47 | want: ServerRoleSingle, 48 | }, 49 | "agent": { 50 | args: args{ 51 | arangoDBRole: "AGENT", 52 | }, 53 | want: ServerRoleAgent, 54 | }, 55 | "primary": { 56 | args: args{ 57 | arangoDBRole: "PRIMARY", 58 | }, 59 | want: ServerRoleDBServer, 60 | }, 61 | "undefined": { 62 | args: args{ 63 | arangoDBRole: "invalid", 64 | }, 65 | want: ServerRoleUndefined, 66 | }, 67 | } 68 | 69 | for testName, test := range tests { 70 | t.Run(testName, func(t *testing.T) { 71 | got := ConvertServerRole(test.args.arangoDBRole) 72 | assert.Equal(t, test.want, got) 73 | }) 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /v2/examples/example_client_roundrobin_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2023-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 | // ExampleNewRoundRobinEndpoints shows how to create a client with round-robin endpoint list 32 | func ExampleNewRoundRobinEndpoints() { 33 | // Create an HTTP connection to the database 34 | endpoint := connection.NewRoundRobinEndpoints([]string{"https://a:8529", "https://a:8539", "https://b: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 | // Create a client 45 | client := arangodb.NewClient(conn) 46 | 47 | // Ask the version of the server 48 | versionInfo, err := client.Version(context.Background()) 49 | if err != nil { 50 | log.Printf("Failed to get version info: %v", err) 51 | } 52 | log.Printf("Database has version '%s' and license '%s'\n", versionInfo.Version, versionInfo.License) 53 | } 54 | -------------------------------------------------------------------------------- /v2/arangodb/client_impl.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2020-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 | 21 | package arangodb 22 | 23 | import ( 24 | "github.com/arangodb/go-driver/v2/connection" 25 | ) 26 | 27 | func NewClient(connection connection.Connection) Client { 28 | return newClient(connection) 29 | } 30 | 31 | func newClient(connection connection.Connection) *client { 32 | c := &client{ 33 | connection: connection, 34 | } 35 | 36 | c.clientDatabase = newClientDatabase(c) 37 | c.clientUser = newClientUser(c) 38 | c.clientServerInfo = newClientServerInfo(c) 39 | c.clientAdmin = newClientAdmin(c) 40 | c.clientAsyncJob = newClientAsyncJob(c) 41 | c.clientFoxx = newClientFoxx(c) 42 | c.clientTask = newClientTask(c) 43 | c.clientReplication = newClientReplication(c) 44 | c.clientAccessTokens = newClientAccessTokens(c) 45 | 46 | c.Requests = NewRequests(connection) 47 | 48 | return c 49 | } 50 | 51 | var _ Client = &client{} 52 | 53 | type client struct { 54 | connection connection.Connection 55 | 56 | *clientDatabase 57 | *clientUser 58 | *clientServerInfo 59 | *clientAdmin 60 | *clientAsyncJob 61 | *clientFoxx 62 | *clientTask 63 | *clientReplication 64 | *clientAccessTokens 65 | 66 | Requests 67 | } 68 | 69 | func (c *client) Connection() connection.Connection { 70 | return c.connection 71 | } 72 | -------------------------------------------------------------------------------- /v2/examples/example_client_retry_on_503_test.go: -------------------------------------------------------------------------------- 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 | } 58 | -------------------------------------------------------------------------------- /v2/tests/utils_retry_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2020-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 tests 22 | 23 | import ( 24 | "errors" 25 | "fmt" 26 | "testing" 27 | "time" 28 | 29 | "github.com/stretchr/testify/require" 30 | ) 31 | 32 | // defaultTestTimeout is the default timeout for context use in tests 33 | // less than 2 minutes is causing problems on CI 34 | const defaultTestTimeout = 20 * time.Minute 35 | 36 | type Timeout func() error 37 | 38 | func NewTimeout(f func() error) Timeout { 39 | return f 40 | } 41 | 42 | func (t Timeout) TimeoutT(test testing.TB, timeout, interval time.Duration) { 43 | require.NoError(test, t.Timeout(timeout, interval)) 44 | } 45 | 46 | func (t Timeout) Timeout(timeout, interval time.Duration) error { 47 | timeoutT := time.NewTimer(timeout) 48 | defer timeoutT.Stop() 49 | intervalT := time.NewTicker(interval) 50 | defer intervalT.Stop() 51 | 52 | for { 53 | err := t() 54 | if err != nil { 55 | var interrupt Interrupt 56 | if errors.As(err, &interrupt) { 57 | return nil 58 | } 59 | 60 | return err 61 | } 62 | 63 | select { 64 | case <-timeoutT.C: 65 | return fmt.Errorf("Timeouted") 66 | case <-intervalT.C: 67 | continue 68 | } 69 | } 70 | } 71 | 72 | type Interrupt struct { 73 | } 74 | 75 | func (i Interrupt) Error() string { 76 | return "interrupt" 77 | } 78 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ArangoDB Go Driver 2 | 3 | This project contains the official Go driver for the [ArangoDB database system](https://arangodb.com). 4 | 5 | [![CircleCI](https://dl.circleci.com/status-badge/img/gh/arangodb/go-driver/tree/master.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/arangodb/go-driver/tree/master) 6 | [![GoDoc](https://godoc.org/github.com/arangodb/go-driver?status.svg)](http://godoc.org/github.com/arangodb/go-driver) 7 | 8 | Version 2: 9 | - [Tutorial](https://docs.arangodb.com/stable/develop/drivers/go/) 10 | - [Code examples](v2/examples/) 11 | - [Reference documentation](https://godoc.org/github.com/arangodb/go-driver/v2) 12 | 13 | Version 1: 14 | - ⚠️ This version is deprecated and will not receive any new features. 15 | Please use version 2 ([v2/](v2/)) instead. 16 | - [Tutorial](Tutorial_v1.md) 17 | - [Code examples](examples/) 18 | - [Reference documentation](https://godoc.org/github.com/arangodb/go-driver) 19 | 20 | ## Supported Go Versions 21 | 22 | | Driver | Go 1.19 | Go 1.20 | Go 1.21 | 23 | |---------------|---------|---------|---------| 24 | | `1.5.0-1.6.1` | ✓ | - | - | 25 | | `1.6.2` | ✓ | ✓ | ✓ | 26 | | `2.1.0` | ✓ | ✓ | ✓ | 27 | | `master` | ✓ | ✓ | ✓ | 28 | 29 | ## Supported ArangoDB Versions 30 | 31 | | Driver | ArangoDB 3.10 | ArangoDB 3.11 | ArangoDB 3.12 | 32 | |----------|---------------|---------------|---------------| 33 | | `1.5.0` | ✓ | - | - | 34 | | `1.6.0` | ✓ | ✓ | - | 35 | | `2.1.0` | ✓ | ✓ | ✓ | 36 | | `master` | + | + | + | 37 | 38 | Key: 39 | 40 | * `✓` Exactly the same features in both the driver and the ArangoDB version. 41 | * `+` Features included in the driver may be not present in the ArangoDB API. 42 | Calls to ArangoDB may result in unexpected responses (404). 43 | * `-` The ArangoDB version has features that are not supported by the driver. 44 | -------------------------------------------------------------------------------- /vst/doc.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2018 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 | // Author Ewout Prangsma 21 | // 22 | 23 | /* 24 | Package vst implements driver.Connection using a VelocyStream connection. 25 | 26 | This connection uses VelocyStream (with optional TLS) to connect to the ArangoDB database. 27 | It encodes its contents as Velocypack. 28 | 29 | # Creating an Insecure Connection 30 | 31 | To create a VST connection, use code like this. 32 | 33 | // Create a VST connection to the database 34 | conn, err := vst.NewConnection(vst.ConnectionConfig{ 35 | Endpoints: []string{"http://localhost:8529"}, 36 | }) 37 | if err != nil { 38 | // Handle error 39 | } 40 | 41 | The resulting connection is used to create a client which you will use 42 | for normal database requests. 43 | 44 | // Create a client 45 | c, err := driver.NewClient(driver.ClientConfig{ 46 | Connection: conn, 47 | }) 48 | if err != nil { 49 | // Handle error 50 | } 51 | 52 | # Creating a Secure Connection 53 | 54 | To create a secure VST connection, use code like this. 55 | 56 | // Create a VST over TLS connection to the database 57 | conn, err := vst.NewConnection(vst.ConnectionConfig{ 58 | Endpoints: []string{"https://localhost:8529"}, 59 | TLSConfig: &tls.Config{ 60 | InsecureSkipVerify: trueWhenUsingNonPublicCertificates, 61 | }, 62 | }) 63 | if err != nil { 64 | // Handle error 65 | } 66 | */ 67 | package vst 68 | -------------------------------------------------------------------------------- /meta.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2017 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 | // Author Ewout Prangsma 21 | // 22 | 23 | package driver 24 | 25 | // DocumentMeta contains all meta data used to identifier a document. 26 | type DocumentMeta struct { 27 | Key string `json:"_key,omitempty"` 28 | ID DocumentID `json:"_id,omitempty"` 29 | Rev string `json:"_rev,omitempty"` 30 | OldRev string `json:"_oldRev,omitempty"` 31 | } 32 | 33 | // validateKey returns an error if the given key is empty otherwise invalid. 34 | func validateKey(key string) error { 35 | if key == "" { 36 | return WithStack(InvalidArgumentError{Message: "key is empty"}) 37 | } 38 | return nil 39 | } 40 | 41 | // DocumentMetaSlice is a slice of DocumentMeta elements 42 | type DocumentMetaSlice []DocumentMeta 43 | 44 | // Keys returns the keys of all elements. 45 | func (l DocumentMetaSlice) Keys() []string { 46 | keys := make([]string, len(l)) 47 | for i, m := range l { 48 | keys[i] = m.Key 49 | } 50 | return keys 51 | } 52 | 53 | // Revs returns the revisions of all elements. 54 | func (l DocumentMetaSlice) Revs() []string { 55 | revs := make([]string, len(l)) 56 | for i, m := range l { 57 | revs[i] = m.Rev 58 | } 59 | return revs 60 | } 61 | 62 | // IDs returns the ID's of all elements. 63 | func (l DocumentMetaSlice) IDs() []DocumentID { 64 | ids := make([]DocumentID, len(l)) 65 | for i, m := range l { 66 | ids[i] = m.ID 67 | } 68 | return ids 69 | } 70 | -------------------------------------------------------------------------------- /v2/connection/connection_http_response_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2021-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 | 21 | package connection 22 | 23 | import ( 24 | "net/http" 25 | "testing" 26 | 27 | "github.com/stretchr/testify/assert" 28 | ) 29 | 30 | func Test_httpResponse_Content(t *testing.T) { 31 | 32 | t.Run("pure content type", func(t *testing.T) { 33 | j := httpResponse{ 34 | response: &http.Response{ 35 | Header: map[string][]string{}, 36 | }, 37 | } 38 | j.response.Header.Set(ContentType, "application/json") 39 | 40 | assert.Equal(t, "application/json", j.Content()) 41 | }) 42 | 43 | t.Run("content type with the arguments", func(t *testing.T) { 44 | j := httpResponse{ 45 | response: &http.Response{ 46 | Header: map[string][]string{}, 47 | }, 48 | } 49 | j.response.Header.Set(ContentType, "text/plain; charset=UTF-8") 50 | 51 | assert.Equal(t, "text/plain", j.Content()) 52 | }) 53 | 54 | t.Run("empty content type", func(t *testing.T) { 55 | j := httpResponse{ 56 | response: &http.Response{ 57 | Header: map[string][]string{}, 58 | }, 59 | } 60 | j.response.Header.Set(ContentType, "") 61 | 62 | assert.Equal(t, "", j.Content()) 63 | }) 64 | 65 | t.Run("content type header does not exist", func(t *testing.T) { 66 | j := httpResponse{ 67 | response: &http.Response{ 68 | Header: map[string][]string{}, 69 | }, 70 | } 71 | 72 | assert.Equal(t, "", j.Content()) 73 | }) 74 | } 75 | -------------------------------------------------------------------------------- /test/json_agency_config_parse_leader_id/json_agency_config_parse_leader_id.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2025 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 main 22 | 23 | import ( 24 | "encoding/json" 25 | "errors" 26 | "fmt" 27 | "io" 28 | "os" 29 | ) 30 | 31 | func ExtractValue(input io.Reader) error { 32 | var data map[string]interface{} 33 | 34 | decoder := json.NewDecoder(input) 35 | if err := decoder.Decode(&data); err != nil { 36 | return fmt.Errorf("failed to decode JSON: %w", err) 37 | } 38 | 39 | configuration, ok := data["configuration"].(map[string]interface{}) 40 | if !ok { 41 | return errors.New("key 'configuration' not found or not an object") 42 | } 43 | pool, ok := configuration["pool"].(map[string]interface{}) 44 | if !ok { 45 | return errors.New("key 'pool' not found or not an array") 46 | } 47 | 48 | leaderId, ok := data["leaderId"].(string) 49 | if !ok { 50 | return errors.New("key 'leaderId' not found or not a str") 51 | } 52 | if leaderId == "" { 53 | return errors.New("key 'leaderId' not set") 54 | } 55 | 56 | endpoint, ok := pool[leaderId].(string) 57 | if !ok { 58 | return fmt.Errorf("key '%s' not found or not a str", leaderId) 59 | } 60 | fmt.Println(endpoint) 61 | 62 | return nil 63 | } 64 | 65 | func main() { 66 | if err := ExtractValue(os.Stdin); err != nil { 67 | fmt.Fprintf(os.Stderr, "JsonAgencyConfigParseError: %v\n and as a result the agency dump could not be created.\n", err) 68 | 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /test/server_metrics_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2018-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 | 21 | package test 22 | 23 | import ( 24 | "context" 25 | "testing" 26 | 27 | "github.com/stretchr/testify/require" 28 | 29 | "github.com/arangodb/go-driver" 30 | ) 31 | 32 | // TestGetServerMetrics tests if Client.Metrics works at all 33 | func TestGetServerMetrics(t *testing.T) { 34 | c := createClient(t, nil) 35 | ctx := context.Background() 36 | skipBelowVersion(c, "3.8", t) 37 | 38 | metrics, err := c.Metrics(ctx) 39 | require.NoError(t, err) 40 | require.Contains(t, string(metrics), "arangodb_client_connection_statistics_total_time") 41 | } 42 | 43 | // TestGetServerMetricsForSingleServer tests if Client.MetricsForSingleServer works at all 44 | func TestGetServerMetricsForSingleServer(t *testing.T) { 45 | c := createClient(t, nil) 46 | ctx := context.Background() 47 | skipBelowVersion(c, "3.8", t) 48 | skipNoCluster(c, t) 49 | 50 | cl, err := c.Cluster(ctx) 51 | require.NoError(t, err) 52 | 53 | h, err := cl.Health(ctx) 54 | require.NoError(t, err) 55 | 56 | for id, sh := range h.Health { 57 | if sh.Role == driver.ServerRoleDBServer || sh.Role == driver.ServerRoleCoordinator { 58 | metrics, err := c.MetricsForSingleServer(ctx, string(id)) 59 | require.NoError(t, err) 60 | require.Contains(t, string(metrics), "arangodb_client_connection_statistics_total_time") 61 | require.Contains(t, string(metrics), sh.ShortName) 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /http/doc.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2018 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 | // Author Ewout Prangsma 21 | // 22 | 23 | /* 24 | Package http implements driver.Connection using an HTTP connection. 25 | 26 | This connection uses HTTP or HTTPS to connect to the ArangoDB database and 27 | encodes its content as JSON or Velocypack, depending on the value 28 | of the `ContentType` fields in the `http.ConnectionConfig`. 29 | 30 | # Creating an Insecure Connection 31 | 32 | To create an HTTP connection, use code like this. 33 | 34 | // Create an HTTP connection to the database 35 | conn, err := http.NewConnection(http.ConnectionConfig{ 36 | Endpoints: []string{"http://localhost:8529"}, 37 | }) 38 | if err != nil { 39 | // Handle error 40 | } 41 | 42 | The resulting connection is used to create a client which you will use 43 | for normal database requests. 44 | 45 | // Create a client 46 | c, err := driver.NewClient(driver.ClientConfig{ 47 | Connection: conn, 48 | }) 49 | if err != nil { 50 | // Handle error 51 | } 52 | 53 | # Creating a Secure Connection 54 | 55 | To create a secure HTTPS connection, use code like this. 56 | 57 | // Create an HTTPS connection to the database 58 | conn, err := http.NewConnection(http.ConnectionConfig{ 59 | Endpoints: []string{"https://localhost:8529"}, 60 | TLSConfig: &tls.Config{ 61 | InsecureSkipVerify: trueWhenUsingNonPublicCertificates, 62 | }, 63 | }) 64 | if err != nil { 65 | // Handle error 66 | } 67 | */ 68 | package http 69 | -------------------------------------------------------------------------------- /v2/tests/documents_def_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2020-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 | 21 | package tests 22 | 23 | type DocWithRev struct { 24 | Rev string `json:"_rev,omitempty"` 25 | Key string `json:"_key,omitempty"` 26 | Name string `json:"name"` 27 | Age *int `json:"age"` 28 | Countries map[string]int `json:"countries"` 29 | } 30 | 31 | type DocIDGetter interface { 32 | GetKey() string 33 | } 34 | 35 | type basicDocuments []basicDocument 36 | 37 | func (b basicDocuments) getKeys() []string { 38 | l := make([]string, len(b)) 39 | 40 | for i, g := range b { 41 | l[i] = g.GetKey() 42 | } 43 | 44 | return l 45 | } 46 | 47 | type basicDocument struct { 48 | Key string `json:"_key"` 49 | } 50 | 51 | func newBasicDocument() basicDocument { 52 | return basicDocument{ 53 | Key: GenerateUUID("test-doc-basic"), 54 | } 55 | } 56 | 57 | func (d basicDocument) GetKey() string { 58 | return d.Key 59 | } 60 | 61 | type documents []document 62 | 63 | func (d documents) asBasic() basicDocuments { 64 | z := make([]basicDocument, len(d)) 65 | 66 | for i, q := range d { 67 | z[i] = q.basicDocument 68 | } 69 | 70 | return z 71 | } 72 | 73 | type document struct { 74 | basicDocument `json:",inline"` 75 | Fields interface{} `json:"data,omitempty"` 76 | } 77 | 78 | func newDocs(c int) documents { 79 | r := make([]document, c) 80 | 81 | for i := 0; i < c; i++ { 82 | r[i].basicDocument = newBasicDocument() 83 | } 84 | 85 | return r 86 | } 87 | -------------------------------------------------------------------------------- /v2/connection/decoder_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2020 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 connection 21 | 22 | import ( 23 | "bytes" 24 | "strings" 25 | "testing" 26 | 27 | "github.com/stretchr/testify/assert" 28 | "github.com/stretchr/testify/require" 29 | ) 30 | 31 | func Test_bytesDecoder_Decode(t *testing.T) { 32 | t.Run("got response", func(t *testing.T) { 33 | response := "the response" 34 | var output []byte 35 | 36 | err := bytesDecoder{}.Decode(strings.NewReader(response), &output) 37 | require.NoError(t, err) 38 | require.NotNilf(t, output, "the output should be allocated in the decoder") 39 | assert.Equal(t, string(output), response) 40 | }) 41 | 42 | t.Run("invalid output argument", func(t *testing.T) { 43 | var output string 44 | 45 | err := bytesDecoder{}.Decode(strings.NewReader("the response"), &output) 46 | require.EqualError(t, err, ErrReaderOutputBytes.Error()) 47 | assert.Equal(t, "", output, "the output should be empty") 48 | }) 49 | } 50 | 51 | func Test_bytesDecoder_Encode(t *testing.T) { 52 | t.Run("send request", func(t *testing.T) { 53 | var buf bytes.Buffer 54 | request := "the request" 55 | 56 | err := bytesDecoder{}.Encode(&buf, []byte(request)) 57 | 58 | require.NoError(t, err) 59 | assert.Equal(t, request, string(buf.Bytes())) 60 | }) 61 | 62 | t.Run("invalid input argument", func(t *testing.T) { 63 | var buf bytes.Buffer 64 | 65 | err := bytesDecoder{}.Encode(&buf, "string") 66 | require.EqualError(t, err, ErrWriterInputBytes.Error()) 67 | }) 68 | } 69 | -------------------------------------------------------------------------------- /examples/main_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2020-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 | 21 | package examples 22 | 23 | import ( 24 | "context" 25 | "log" 26 | "os" 27 | "testing" 28 | "time" 29 | 30 | "github.com/arangodb/go-driver" 31 | "github.com/arangodb/go-driver/http" 32 | ) 33 | 34 | // TestMain creates a simple connection and waits for the server to be ready. 35 | // This avoid a lot of clutter code in the examples. 36 | func TestMain(m *testing.M) { 37 | // Wait for database connection to be ready. 38 | conn, err := http.NewConnection(http.ConnectionConfig{ 39 | Endpoints: []string{"http://localhost:8529"}, 40 | }) 41 | if err != nil { 42 | log.Fatalf("Failed to create HTTP connection: %v", err) 43 | } 44 | c, err := driver.NewClient(driver.ClientConfig{ 45 | Connection: conn, 46 | }) 47 | 48 | waitUntilServerAvailable(context.Background(), c) 49 | 50 | os.Exit(m.Run()) 51 | } 52 | 53 | // waitUntilServerAvailable keeps waiting until the server/cluster that the client is addressing is available. 54 | func waitUntilServerAvailable(ctx context.Context, c driver.Client) bool { 55 | instanceUp := make(chan bool) 56 | go func() { 57 | for { 58 | verCtx, cancel := context.WithTimeout(ctx, time.Second*5) 59 | if _, err := c.Version(verCtx); err == nil { 60 | cancel() 61 | instanceUp <- true 62 | return 63 | } else { 64 | cancel() 65 | time.Sleep(time.Second) 66 | } 67 | } 68 | }() 69 | select { 70 | case up := <-instanceUp: 71 | return up 72 | case <-ctx.Done(): 73 | return false 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /v2/examples/example_client_maglev_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2023-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 | // ExampleNewMaglevHashEndpoints shows how to create a new MaglevHashEndpoints 32 | // It lets use different endpoints for different databases by using a RequestDBNameValueExtractor function. 33 | // E.g.: 34 | // - all requests to _db/ will use endpoint 1 35 | // - all requests to _db/ will use endpoint 2 36 | func ExampleNewMaglevHashEndpoints() { 37 | // Create an HTTP connection to the database 38 | endpoint, err := connection.NewMaglevHashEndpoints( 39 | []string{"https://a:8529", "https://a:8539", "https://b:8529"}, 40 | connection.RequestDBNameValueExtractor, 41 | ) 42 | 43 | conn := connection.NewHttp2Connection(connection.DefaultHTTP2ConfigurationWrapper(endpoint, true)) 44 | 45 | // Add authentication 46 | auth := connection.NewBasicAuth("root", "") 47 | err = conn.SetAuthentication(auth) 48 | if err != nil { 49 | log.Fatalf("Failed to set authentication: %v", err) 50 | } 51 | 52 | // Create a client 53 | client := arangodb.NewClient(conn) 54 | 55 | // Ask the version of the server 56 | versionInfo, err := client.Version(context.Background()) 57 | if err != nil { 58 | log.Printf("Failed to get version info: %v", err) 59 | } 60 | log.Printf("Database has version '%s' and license '%s'\n", versionInfo.Version, versionInfo.License) 61 | } 62 | -------------------------------------------------------------------------------- /v2/tests/utils_client_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2020-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 | 21 | package tests 22 | 23 | import ( 24 | "os" 25 | "strings" 26 | "testing" 27 | 28 | "github.com/stretchr/testify/require" 29 | 30 | "github.com/arangodb/go-driver/v2/connection" 31 | ) 32 | 33 | func createAuthenticationFromEnv(t testing.TB, conn connection.Connection) connection.Connection { 34 | authSpec := os.Getenv("TEST_AUTHENTICATION") 35 | if authSpec == "" { 36 | return conn 37 | } 38 | parts := strings.Split(authSpec, ":") 39 | switch parts[0] { 40 | case "basic": 41 | if len(parts) != 3 { 42 | t.Fatalf("Expected username & password for basic authentication") 43 | } 44 | auth := connection.NewBasicAuth(parts[1], parts[2]) 45 | 46 | require.NoError(t, conn.SetAuthentication(auth)) 47 | 48 | return conn 49 | case "jwt": 50 | if len(parts) != 3 { 51 | t.Fatalf("Expected username & password for jwt authentication") 52 | } 53 | return connection.NewJWTAuthWrapper(parts[1], parts[2])(conn) 54 | default: 55 | t.Fatalf("Unknown authentication: '%s'", parts[0]) 56 | return nil 57 | } 58 | } 59 | 60 | // getEndpointsFromEnv returns the endpoints specified in the TEST_ENDPOINTS environment variable. 61 | func getEndpointsFromEnv(t testing.TB) []string { 62 | v, ok := os.LookupEnv("TEST_ENDPOINTS") 63 | if !ok { 64 | t.Fatal("No endpoints found in environment variable TEST_ENDPOINTS") 65 | } 66 | 67 | eps := strings.Split(v, ",") 68 | if len(eps) == 0 { 69 | t.Fatal("No endpoints found in environment variable TEST_ENDPOINTS") 70 | } 71 | return eps 72 | } 73 | -------------------------------------------------------------------------------- /agency/operation_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2020 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 | // Author Adam Janikowski 21 | // 22 | 23 | package agency_test 24 | 25 | import ( 26 | "testing" 27 | 28 | "github.com/stretchr/testify/require" 29 | 30 | "github.com/arangodb/go-driver/agency" 31 | ) 32 | 33 | func TestCreateSubKey(t *testing.T) { 34 | testCases := []struct { 35 | name string 36 | elements []string 37 | key agency.Key 38 | }{ 39 | { 40 | name: "Create a new key based on not empty key with not empty elements", 41 | key: agency.Key{"level1", "level2"}, 42 | elements: []string{"level3"}, 43 | }, 44 | { 45 | name: "Create a new key based on not empty key with empty elements", 46 | key: agency.Key{"level1", "level2"}, 47 | }, 48 | { 49 | name: "Create a new key based on empty key", 50 | elements: []string{"level3"}, 51 | }, 52 | { 53 | name: "Create a new key based on empty key with empty elements", 54 | }, 55 | } 56 | 57 | for _, testCase := range testCases { 58 | t.Run(testCase.name, func(t *testing.T) { 59 | newKey := testCase.key.CreateSubKey(testCase.elements...) 60 | 61 | require.Len(t, newKey, len(testCase.key)+len(testCase.elements)) 62 | if len(testCase.key) > 0 && &testCase.key[0] == &newKey[0] { 63 | require.Fail(t, "New key should have always different address") 64 | } 65 | 66 | for i, s := range testCase.key { 67 | require.Equal(t, s, newKey[i]) 68 | } 69 | for i, s := range testCase.elements { 70 | require.Equal(t, s, newKey[i+len(testCase.key)]) 71 | } 72 | }) 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /examples/example_context_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2017-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 | 21 | //go:build !auth 22 | 23 | package examples 24 | 25 | import ( 26 | "context" 27 | "time" 28 | 29 | driver "github.com/arangodb/go-driver" 30 | ) 31 | 32 | func ExampleWithRevision() { 33 | var sampleCollection driver.Collection 34 | var result Book 35 | 36 | // Using WithRevision we get an error when the current revision of the document is different. 37 | ctx := driver.WithRevision(context.Background(), "a-specific-revision") 38 | if _, err := sampleCollection.ReadDocument(ctx, "someValidKey", &result); err != nil { 39 | // This call will fail when a document does not exist, or when its current revision is different. 40 | } 41 | } 42 | 43 | func ExampleWithSilent() { 44 | var sampleCollection driver.Collection 45 | var result Book 46 | 47 | // Using WithSilent we do not care about any returned meta data. 48 | ctx := driver.WithSilent(context.Background()) 49 | if _, err := sampleCollection.ReadDocument(ctx, "someValidKey", &result); err != nil { 50 | // No meta data is returned 51 | } 52 | } 53 | 54 | func ExampleWithArangoQueueTime() { 55 | var sampleCollection driver.Collection 56 | var result Book 57 | 58 | // Using WithArangoQueueTimeout we get Timout error if not response after time specified in WithArangoQueueTime 59 | ctx := driver.WithArangoQueueTimeout(context.Background(), true) 60 | ctx = driver.WithArangoQueueTime(ctx, time.Second*5) 61 | 62 | if _, err := sampleCollection.ReadDocument(ctx, "someValidKey", &result); err != nil { 63 | // This call will fail if no response after 5 sec 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /v2/connection/modifiers.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2020-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 connection 22 | 23 | import ( 24 | "context" 25 | "fmt" 26 | "strings" 27 | "time" 28 | 29 | "github.com/arangodb/go-driver/v2/version" 30 | ) 31 | 32 | func WithTransactionID(transactionID string) RequestModifier { 33 | return func(r Request) error { 34 | r.AddHeader("x-arango-trx-id", transactionID) 35 | return nil 36 | } 37 | } 38 | 39 | func WithFragment(s string) RequestModifier { 40 | return func(r Request) error { 41 | r.SetFragment(s) 42 | return nil 43 | } 44 | } 45 | 46 | func WithQuery(s, value string) RequestModifier { 47 | return func(r Request) error { 48 | r.AddQuery(s, value) 49 | return nil 50 | } 51 | } 52 | 53 | func applyArangoDBConfiguration(config ArangoDBConfiguration, ctx context.Context) RequestModifier { 54 | return func(r Request) error { 55 | // Set version header 56 | val := fmt.Sprintf("go-driver-v2/%s", version.DriverVersion()) 57 | if len(config.DriverFlags) > 0 { 58 | val = fmt.Sprintf("%s (%s)", val, strings.Join(config.DriverFlags, ",")) 59 | } 60 | r.AddHeader("x-arango-driver", val) 61 | 62 | if config.ArangoQueueTimeoutEnabled { 63 | if config.ArangoQueueTimeoutSec > 0 { 64 | r.AddHeader("x-arango-queue-time-seconds", fmt.Sprint(config.ArangoQueueTimeoutSec)) 65 | } else if deadline, ok := ctx.Deadline(); ok { 66 | timeout := deadline.Sub(time.Now()) 67 | r.AddHeader("x-arango-queue-time-seconds", fmt.Sprint(timeout.Seconds())) 68 | } 69 | } 70 | 71 | newCompression(config.Compression).ApplyRequestHeaders(r) 72 | 73 | return nil 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /v2/arangodb/database_opts.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2020-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 arangodb 22 | 23 | // DatabaseInfo contains information about a database 24 | type DatabaseInfo struct { 25 | // The identifier of the database. 26 | ID string `json:"id,omitempty"` 27 | 28 | // The name of the database. 29 | Name string `json:"name,omitempty"` 30 | 31 | // The filesystem path of the database. 32 | Path string `json:"path,omitempty"` 33 | 34 | // If true then the database is the _system database. 35 | IsSystem bool `json:"isSystem,omitempty"` 36 | 37 | // Default replication factor for collections in database 38 | ReplicationFactor ReplicationFactor `json:"replicationFactor,omitempty"` 39 | 40 | // Default write concern for collections in database 41 | WriteConcern int `json:"writeConcern,omitempty"` 42 | 43 | // Default sharding for collections in database 44 | Sharding DatabaseSharding `json:"sharding,omitempty"` 45 | 46 | // Replication version used for this database 47 | ReplicationVersion DatabaseReplicationVersion `json:"replicationVersion,omitempty"` 48 | } 49 | 50 | // EngineType indicates type of database engine being used. 51 | type EngineType string 52 | 53 | const ( 54 | EngineTypeMMFiles = EngineType("mmfiles") 55 | EngineTypeRocksDB = EngineType("rocksdb") 56 | ) 57 | 58 | func (t EngineType) String() string { 59 | return string(t) 60 | } 61 | 62 | // EngineInfo contains information about the database engine being used. 63 | type EngineInfo struct { 64 | Type EngineType `json:"name"` 65 | } 66 | 67 | type KeyGeneratorsResponse struct { 68 | KeyGenerators []string `json:"keyGenerators"` 69 | } 70 | -------------------------------------------------------------------------------- /v2/tests/graph_helper_test.go: -------------------------------------------------------------------------------- 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 tests 22 | 23 | import ( 24 | "context" 25 | "testing" 26 | 27 | "github.com/arangodb/go-driver/v2/utils" 28 | 29 | "github.com/stretchr/testify/require" 30 | 31 | "github.com/arangodb/go-driver/v2/arangodb" 32 | "github.com/arangodb/go-driver/v2/arangodb/shared" 33 | ) 34 | 35 | func sampleSmartGraph() *arangodb.GraphDefinition { 36 | return &arangodb.GraphDefinition{ 37 | NumberOfShards: utils.NewType(3), 38 | SmartGraphAttribute: "key", 39 | IsSmart: true, 40 | } 41 | } 42 | 43 | func sampleGraphWithEdges(db arangodb.Database) *arangodb.GraphDefinition { 44 | edge := db.Name() + "_edge" 45 | to := db.Name() + "_to-coll" 46 | from := db.Name() + "_from-coll" 47 | 48 | g := sampleSmartGraph() 49 | g.Name = db.Name() + "_graph" 50 | g.EdgeDefinitions = []arangodb.EdgeDefinition{ 51 | { 52 | Collection: edge, 53 | To: []string{to}, 54 | From: []string{from}, 55 | }, 56 | } 57 | g.OrphanCollections = []string{"orphan1", "orphan2"} 58 | 59 | return g 60 | } 61 | 62 | func ensureVertex(t *testing.T, ctx context.Context, graph arangodb.Graph, collection string, doc interface{}) arangodb.DocumentMeta { 63 | col, err := graph.VertexCollection(ctx, collection) 64 | if err != nil { 65 | if shared.IsNotFound(err) { 66 | col, err = graph.CreateVertexCollection(ctx, collection, nil) 67 | require.NoError(t, err) 68 | } 69 | require.NoError(t, err) 70 | } 71 | 72 | meta, err := col.CreateVertex(ctx, doc, nil) 73 | require.NoError(t, err) 74 | 75 | return meta.DocumentMeta 76 | } 77 | -------------------------------------------------------------------------------- /v2/arangodb/database_collection.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2020-2025 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 arangodb 22 | 23 | import ( 24 | "context" 25 | ) 26 | 27 | type DatabaseCollection interface { 28 | // GetCollection opens a connection to an existing collection within the database. 29 | // If no collection with given name exists, an NotFoundError is returned. 30 | GetCollection(ctx context.Context, name string, options *GetCollectionOptions) (Collection, error) 31 | 32 | // CollectionExists returns true if a collection with given name exists within the database. 33 | CollectionExists(ctx context.Context, name string) (bool, error) 34 | 35 | // Collections returns a list of all collections in the database. 36 | Collections(ctx context.Context) ([]Collection, error) 37 | 38 | // CreateCollection creates a new collection with given name and options, and opens a connection to it. 39 | // If a collection with given name already exists within the database, a DuplicateError is returned. 40 | CreateCollectionV2(ctx context.Context, name string, props *CreateCollectionPropertiesV2) (Collection, error) 41 | 42 | // CreateCollectionWithOptions creates a new collection with given name and options, and opens a connection to it. 43 | // If a collection with given name already exists within the database, a DuplicateError is returned. 44 | CreateCollectionWithOptionsV2(ctx context.Context, name string, props *CreateCollectionPropertiesV2, options *CreateCollectionOptions) (Collection, error) 45 | } 46 | 47 | type GetCollectionOptions struct { 48 | // SkipExistCheck skips checking if collection exists 49 | SkipExistCheck bool `json:"skipExistCheck,omitempty"` 50 | } 51 | -------------------------------------------------------------------------------- /v2/arangodb/database_view.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2023-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 arangodb 22 | 23 | import "context" 24 | 25 | type DatabaseView interface { 26 | // View opens a connection to an existing view within the database. 27 | // If no view with given name exists, an NotFoundError is returned. 28 | View(ctx context.Context, name string) (View, error) 29 | 30 | // ViewExists returns true if a view with given name exists within the database. 31 | ViewExists(ctx context.Context, name string) (bool, error) 32 | 33 | // Views returns a reader to iterate over all views in the database 34 | Views(ctx context.Context) (ViewsResponseReader, error) 35 | 36 | // ViewsAll returns all views in the database 37 | ViewsAll(ctx context.Context) ([]View, error) 38 | 39 | // CreateArangoSearchView creates a new view of type ArangoSearch, 40 | // with given name and options, and opens a connection to it. 41 | // If a view with given name already exists within the database, a ConflictError is returned. 42 | CreateArangoSearchView(ctx context.Context, name string, options *ArangoSearchViewProperties) (ArangoSearchView, error) 43 | 44 | // CreateArangoSearchAliasView creates ArangoSearch alias view with given name and options, and opens a connection to it. 45 | // If a view with given name already exists within the database, a ConflictError is returned. 46 | CreateArangoSearchAliasView(ctx context.Context, name string, options *ArangoSearchAliasViewProperties) (ArangoSearchViewAlias, error) 47 | } 48 | 49 | type ViewsResponseReader interface { 50 | // Read returns next View. If no Views left, shared.NoMoreDocumentsError returned 51 | Read() (View, error) 52 | } 53 | -------------------------------------------------------------------------------- /context_read.go: -------------------------------------------------------------------------------- 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 | 21 | package driver 22 | 23 | import "context" 24 | 25 | // IsAsyncRequest returns true if the given context is an async request. 26 | func IsAsyncRequest(ctx context.Context) bool { 27 | if ctx != nil { 28 | if v := ctx.Value(keyAsyncRequest); v != nil { 29 | if isAsync, ok := v.(bool); ok && isAsync { 30 | return true 31 | } 32 | } 33 | } 34 | 35 | return false 36 | } 37 | 38 | // HasAsyncID returns the async Job ID from the given context. 39 | func HasAsyncID(ctx context.Context) (string, bool) { 40 | if ctx != nil { 41 | if q := ctx.Value(keyAsyncID); q != nil { 42 | if v, ok := q.(string); ok { 43 | return v, true 44 | } 45 | } 46 | } 47 | 48 | return "", false 49 | } 50 | 51 | // HasTransactionID returns the transaction ID from the given context. 52 | func HasTransactionID(ctx context.Context) (TransactionID, bool) { 53 | if ctx != nil { 54 | if q := ctx.Value(keyTransactionID); q != nil { 55 | if v, ok := q.(TransactionID); ok { 56 | return v, true 57 | } 58 | } 59 | } 60 | 61 | return "", false 62 | } 63 | 64 | // HasReturnNew is used to fetch the new document from the context. 65 | func HasReturnNew(ctx context.Context) (interface{}, bool) { 66 | if ctx != nil { 67 | if q := ctx.Value(keyReturnNew); q != nil { 68 | return q, true 69 | } 70 | } 71 | return nil, false 72 | } 73 | 74 | // HasReturnOld is used to fetch the old document from the context. 75 | func HasReturnOld(ctx context.Context) (interface{}, bool) { 76 | if ctx != nil { 77 | if q := ctx.Value(keyReturnOld); q != nil { 78 | return q, true 79 | } 80 | } 81 | return nil, false 82 | } 83 | -------------------------------------------------------------------------------- /client_users.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2017 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 | // Author Ewout Prangsma 21 | // 22 | 23 | package driver 24 | 25 | import "context" 26 | 27 | // ClientUsers provides access to the users in a single arangodb database server, or an entire cluster of arangodb servers. 28 | type ClientUsers interface { 29 | // User opens a connection to an existing user. 30 | // If no user with given name exists, an NotFoundError is returned. 31 | User(ctx context.Context, name string) (User, error) 32 | 33 | // UserExists returns true if a user with given name exists. 34 | UserExists(ctx context.Context, name string) (bool, error) 35 | 36 | // Users returns a list of all users found by the client. 37 | Users(ctx context.Context) ([]User, error) 38 | 39 | // CreateUser creates a new user with given name and opens a connection to it. 40 | // If a user with given name already exists, a Conflict error is returned. 41 | CreateUser(ctx context.Context, name string, options *UserOptions) (User, error) 42 | } 43 | 44 | // UserOptions contains options for creating a new user, updating or replacing a user. 45 | type UserOptions struct { 46 | // The user password as a string. If not specified, it will default to an empty string. 47 | Password string `json:"passwd,omitempty"` 48 | // A flag indicating whether the user account should be activated or not. The default value is true. If set to false, the user won't be able to log into the database. 49 | Active *bool `json:"active,omitempty"` 50 | // A JSON object with extra user information. The data contained in extra will be stored for the user but not be interpreted further by ArangoDB. 51 | Extra interface{} `json:"extra,omitempty"` 52 | } 53 | -------------------------------------------------------------------------------- /http/mergeObject.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2017 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 | // Author Ewout Prangsma 21 | // 22 | 23 | package http 24 | 25 | import ( 26 | "encoding/json" 27 | 28 | driver "github.com/arangodb/go-driver" 29 | ) 30 | 31 | // mergeObject is a helper used to merge 2 objects into JSON. 32 | type mergeObject struct { 33 | Object interface{} 34 | Merge interface{} 35 | } 36 | 37 | func (m mergeObject) MarshalJSON() ([]byte, error) { 38 | m1, err := toMap(m.Object) 39 | if err != nil { 40 | return nil, driver.WithStack(err) 41 | } 42 | m2, err := toMap(m.Merge) 43 | if err != nil { 44 | return nil, driver.WithStack(err) 45 | } 46 | var merged map[string]interface{} 47 | // If m1 an empty object? 48 | if len(m1) == 0 { 49 | merged = m2 50 | } else if len(m2) == 0 { 51 | merged = m1 52 | } else { 53 | // Merge 54 | merged = make(map[string]interface{}) 55 | for k, v := range m1 { 56 | merged[k] = v 57 | } 58 | for k, v := range m2 { 59 | merged[k] = v 60 | } 61 | } 62 | // Marshal merged map 63 | data, err := json.Marshal(merged) 64 | if err != nil { 65 | return nil, driver.WithStack(err) 66 | } 67 | return data, nil 68 | } 69 | 70 | // toMap converts the given object to a map (using JSON marshal/unmarshal when needed) 71 | func toMap(object interface{}) (map[string]interface{}, error) { 72 | if m, ok := object.(map[string]interface{}); ok { 73 | return m, nil 74 | } 75 | data, err := json.Marshal(object) 76 | if err != nil { 77 | return nil, driver.WithStack(err) 78 | } 79 | var m map[string]interface{} 80 | if err := json.Unmarshal(data, &m); err != nil { 81 | return nil, driver.WithStack(err) 82 | } 83 | return m, nil 84 | } 85 | -------------------------------------------------------------------------------- /foxx.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2020 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 | // Author Tomasz Mielech 21 | // 22 | 23 | package driver 24 | 25 | import ( 26 | "context" 27 | "net/http" 28 | "os" 29 | "strconv" 30 | ) 31 | 32 | // InstallFoxxService installs a new service at a given mount path. 33 | func (c *client) InstallFoxxService(ctx context.Context, zipFile string, options FoxxCreateOptions) error { 34 | 35 | req, err := c.conn.NewRequest("POST", "_api/foxx") 36 | if err != nil { 37 | return WithStack(err) 38 | } 39 | 40 | req.SetHeader("Content-Type", "application/zip") 41 | req.SetQuery("mount", options.Mount) 42 | 43 | bytes, err := os.ReadFile(zipFile) 44 | if err != nil { 45 | return WithStack(err) 46 | } 47 | 48 | _, err = req.SetBody(bytes) 49 | if err != nil { 50 | return WithStack(err) 51 | } 52 | 53 | resp, err := c.conn.Do(ctx, req) 54 | if err != nil { 55 | return WithStack(err) 56 | } 57 | 58 | if err := resp.CheckStatus(http.StatusCreated); err != nil { 59 | return WithStack(err) 60 | } 61 | 62 | return nil 63 | } 64 | 65 | // UninstallFoxxService uninstalls service at a given mount path. 66 | func (c *client) UninstallFoxxService(ctx context.Context, options FoxxDeleteOptions) error { 67 | req, err := c.conn.NewRequest("DELETE", "_api/foxx/service") 68 | if err != nil { 69 | return WithStack(err) 70 | } 71 | 72 | req.SetQuery("mount", options.Mount) 73 | req.SetQuery("teardown", strconv.FormatBool(options.Teardown)) 74 | 75 | resp, err := c.conn.Do(ctx, req) 76 | if err != nil { 77 | return WithStack(err) 78 | } 79 | 80 | if err := resp.CheckStatus(http.StatusNoContent); err != nil { 81 | return WithStack(err) 82 | } 83 | 84 | return nil 85 | } 86 | -------------------------------------------------------------------------------- /view_arangosearch_impl.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2018 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 | // Author Ewout Prangsma 21 | // 22 | 23 | package driver 24 | 25 | import ( 26 | "context" 27 | "path" 28 | ) 29 | 30 | // viewArangoSearch implements ArangoSearchView 31 | type viewArangoSearch struct { 32 | view 33 | } 34 | 35 | // Properties fetches extended information about the view. 36 | func (v *viewArangoSearch) Properties(ctx context.Context) (ArangoSearchViewProperties, error) { 37 | req, err := v.conn.NewRequest("GET", path.Join(v.relPath(), "properties")) 38 | if err != nil { 39 | return ArangoSearchViewProperties{}, WithStack(err) 40 | } 41 | applyContextSettings(ctx, req) 42 | resp, err := v.conn.Do(ctx, req) 43 | if err != nil { 44 | return ArangoSearchViewProperties{}, WithStack(err) 45 | } 46 | if err := resp.CheckStatus(200); err != nil { 47 | return ArangoSearchViewProperties{}, WithStack(err) 48 | } 49 | var data ArangoSearchViewProperties 50 | if err := resp.ParseBody("", &data); err != nil { 51 | return ArangoSearchViewProperties{}, WithStack(err) 52 | } 53 | return data, nil 54 | } 55 | 56 | // SetProperties changes properties of the view. 57 | func (v *viewArangoSearch) SetProperties(ctx context.Context, options ArangoSearchViewProperties) error { 58 | req, err := v.conn.NewRequest("PUT", path.Join(v.relPath(), "properties")) 59 | if err != nil { 60 | return WithStack(err) 61 | } 62 | if _, err := req.SetBody(options); err != nil { 63 | return WithStack(err) 64 | } 65 | applyContextSettings(ctx, req) 66 | resp, err := v.conn.Do(ctx, req) 67 | if err != nil { 68 | return WithStack(err) 69 | } 70 | if err := resp.CheckStatus(200); err != nil { 71 | return WithStack(err) 72 | } 73 | return nil 74 | } 75 | -------------------------------------------------------------------------------- /http/authentication_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2020 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 | // Author Tomasz Mielech 21 | // 22 | 23 | package http 24 | 25 | import ( 26 | "testing" 27 | 28 | "github.com/stretchr/testify/assert" 29 | 30 | "github.com/arangodb/go-driver" 31 | ) 32 | 33 | func TestIsAuthenticationTheSame(t *testing.T) { 34 | testCases := map[string]struct { 35 | auth1 driver.Authentication 36 | auth2 driver.Authentication 37 | expected bool 38 | }{ 39 | "Two authentications are nil": { 40 | expected: true, 41 | }, 42 | "One authentication is nil": { 43 | auth1: driver.BasicAuthentication("", ""), 44 | }, 45 | "Different type of authentication": { 46 | auth1: driver.BasicAuthentication("", ""), 47 | auth2: driver.JWTAuthentication("", ""), 48 | }, 49 | "Raw authentications are different": { 50 | auth1: driver.RawAuthentication(""), 51 | auth2: driver.RawAuthentication("test"), 52 | }, 53 | "Raw authentications are the same": { 54 | auth1: driver.RawAuthentication("test"), 55 | auth2: driver.RawAuthentication("test"), 56 | expected: true, 57 | }, 58 | "Basic authentications are different": { 59 | auth1: driver.BasicAuthentication("test", "test"), 60 | auth2: driver.BasicAuthentication("test", "test1"), 61 | }, 62 | "Basic authentications are the same": { 63 | auth1: driver.BasicAuthentication("test", "test"), 64 | auth2: driver.BasicAuthentication("test", "test"), 65 | expected: true, 66 | }, 67 | } 68 | 69 | for testName, testCase := range testCases { 70 | t.Run(testName, func(t *testing.T) { 71 | equal := IsAuthenticationTheSame(testCase.auth1, testCase.auth2) 72 | assert.Equal(t, testCase.expected, equal) 73 | }) 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /test/types.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2017 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 | // Author Ewout Prangsma 21 | // 22 | 23 | package test 24 | 25 | type UserDoc struct { 26 | Name string `json:"name"` 27 | Age int `json:"age"` 28 | } 29 | 30 | type UserDocWithKey struct { 31 | Key string `json:"_key"` 32 | Name string `json:"name"` 33 | Age int `json:"age"` 34 | } 35 | 36 | type UserDocWithKeyWithOmit struct { 37 | Key string `json:"_key,omitempty"` 38 | Name string `json:"name,omitempty"` 39 | Age int `json:"age,omitempty"` 40 | } 41 | 42 | type NestedFieldsDoc struct { 43 | Name string `json:"name"` 44 | Dimensions []Dimension `json:"dimensions,omitempty"` 45 | } 46 | 47 | type Dimension struct { 48 | Type string `json:"type"` 49 | Value int `json:"value"` 50 | } 51 | 52 | type Account struct { 53 | ID string `json:"id"` 54 | User *UserDoc `json:"user"` 55 | } 56 | 57 | type Book struct { 58 | Title string 59 | } 60 | 61 | type BookWithAuthor struct { 62 | Title string 63 | Author string 64 | } 65 | 66 | type RouteEdge struct { 67 | From string `json:"_from,omitempty"` 68 | To string `json:"_to,omitempty"` 69 | Distance int `json:"distance,omitempty"` 70 | } 71 | 72 | type RouteEdgeWithKey struct { 73 | Key string `json:"_key"` 74 | From string `json:"_from,omitempty"` 75 | To string `json:"_to,omitempty"` 76 | Distance int `json:"distance,omitempty"` 77 | } 78 | 79 | type RelationEdge struct { 80 | From string `json:"_from,omitempty"` 81 | To string `json:"_to,omitempty"` 82 | Type string `json:"type,omitempty"` 83 | } 84 | 85 | type AccountEdge struct { 86 | From string `json:"_from,omitempty"` 87 | To string `json:"_to,omitempty"` 88 | User *UserDoc `json:"user"` 89 | } 90 | -------------------------------------------------------------------------------- /vst/protocol/message_store.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2017 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 | // Author Ewout Prangsma 21 | // 22 | 23 | package protocol 24 | 25 | import ( 26 | "fmt" 27 | "sync" 28 | ) 29 | 30 | type messageStore struct { 31 | mutex sync.RWMutex 32 | messages map[uint64]*Message 33 | } 34 | 35 | // Size returns the number of messages in this store. 36 | func (s *messageStore) Size() int { 37 | s.mutex.RLock() 38 | defer s.mutex.RUnlock() 39 | 40 | return len(s.messages) 41 | } 42 | 43 | // Get returns the message with given id, or nil if not found 44 | func (s *messageStore) Get(id uint64) *Message { 45 | s.mutex.RLock() 46 | defer s.mutex.RUnlock() 47 | 48 | m, ok := s.messages[id] 49 | if ok { 50 | return m 51 | } 52 | return nil 53 | } 54 | 55 | // Add adds a new message to the store with given ID. 56 | // If the ID is not unique this function will panic. 57 | func (s *messageStore) Add(id uint64) *Message { 58 | s.mutex.Lock() 59 | defer s.mutex.Unlock() 60 | 61 | if s.messages == nil { 62 | s.messages = make(map[uint64]*Message) 63 | } 64 | if _, ok := s.messages[id]; ok { 65 | panic(fmt.Sprintf("ID %v is not unique", id)) 66 | } 67 | 68 | m := &Message{ 69 | ID: id, 70 | responseChan: make(chan Message), 71 | } 72 | s.messages[id] = m 73 | return m 74 | } 75 | 76 | // Remove removes the message with given ID from the store. 77 | func (s *messageStore) Remove(id uint64) { 78 | s.mutex.Lock() 79 | defer s.mutex.Unlock() 80 | 81 | delete(s.messages, id) 82 | } 83 | 84 | // ForEach calls the given function for each message in the store. 85 | func (s *messageStore) ForEach(cb func(*Message)) { 86 | s.mutex.RLock() 87 | defer s.mutex.RUnlock() 88 | 89 | for _, m := range s.messages { 90 | cb(m) 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /test/context_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2017-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 | 21 | package test 22 | 23 | import ( 24 | "context" 25 | "testing" 26 | "time" 27 | 28 | "github.com/stretchr/testify/require" 29 | 30 | driver "github.com/arangodb/go-driver" 31 | ) 32 | 33 | // TestContextParentNil calls all WithXyz context functions with a nil parent context. 34 | // This must not crash. 35 | func TestContextParentNil(t *testing.T) { 36 | testValue := func(ctx context.Context) { 37 | ctx.Value("foo") 38 | } 39 | 40 | testValue(driver.WithRevision(nil, "rev")) 41 | testValue(driver.WithRevisions(nil, []string{"rev1", "rev2"})) 42 | testValue(driver.WithReturnNew(nil, make(map[string]interface{}))) 43 | testValue(driver.WithReturnOld(nil, make(map[string]interface{}))) 44 | testValue(driver.WithDetails(nil)) 45 | testValue(driver.WithKeepNull(nil, false)) 46 | testValue(driver.WithMergeObjects(nil, true)) 47 | testValue(driver.WithSilent(nil)) 48 | testValue(driver.WithWaitForSync(nil)) 49 | testValue(driver.WithRawResponse(nil, &[]byte{})) 50 | testValue(driver.WithArangoQueueTimeout(nil, true)) 51 | testValue(driver.WithArangoQueueTime(nil, time.Second*5)) 52 | testValue(driver.WithDriverFlags(nil, []string{"foo", "bar"})) 53 | } 54 | 55 | func TestContextWithArangoQueueTimeoutParams(t *testing.T) { 56 | c := createClient(t, nil) 57 | skipBelowVersion(c, "3.9", t) 58 | 59 | t.Run("without timout", func(t *testing.T) { 60 | _, err := c.Version(context.Background()) 61 | require.NoError(t, err) 62 | }) 63 | 64 | t.Run("without timeout - if no queue timeout and no context deadline set", func(t *testing.T) { 65 | ctx := driver.WithArangoQueueTimeout(context.Background(), true) 66 | 67 | _, err := c.Version(ctx) 68 | require.NoError(t, err) 69 | }) 70 | } 71 | -------------------------------------------------------------------------------- /v2/arangodb/asyncjob.go: -------------------------------------------------------------------------------- 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 | 21 | package arangodb 22 | 23 | import ( 24 | "context" 25 | "time" 26 | ) 27 | 28 | // ClientAsyncJob https://docs.arangodb.com/stable/develop/http-api/jobs/ 29 | type ClientAsyncJob interface { 30 | // AsyncJobList Returns the ids of job results with a specific status 31 | AsyncJobList(ctx context.Context, jobType AsyncJobStatusType, opts *AsyncJobListOptions) ([]string, error) 32 | // AsyncJobStatus Returns the status of a specific job 33 | AsyncJobStatus(ctx context.Context, jobID string) (AsyncJobStatusType, error) 34 | // AsyncJobCancel Cancels a specific async job 35 | AsyncJobCancel(ctx context.Context, jobID string) (bool, error) 36 | // AsyncJobDelete Deletes async job result 37 | AsyncJobDelete(ctx context.Context, deleteType AsyncJobDeleteType, opts *AsyncJobDeleteOptions) (bool, error) 38 | } 39 | 40 | type AsyncJobStatusType string 41 | 42 | const ( 43 | JobDone AsyncJobStatusType = "done" 44 | JobPending AsyncJobStatusType = "pending" 45 | ) 46 | 47 | type AsyncJobListOptions struct { 48 | // Count The maximum number of ids to return per call. 49 | // If not specified, a server-defined maximum value will be used. 50 | Count int `json:"count,omitempty"` 51 | } 52 | 53 | type AsyncJobDeleteType string 54 | 55 | const ( 56 | DeleteAllJobs AsyncJobDeleteType = "all" 57 | DeleteExpiredJobs AsyncJobDeleteType = "expired" 58 | DeleteSingleJob AsyncJobDeleteType = "single" 59 | ) 60 | 61 | type AsyncJobDeleteOptions struct { 62 | // JobID The id of the job to delete. Works only if type is set to 'single'. 63 | JobID string `json:"id,omitempty"` 64 | 65 | // Stamp A Unix timestamp specifying the expiration threshold for when the type is set to 'expired'. 66 | Stamp time.Time `json:"stamp,omitempty"` 67 | } 68 | -------------------------------------------------------------------------------- /asyncjob.go: -------------------------------------------------------------------------------- 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 | 21 | package driver 22 | 23 | import ( 24 | "context" 25 | "time" 26 | ) 27 | 28 | type ClientAsyncJob interface { 29 | AsyncJob() AsyncJobService 30 | } 31 | 32 | // AsyncJobService https://docs.arangodb.com/stable/develop/http-api/jobs/ 33 | type AsyncJobService interface { 34 | // List Returns the ids of job results with a specific status 35 | List(ctx context.Context, jobType AsyncJobStatusType, opts *AsyncJobListOptions) ([]string, error) 36 | // Status Returns the status of a specific job 37 | Status(ctx context.Context, jobID string) (AsyncJobStatusType, error) 38 | // Cancel Cancels a specific async job 39 | Cancel(ctx context.Context, jobID string) (bool, error) 40 | // Delete Deletes async job result 41 | Delete(ctx context.Context, deleteType AsyncJobDeleteType, opts *AsyncJobDeleteOptions) (bool, error) 42 | } 43 | 44 | type AsyncJobStatusType string 45 | 46 | const ( 47 | JobDone AsyncJobStatusType = "done" 48 | JobPending AsyncJobStatusType = "pending" 49 | ) 50 | 51 | type AsyncJobListOptions struct { 52 | // Count The maximum number of ids to return per call. 53 | // If not specified, a server-defined maximum value will be used. 54 | Count int `json:"count,omitempty"` 55 | } 56 | 57 | type AsyncJobDeleteType string 58 | 59 | const ( 60 | DeleteAllJobs AsyncJobDeleteType = "all" 61 | DeleteExpiredJobs AsyncJobDeleteType = "expired" 62 | DeleteSingleJob AsyncJobDeleteType = "single" 63 | ) 64 | 65 | type AsyncJobDeleteOptions struct { 66 | // JobID The id of the job to delete. Works only if type is set to 'single'. 67 | JobID string `json:"id,omitempty"` 68 | 69 | // Stamp A Unix timestamp specifying the expiration threshold for when the type is set to 'expired'. 70 | Stamp time.Time `json:"stamp,omitempty"` 71 | } 72 | -------------------------------------------------------------------------------- /v2/connection/context.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2017-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 connection 22 | 23 | import ( 24 | "context" 25 | ) 26 | 27 | type ContextKey string 28 | 29 | const ( 30 | keyAsyncRequest ContextKey = "arangodb-async-request" 31 | keyAsyncID ContextKey = "arangodb-async-id" 32 | ) 33 | 34 | // contextOrBackground returns the given context if it is not nil. 35 | // Returns context.Background() otherwise. 36 | func contextOrBackground(ctx context.Context) context.Context { 37 | if ctx != nil { 38 | return ctx 39 | } 40 | return context.Background() 41 | } 42 | 43 | // WithAsync is used to configure a context to make an async operation - requires Connection with Async wrapper! 44 | func WithAsync(parent context.Context) context.Context { 45 | return context.WithValue(contextOrBackground(parent), keyAsyncRequest, true) 46 | } 47 | 48 | // WithAsyncID is used to check an async operation result - requires Connection with Async wrapper! 49 | func WithAsyncID(parent context.Context, asyncID string) context.Context { 50 | return context.WithValue(contextOrBackground(parent), keyAsyncID, asyncID) 51 | } 52 | 53 | // 54 | // READ METHODS 55 | // 56 | 57 | // IsAsyncRequest returns true if the given context is an async request. 58 | func IsAsyncRequest(ctx context.Context) bool { 59 | if ctx != nil { 60 | if v := ctx.Value(keyAsyncRequest); v != nil { 61 | if isAsync, ok := v.(bool); ok && isAsync { 62 | return true 63 | } 64 | } 65 | } 66 | 67 | return false 68 | } 69 | 70 | // HasAsyncID returns the async Job ID from the given context. 71 | func HasAsyncID(ctx context.Context) (string, bool) { 72 | if ctx != nil { 73 | if q := ctx.Value(keyAsyncID); q != nil { 74 | if v, ok := q.(string); ok { 75 | return v, true 76 | } 77 | } 78 | } 79 | 80 | return "", false 81 | } 82 | -------------------------------------------------------------------------------- /examples/example_create_documents_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2017-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 | 21 | //go:build !auth 22 | 23 | // This example demonstrates how to create multiple documents at once. 24 | package examples 25 | 26 | import ( 27 | "flag" 28 | "fmt" 29 | "log" 30 | "strings" 31 | 32 | "github.com/arangodb/go-driver" 33 | "github.com/arangodb/go-driver/http" 34 | ) 35 | 36 | type User struct { 37 | Name string `json:"name"` 38 | Age int `json:"age"` 39 | } 40 | 41 | func Example_createDocuments() { 42 | flag.Parse() 43 | conn, err := http.NewConnection(http.ConnectionConfig{ 44 | Endpoints: []string{"http://localhost:8529"}, 45 | }) 46 | if err != nil { 47 | log.Fatalf("Failed to create HTTP connection: %v", err) 48 | } 49 | c, err := driver.NewClient(driver.ClientConfig{ 50 | Connection: conn, 51 | }) 52 | 53 | // Create database 54 | db, err := c.CreateDatabase(nil, "examples_users", nil) 55 | if err != nil { 56 | log.Fatalf("Failed to create database: %v", err) 57 | } 58 | 59 | // Create collection 60 | col, err := db.CreateCollection(nil, "users", nil) 61 | if err != nil { 62 | log.Fatalf("Failed to create collection: %v", err) 63 | } 64 | 65 | // Create documents 66 | users := []User{ 67 | { 68 | Name: "John", 69 | Age: 65, 70 | }, 71 | { 72 | Name: "Tina", 73 | Age: 25, 74 | }, 75 | { 76 | Name: "George", 77 | Age: 31, 78 | }, 79 | } 80 | metas, errs, err := col.CreateDocuments(nil, users) 81 | if err != nil { 82 | log.Fatalf("Failed to create documents: %v", err) 83 | } else if err := errs.FirstNonNil(); err != nil { 84 | log.Fatalf("Failed to create documents: first error: %v", err) 85 | } 86 | 87 | fmt.Printf("Created documents with keys '%s' in collection '%s' in database '%s'\n", strings.Join(metas.Keys(), ","), col.Name(), db.Name()) 88 | } 89 | -------------------------------------------------------------------------------- /database_views.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2018-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 driver 22 | 23 | import "context" 24 | 25 | // DatabaseViews provides access to all views in a single database. 26 | // Views are only available in ArangoDB 3.4 and higher. 27 | type DatabaseViews interface { 28 | // View opens a connection to an existing view within the database. 29 | // If no collection with given name exists, an NotFoundError is returned. 30 | View(ctx context.Context, name string) (View, error) 31 | 32 | // ViewExists returns true if a view with given name exists within the database. 33 | ViewExists(ctx context.Context, name string) (bool, error) 34 | 35 | // Views return a list of all views in the database. 36 | Views(ctx context.Context) ([]View, error) 37 | 38 | // CreateArangoSearchView creates a new view of type ArangoSearch, 39 | // with given name and options, and opens a connection to it. 40 | // If a view with given name already exists within the database, a ConflictError is returned. 41 | CreateArangoSearchView(ctx context.Context, name string, options *ArangoSearchViewProperties) (ArangoSearchView, error) 42 | 43 | // CreateArangoSearchAliasView creates ArangoSearch alias view with given name and options, and opens a connection to it. 44 | // If a view with given name already exists within the database, a ConflictError is returned. 45 | CreateArangoSearchAliasView(ctx context.Context, name string, options *ArangoSearchAliasViewProperties) (ArangoSearchViewAlias, error) 46 | } 47 | 48 | // ViewType is the type of view. 49 | type ViewType string 50 | 51 | const ( 52 | // ViewTypeArangoSearch specifies an ArangoSearch view type. 53 | ViewTypeArangoSearch = ViewType("arangosearch") 54 | // ViewTypeArangoSearchAlias specifies an ArangoSearch view type alias. 55 | ViewTypeArangoSearchAlias = ViewType("search-alias") 56 | ) 57 | -------------------------------------------------------------------------------- /test/on_failure.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "failure!\n" 3 | 4 | echo "\nARANGODB-STARTER logs: " 5 | docker logs ${TESTCONTAINER}-s 6 | 7 | echo -n "\nARANGODB-S-* logs:" 8 | docker ps -f name=${TESTCONTAINER}-s- --format "{{.ID}} {{.Names}}" | xargs -L1 bash -c 'echo -e "\n\tLogs from $1:"; docker logs $0' 9 | 10 | if [ -n "${DUMP_AGENCY_ON_FAILURE}" ] && [ "${TEST_MODE}" = "cluster" ]; then 11 | echo "\nAgency dump..." 12 | 13 | if [ "${TEST_SSL}" = "auto" ]; then 14 | PROTOCOL='https' 15 | else 16 | PROTOCOL='http' 17 | fi 18 | 19 | if [ "${TEST_AUTH}" = "jwt" ] || [ "${TEST_AUTH}" = "rootpw" ] || [ "${TEST_AUTH}" = "jwtsuper" ]; then 20 | JWT_TOKEN=$(bash -c "JWTSECRET=$TEST_JWTSECRET; source ./test/jwt.sh") 21 | AUTH="-H 'authorization: bearer $JWT_TOKEN'" 22 | else 23 | AUTH="" 24 | fi 25 | 26 | SED_DOCKER_NAME_TO_ENDPOINT="s/.*-([a-zA-Z0-9.-]+)-([0-9]+)$/${PROTOCOL}:\/\/\1:\2/" 27 | ANY_ENDPOINT=$(docker ps -f name=${TESTCONTAINER}-s-agent --format '{{.Names}}' | head -n 1 | sed -E $SED_DOCKER_NAME_TO_ENDPOINT) 28 | echo "Any agent endpoint: $ANY_ENDPOINT" 29 | 30 | # _api/agency/config returns leader endpoint with protocol that is usually not supported by curl 31 | AGENCY_CONFIG=$(bash -c "curl -k --no-progress-meter ${AUTH} ${ANY_ENDPOINT}/_api/agency/config") 32 | 33 | # same as: jq -r '.configuration.pool[.leaderId]' 34 | LEADER_ENDPOINT_WITH_UNSUPPORTED_PROTOCOL=$(echo $AGENCY_CONFIG | go run ./test/json_agency_config_parse_leader_id/json_agency_config_parse_leader_id.go | cat) 35 | SED_UNSUPPORTED_PROTOCOL_ENDPOINT_TO_ENDPOINT="s/^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//${PROTOCOL}:\/\//" 36 | LEADER_ENDPOINT=$(echo $LEADER_ENDPOINT_WITH_UNSUPPORTED_PROTOCOL | sed $SED_UNSUPPORTED_PROTOCOL_ENDPOINT_TO_ENDPOINT) 37 | 38 | if expr "$LEADER_ENDPOINT" : "^$PROTOCOL" > /dev/null; then 39 | echo "Leader agent endpoint: $LEADER_ENDPOINT" 40 | DUMP_FILE_PATH=$DUMP_AGENCY_ON_FAILURE 41 | mkdir -p $(dirname ${DUMP_FILE_PATH}) 42 | AGENCY_DUMP=$(bash -c "curl -Lk --no-progress-meter ${AUTH} ${LEADER_ENDPOINT}/_api/agency/state") 43 | echo $AGENCY_DUMP > $DUMP_FILE_PATH 44 | echo "Agency dump created at $(realpath $DUMP_FILE_PATH)" 45 | fi 46 | fi 47 | 48 | echo "\nV${MAJOR_VERSION} Tests with ARGS: TEST_MODE=${TEST_MODE} TEST_AUTH=${TEST_AUTH} TEST_CONTENT_TYPE=${TEST_CONTENT_TYPE} TEST_SSL=${TEST_SSL} TEST_CONNECTION=${TEST_CONNECTION} TEST_CVERSION=${TEST_CVERSION}"; 49 | 50 | echo "\n" 51 | exit 1 -------------------------------------------------------------------------------- /test/wrapper_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2021 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 | // Author Adam Janikowski 21 | // 22 | 23 | package test 24 | 25 | import ( 26 | "context" 27 | "strings" 28 | "time" 29 | 30 | "github.com/arangodb/go-driver" 31 | ) 32 | 33 | func WrapLogger(t testEnv, c driver.Connection) driver.Connection { 34 | return &logWrapper{ 35 | t: t, 36 | c: c, 37 | } 38 | } 39 | 40 | type logWrapper struct { 41 | t testEnv 42 | 43 | c driver.Connection 44 | } 45 | 46 | func (l logWrapper) NewRequest(method, path string) (driver.Request, error) { 47 | return l.c.NewRequest(method, path) 48 | } 49 | 50 | func (l logWrapper) Do(ctx context.Context, req driver.Request) (driver.Response, error) { 51 | t := time.Now() 52 | 53 | if resp, err := l.c.Do(ctx, req); err != nil { 54 | l.t.Logf("Request (UNKNOWN)\t%s\t%s (%s): Failed %s", strings.ToUpper(req.Method()), req.Path(), time.Now().Sub(t).String(), err.Error()) 55 | return resp, err 56 | } else { 57 | l.t.Logf("Request (%s)\t%s\t%s (%s): Code %d", resp.Endpoint(), strings.ToUpper(req.Method()), req.Path(), time.Now().Sub(t).String(), resp.StatusCode()) 58 | return resp, err 59 | } 60 | } 61 | 62 | func (l logWrapper) Unmarshal(data driver.RawObject, result interface{}) error { 63 | return l.c.Unmarshal(data, result) 64 | } 65 | 66 | func (l logWrapper) Endpoints() []string { 67 | return l.c.Endpoints() 68 | } 69 | 70 | func (l logWrapper) UpdateEndpoints(endpoints []string) error { 71 | return l.c.UpdateEndpoints(endpoints) 72 | } 73 | 74 | func (l logWrapper) SetAuthentication(authentication driver.Authentication) (driver.Connection, error) { 75 | if c, err := l.c.SetAuthentication(authentication); err != nil { 76 | return nil, err 77 | } else { 78 | return WrapLogger(l.t, c), nil 79 | } 80 | } 81 | 82 | func (l logWrapper) Protocols() driver.ProtocolSet { 83 | return l.c.Protocols() 84 | } 85 | -------------------------------------------------------------------------------- /examples/example_create_document_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // DISCLAIMER 3 | // 4 | // Copyright 2017-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 | 21 | //go:build !auth 22 | 23 | // This example demonstrates how to create a single document. 24 | package examples 25 | 26 | import ( 27 | "fmt" 28 | "log" 29 | 30 | driver "github.com/arangodb/go-driver" 31 | "github.com/arangodb/go-driver/http" 32 | ) 33 | 34 | type Book struct { 35 | Title string `json:"title"` 36 | NoPages int `json:"no_pages"` 37 | } 38 | 39 | func Example_createDocument() { 40 | conn, err := http.NewConnection(http.ConnectionConfig{ 41 | Endpoints: []string{"http://localhost:8529"}, 42 | }) 43 | if err != nil { 44 | log.Fatalf("Failed to create HTTP connection: %v", err) 45 | } 46 | c, err := driver.NewClient(driver.ClientConfig{ 47 | Connection: conn, 48 | }) 49 | 50 | // Create database 51 | db, err := c.CreateDatabase(nil, "examples_books", nil) 52 | if err != nil { 53 | log.Fatalf("Failed to create database: %v", err) 54 | } 55 | 56 | // Create collection 57 | col, err := db.CreateCollection(nil, "books", nil) 58 | if err != nil { 59 | log.Fatalf("Failed to create collection: %v", err) 60 | } 61 | 62 | // Create document 63 | book := Book{ 64 | Title: "ArangoDB Cookbook", 65 | NoPages: 257, 66 | } 67 | meta, err := col.CreateDocument(nil, book) 68 | if err != nil { 69 | log.Fatalf("Failed to create document: %v", err) 70 | } 71 | fmt.Printf("Created document in collection '%s' in database '%s'\n", col.Name(), db.Name()) 72 | 73 | // Read the document back 74 | var result Book 75 | if _, err := col.ReadDocument(nil, meta.Key, &result); err != nil { 76 | log.Fatalf("Failed to read document: %v", err) 77 | } 78 | fmt.Printf("Read book '%+v'\n", result) 79 | 80 | // Output: 81 | // Created document in collection 'books' in database 'examples_books' 82 | // Read book '{Title:ArangoDB Cookbook NoPages:257}' 83 | } 84 | --------------------------------------------------------------------------------