Merge pull request #124 from cie/go-bindings-cleanup

<rdar://32932617> Go bindings: Use proper import path for fdb imports
This commit is contained in:
Alex Miller 2017-07-10 16:09:00 -07:00 committed by GitHub Enterprise
commit 3efeb474f3
27 changed files with 562 additions and 258 deletions

View File

@ -63,6 +63,6 @@ testers = {
'java_async' : Tester('java', _java_cmd + 'AsyncStackTester', 2040, 500, MAX_API_VERSION),
'java_completable' : Tester('java', _java_completable_cmd + 'StackTester', 2040, 500, MAX_API_VERSION),
'java_completable_async' : Tester('java', _java_completable_cmd + 'AsyncStackTester', 2040, 500, MAX_API_VERSION),
'go' : Tester('go', _absolute_path('go/bin/_stacktester'), 63, 200, MAX_API_VERSION),
'go' : Tester('go', _absolute_path('go/build/bin/_stacktester'), 63, 200, MAX_API_VERSION),
'flow' : Tester('flow', _absolute_path('flow/bin/fdb_flow_tester'), 63, 500, MAX_API_VERSION),
}

9
bindings/go/Gopkg.lock generated Normal file
View File

@ -0,0 +1,9 @@
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "ab4fef131ee828e96ba67d31a7d690bd5f2f42040c6766b1b12fe856f87e0ff7"
solver-name = "gps-cdcl"
solver-version = 1

2
bindings/go/Gopkg.toml Normal file
View File

@ -0,0 +1,2 @@
# The FoundationDB go bindings currently have no external golang dependencies outside of
# the go standard library.

View File

@ -10,10 +10,20 @@ This package requires:
Use of this package requires the selection of a FoundationDB API version at runtime. This package currently supports FoundationDB API versions 200-500.
To install this package, in the top level of this repository run:
To build this package, in the top level of this repository run:
make fdb_go
This will create binary packages for the appropriate platform within the "build" subdirectory of this folder.
To install this package, you can run the "fdb-go-install.sh" script:
./fdb-go-install.sh install
The "install" command of this script does not depend on the presence of the repo in general and will download the repository into
your local go path. Running "localinstall" instead of "install" will use the local copy here (with a symlink) instead
of downloading from the remote repository.
Documentation
-------------

304
bindings/go/fdb-go-install.sh Executable file
View File

@ -0,0 +1,304 @@
#!/bin/bash -eu
#
# fdb-go-install.sh
#
# Installs the FoundationDB Go bindings for a client. This will download
# the repository from the remote repo either into the go directory
# with the appropriate semantic version. It will then build a few
# generated files that need to be present for the go build to work.
# At the end, it has some advice for flags to modify within your
# go environment so that other packages may successfully use this
# library.
#
DESTDIR="${DESTDIR:-}"
FDBVER="${FDBVER:-5.0.1}"
REMOTE="${REMOTE:-github.com}"
FDBREPO="${FDBREPO:-apple/foundationdb}"
status=0
platform=$(uname)
if [[ "${platform}" == "Darwin" ]] ; then
FDBLIBDIR="${FDBLIBDIR:-/usr/local/lib}"
libfdbc="libfdb_c.dylib"
elif [[ "${platform}" == "Linux" ]] ; then
FDBLIBDIR="${FDBLIBDIR:-/usr/lib}"
libfdbc="libfdb_c.so"
else
echo "Unsupported platform ${platform}".
echo "At the moment, only macOS and Linux are supported by this script."
let status="${status} + 1"
fi
filedir=$(cd `dirname "${BASH_SOURCE[0]}"` && pwd)
destdir=""
function printUsage() {
echo "Usage: fdb-go-install.sh <cmd>"
echo
echo "cmd: One of the commands to run. The options are:"
echo " install Download the FDB go bindings and install them"
echo " localinstall Install a into the go path a local copy of the repo"
echo " download Download but do not prepare the FoundationDB bindings"
echo " help Print this help message and then quit"
echo
echo "Command Line Options:"
echo " --fdbver <version> FoundationDB semantic version (default is ${FDBVER})"
echo " -d/--dest-dir <dest> Local location for the repo (default is to place in go path)"
echo
echo "Environment Variable Options:"
echo " REMOTE Remote repository to download from (currently ${REMOTE})"
echo " FDBREPO Repository of FoundationDB library to download (currently ${FDBREPO})"
echo " FDBLIBDIR Directory within which should be the FoundationDB c library (currently ${FDBLIBDIR})"
}
function parseArgs() {
local status=0
if [[ "${#}" -lt 0 ]] ; then
printUsage
let status="${status} + 1"
else
operation="${1}"
shift
if [[ "${operation}" != "install" ]] && [[ "${operation}" != "localinstall" ]] && [[ "${operation}" != "download" ]] && [[ "${operation}" != "help" ]] ; then
echo "Unknown command: ${operation}"
printUsage
let status="${status} + 1"
fi
fi
while [[ "${#}" -gt 0 ]] && [[ "${status}" -eq 0 ]] ; do
local key="${1}"
case "${key}" in
--fdbver)
if [[ "${#}" -lt 2 ]] ; then
echo "No version specified with --fdbver flag"
printUsage
let status="${status} + 1"
else
FDBVER="${2}"
fi
shift
;;
-d|--dest-dir)
if [[ "${#}" -lt 2 ]] ; then
echo "No destination specified with ${key} flag"
printUsage
let status="${status} + 1"
else
destdir="${2}"
fi
shift
;;
*)
echo "Unrecognized argument ${key}"
printUsage
let status="${status} + 1"
esac
shift
done
return "${status}"
}
function checkBin() {
if [[ "${#}" -lt 1 ]] ; then
echo "Usage: checkBin <binary>"
return 1
else
if [[ -n $(which "${1}") ]] ; then
return 0
else
return 1
fi
fi
}
if [[ "${status}" -gt 0 ]] ; then
# We have already failed.
:
elif [[ "${#}" -lt 1 ]] ; then
printUsage
else
required_bins=( 'go' 'git' 'make' 'mono' )
missing_bins=()
for bin in "${required_bins[@]}" ; do
if ! checkBin "${bin}" ; then
missing_bins+=("${bin}")
let status="${status} + 1"
fi
done
if [[ "${status}" -gt 0 ]] ; then
echo "Missing binaries: ${missing_bins[*]}"
elif ! parseArgs ${@} ; then
let status="${status} + 1"
elif [[ "${operation}" == "help" ]] ; then
printUsage
else
# Add go-specific environment variables.
eval $(go env)
golibdir=$(dirname "${GOPATH}/src/${REMOTE}/${FDBREPO}")
if [[ -z "${destdir}" ]] ; then
if [[ "${operation}" == "localinstall" ]] ; then
# Assume its the local directory.
destdir=$(cd "${filedir}/../../.." && pwd)
else
destdir="${golibdir}"
fi
fi
if [[ ! -d "${destdir}" ]] ; then
cmd=( 'mkdir' '-p' "${destdir}" )
echo "${cmd[*]}"
if ! "${cmd[@]}" ; then
let status="${status} + 1"
echo "Could not create destination directory ${destdir}."
fi
fi
# Step 1: Make sure repository is present.
if [[ "${status}" -eq 0 ]] ; then
destdir=$( cd "${destdir}" && pwd ) # Get absolute path of destination dir.
fdbdir="${destdir}/foundation"
if [[ ! -d "${destdir}" ]] ; then
cmd=("mkdir" "-p" "${destdir}")
echo "${cmd[*]}"
if ! "${cmd[@]}" ; then
echo "Could not create destination directory ${destdir}."
let status="${status} + 1"
fi
fi
fi
if [[ "${operation}" == "localinstall" ]] ; then
# No download occurs in this case.
:
else
if [[ -d "${fdbdir}" ]] ; then
echo "Directory ${fdbdir} already exists ; checking out appropriate tag"
cmd1=( 'git' '-C' "${fdbdir}" 'fetch' 'origin' )
cmd2=( 'git' '-C' "${fdbdir}" 'checkout' "release-${FDBVER}" )
if ! echo "${cmd1[*]}" || ! "${cmd1[@]}" ; then
let status="${status} + 1"
echo "Could not pull latest changes from origin"
elif ! echo "${cmd2[*]}" || ! "${cmd2[@]}" ; then
let status="${status} + 1"
echo "Could not checkout tag release-${FDBVER}."
fi
else
echo "Downloading foundation repository into ${destdir}:"
cmd=( 'git' '-C' "${destdir}" 'clone' '--branch' "release-${FDBVER}" "git@${REMOTE}:${FDBREPO}.git" )
echo "${cmd[*]}"
if ! "${cmd[@]}" ; then
let status="${status} + 1"
echo "Could not download repository."
fi
fi
fi
# Step 2: Build generated things.
if [[ "${operation}" == "download" ]] ; then
# The generated files are not created under a strict download.
:
elif [[ "${status}" -eq 0 ]] ; then
echo "Building generated files."
cmd=( 'make' '-C' "${fdbdir}" 'bindings/c/foundationdb/fdb_c_options.g.h' )
echo "${cmd[*]}"
if ! "${cmd[@]}" ; then
let status="${status} + 1"
echo "Could not generate required c header"
else
infile="${fdbdir}/fdbclient/vexillographer/fdb.options"
outfile="${fdbdir}/bindings/go/src/fdb/generated.go"
cmd=( 'go' 'run' "${fdbdir}/bindings/go/src/_util/translate_fdb_options.go" )
echo "${cmd[*]} < ${infile} > ${outfile}"
if ! "${cmd[@]}" < "${infile}" > "${outfile}" ; then
let status="${status} + 1"
echo "Could not generate generated go file."
fi
fi
fi
# Step 3: Add to go path.
if [[ "${operation}" == "download" ]] ; then
# The files are not moved under a strict download.
:
elif [[ "${status}" -eq 0 ]] ; then
linkpath="${GOPATH}/src/${REMOTE}/${FDBREPO}"
if [[ "${linkpath}" == "${fdbdir}" ]] ; then
# Downloaded directly into go path. Skip making the link.
:
elif [[ -e "${linkpath}" ]] ; then
echo "Warning: link path (${linkpath}) already exists. Leaving in place."
else
dirpath=$(dirname "${linkpath}")
if [[ ! -d "${dirpath}" ]] ; then
cmd=( 'mkdir' '-p' "${dirpath}" )
echo "${cmd[*]}"
if ! "${cmd[@]}" ; then
let status="${status} + 1"
echo "Could not create directory for link."
fi
fi
if [[ "${status}" -eq 0 ]] ; then
cmd=( 'ln' '-s' "${fdbdir}" "${linkpath}" )
echo "${cmd[*]}"
if ! "${cmd[@]}" ; then
let status="${status} + 1"
echo "Could not create link within go path."
fi
fi
fi
fi
# Step 4: Build the binaries.
if [[ "${operation}" == "download" ]] ; then
# Do not install if only downloading
:
elif [[ "${status}" -eq 0 ]] ; then
cgo_cflags="-g -O2 -I${linkpath}/bindings/c"
cgo_ldflags="-g -O2 -L${FDBLIBDIR}"
fdb_go_path="${REMOTE}/${FDBREPO}/bindings/go/src"
if [[ ! -e "${FDBLIBDIR}/${libfdbc}" ]] ; then
# Just a warning. Don't fail script.
echo
echo "WARNING: The FoundationDB C library was not found within ${FDBLIBDIR}."
echo "Your installation may be incomplete."
echo
elif ! CGO_CFLAGS="${cgo_cflags}" CGO_LDFLAGS="${cgo_ldflags}" go install "${fdb_go_path}/fdb" "${fdb_go_path}/fdb/tuple" "${fdb_go_path}/fdb/subspace" "${fdb_go_path}/fdb/directory" ; then
let status="${status} + 1"
echo "Could not build FoundationDB go libraries."
fi
fi
# Step 5: Explain CGO flags.
if [[ "${status}" -eq 0 && ("${operation}" == "localinstall" || "${operation}" == "install" ) ]] ; then
echo
echo "The FoundationDB go bindings were successfully installed."
echo "To build packages which use the go bindings, you will need to"
echo "set the following environment variables:"
echo " CGO_CFLAGS=\"${cgo_cflags}\""
echo " CGO_LDFLAGS=\"${cgo_ldflags}\""
fi
fi
fi
exit "${status}"

View File

@ -21,7 +21,11 @@
TARGETS += fdb_go fdb_go_tester
CLEAN_TARGETS += fdb_go_clean fdb_go_tester_clean
GOPATH := $(CURDIR)/bindings/go
GOPATH := $(CURDIR)/bindings/go/build
GO_IMPORT_PATH := github.com/apple/foundationdb/bindings/go/src
GO_DEST := $(GOPATH)/src/$(GO_IMPORT_PATH)
.PHONY: fdb_go fdb_go_path fdb_go_tester fdb_go_tester_clean godoc godoc_clean
# We only override if the environment didn't set it (this is used by
# the fdbwebsite documentation build process)
@ -38,18 +42,23 @@ else
$(error Not prepared to compile on platform $(PLATFORM))
endif
GO_PACKAGE_OUTDIR := $(GOPATH)/pkg/$(GOPLATFORM)
GO_PACKAGE_OUTDIR := $(GOPATH)/pkg/$(GOPLATFORM)/$(GO_IMPORT_PATH)
GO_PACKAGES := fdb fdb/tuple fdb/subspace fdb/directory
GO_PACKAGE_OBJECTS := $(addprefix $(GO_PACKAGE_OUTDIR)/,$(GO_PACKAGES:=.a))
GO_SRC := $(shell find $(GOPATH)/src -name '*.go')
GO_SRC := $(shell find $(CURDIR)/bindings/go/src -name '*.go')
fdb_go: $(GO_PACKAGE_OBJECTS) $(GO_SRC)
fdb_go_path: $(GO_SRC)
@echo "Creating fdb_go_path"
@mkdir -p $(GO_DEST)
@cp -r bindings/go/src/* $(GO_DEST)
fdb_go_clean:
@echo "Cleaning fdb_go"
@rm -rf $(GO_PACKAGE_OUTDIR)
@rm -rf $(GOPATH)
fdb_go_tester: $(GOPATH)/bin/_stacktester
@ -57,40 +66,40 @@ fdb_go_tester_clean:
@echo "Cleaning fdb_go_tester"
@rm -rf $(GOPATH)/bin
$(GOPATH)/bin/_stacktester: $(GO_SRC) $(GO_PACKAGE_OBJECTS) bindings/go/src/fdb/generated.go
$(GOPATH)/bin/_stacktester: fdb_go_path $(GO_SRC) $(GO_PACKAGE_OBJECTS) $(GO_DEST)/fdb/generated.go
@echo "Compiling $(basename $(notdir $@))"
@go install _stacktester
@go install $(GO_IMPORT_PATH)/_stacktester
$(GO_PACKAGE_OUTDIR)/fdb/tuple.a: $(GO_SRC) $(GO_PACKAGE_OUTDIR)/fdb.a bindings/go/src/fdb/generated.go
$(GO_PACKAGE_OUTDIR)/fdb/tuple.a: fdb_go_path $(GO_SRC) $(GO_PACKAGE_OUTDIR)/fdb.a $(GO_DEST)/fdb/generated.go
@echo "Compiling fdb/tuple"
@go install fdb/tuple
@go install $(GO_IMPORT_PATH)/fdb/tuple
$(GO_PACKAGE_OUTDIR)/fdb/subspace.a: $(GO_SRC) $(GO_PACKAGE_OUTDIR)/fdb.a $(GO_PACKAGE_OUTDIR)/fdb/tuple.a bindings/go/src/fdb/generated.go
$(GO_PACKAGE_OUTDIR)/fdb/subspace.a: fdb_go_path $(GO_SRC) $(GO_PACKAGE_OUTDIR)/fdb.a $(GO_PACKAGE_OUTDIR)/fdb/tuple.a $(GO_DEST)/fdb/generated.go
@echo "Compiling fdb/subspace"
@go install fdb/subspace
@go install $(GO_IMPORT_PATH)/fdb/subspace
$(GO_PACKAGE_OUTDIR)/fdb/directory.a: $(GO_SRC) $(GO_PACKAGE_OUTDIR)/fdb.a $(GO_PACKAGE_OUTDIR)/fdb/tuple.a $(GO_PACKAGE_OUTDIR)/fdb/subspace.a bindings/go/src/fdb/generated.go
$(GO_PACKAGE_OUTDIR)/fdb/directory.a: fdb_go_path $(GO_SRC) $(GO_PACKAGE_OUTDIR)/fdb.a $(GO_PACKAGE_OUTDIR)/fdb/tuple.a $(GO_PACKAGE_OUTDIR)/fdb/subspace.a $(GO_DEST)/fdb/generated.go
@echo "Compiling fdb/directory"
@go install fdb/directory
@go install $(GO_IMPORT_PATH)/fdb/directory
$(GO_PACKAGE_OUTDIR)/fdb.a: $(GO_SRC) bindings/go/src/fdb/generated.go
$(GO_PACKAGE_OUTDIR)/fdb.a: fdb_go_path $(GO_SRC) $(GO_DEST)/fdb/generated.go
@echo "Compiling fdb"
@go install fdb
@go install $(GO_IMPORT_PATH)/fdb
bindings/go/src/fdb/generated.go: lib/libfdb_c.$(DLEXT) bindings/go/src/_util/translate_fdb_options.go fdbclient/vexillographer/fdb.options
$(GO_DEST)/fdb/generated.go: fdb_go_path lib/libfdb_c.$(DLEXT) bindings/go/src/_util/translate_fdb_options.go fdbclient/vexillographer/fdb.options
@echo "Building $@"
@go run bindings/go/src/_util/translate_fdb_options.go < fdbclient/vexillographer/fdb.options > $@
godoc: $(GO_SRC)
godoc: fdb_go_path $(GO_SRC)
@echo "Generating Go Documentation"
@rm -rf $(GODOC_DIR)/godoc
@mkdir -p $(GODOC_DIR)/godoc
@mkdir -p $(GODOC_DIR)/godoc/lib/godoc
@godoc -url "http://localhost:6060/pkg/fdb" > $(GODOC_DIR)/godoc/fdb.html
@godoc -url "http://localhost:6060/pkg/fdb/tuple" > $(GODOC_DIR)/godoc/fdb.tuple.html
@godoc -url "http://localhost:6060/pkg/fdb/subspace" > $(GODOC_DIR)/godoc/fdb.subspace.html
@godoc -url "http://localhost:6060/pkg/fdb/directory" > $(GODOC_DIR)/godoc/fdb.directory.html
@cp $(GOPATH)/godoc-resources/* $(GODOC_DIR)/godoc/lib/godoc
@godoc -url "pkg/$(GO_IMPORT_PATH)/fdb" > $(GODOC_DIR)/godoc/fdb.html
@godoc -url "pkg/$(GO_IMPORT_PATH)/fdb/tuple" > $(GODOC_DIR)/godoc/fdb.tuple.html
@godoc -url "pkg/$(GO_IMPORT_PATH)/fdb/subspace" > $(GODOC_DIR)/godoc/fdb.subspace.html
@godoc -url "pkg/$(GO_IMPORT_PATH)/fdb/directory" > $(GODOC_DIR)/godoc/fdb.directory.html
@cp $(CURDIR)/bindings/go/godoc-resources/* $(GODOC_DIR)/godoc/lib/godoc
@echo "Mangling paths in Go Documentation"
@(find $(GODOC_DIR)/godoc/ -name *.html -exec sed -i '' -e 's_/lib_lib_' {} \;)
@(sed -i -e 's_a href="tuple/"_a href="fdb.tuple.html"_' $(GODOC_DIR)/godoc/fdb.html)

View File

@ -21,10 +21,10 @@
package main
import (
"fdb"
"fdb/tuple"
"fdb/subspace"
"fdb/directory"
"github.com/apple/foundationdb/bindings/go/src/fdb"
"github.com/apple/foundationdb/bindings/go/src/fdb/tuple"
"github.com/apple/foundationdb/bindings/go/src/fdb/subspace"
"github.com/apple/foundationdb/bindings/go/src/fdb/directory"
"strings"
"bytes"
)
@ -94,14 +94,14 @@ func (sm *StackMachine) maybePath() []string {
}
var createOps = map[string]bool {
"CREATE_SUBSPACE": true,
"CREATE_LAYER": true,
"CREATE_OR_OPEN": true,
"CREATE": true,
"OPEN": true,
"MOVE": true,
"MOVE_TO": true,
"OPEN_SUBSPACE": true,
"CREATE_SUBSPACE": true,
"CREATE_LAYER": true,
"CREATE_OR_OPEN": true,
"CREATE": true,
"OPEN": true,
"MOVE": true,
"MOVE_TO": true,
"OPEN_SUBSPACE": true,
}
func (de *DirectoryExtension) processOp(sm *StackMachine, op string, isDB bool, idx int, t fdb.Transactor, rt fdb.ReadTransactor) {

View File

@ -24,8 +24,8 @@ import (
"bytes"
"encoding/binary"
"encoding/hex"
"fdb"
"fdb/tuple"
"github.com/apple/foundationdb/bindings/go/src/fdb"
"github.com/apple/foundationdb/bindings/go/src/fdb/tuple"
"log"
"fmt"
"os"

View File

@ -23,8 +23,8 @@
package directory
import (
"fdb"
"fdb/subspace"
"github.com/apple/foundationdb/bindings/go/src/fdb"
"github.com/apple/foundationdb/bindings/go/src/fdb/subspace"
"encoding/binary"
"bytes"
"math/rand"

View File

@ -40,8 +40,8 @@
package directory
import (
"fdb"
"fdb/subspace"
"github.com/apple/foundationdb/bindings/go/src/fdb"
"github.com/apple/foundationdb/bindings/go/src/fdb/subspace"
"errors"
)
@ -140,15 +140,15 @@ type Directory interface {
}
func stringsEqual(a, b []string) bool {
if len(a) != len(b) {
return false
}
for i, v := range a {
if v != b[i] {
return false
}
}
return true
if len(a) != len(b) {
return false
}
for i, v := range a {
if v != b[i] {
return false
}
}
return true
}
func moveTo(t fdb.Transactor, dl directoryLayer, path, newAbsolutePath []string) (DirectorySubspace, error) {

View File

@ -23,9 +23,9 @@
package directory
import (
"fdb"
"fdb/subspace"
"fdb/tuple"
"github.com/apple/foundationdb/bindings/go/src/fdb"
"github.com/apple/foundationdb/bindings/go/src/fdb/subspace"
"github.com/apple/foundationdb/bindings/go/src/fdb/tuple"
"encoding/binary"
"bytes"
"fmt"

View File

@ -23,9 +23,9 @@
package directory
import (
"fdb"
"fdb/subspace"
"fdb/tuple"
"github.com/apple/foundationdb/bindings/go/src/fdb"
"github.com/apple/foundationdb/bindings/go/src/fdb/subspace"
"github.com/apple/foundationdb/bindings/go/src/fdb/tuple"
)
type directoryPartition struct {

View File

@ -23,8 +23,8 @@
package directory
import (
"fdb"
"fdb/subspace"
"github.com/apple/foundationdb/bindings/go/src/fdb"
"github.com/apple/foundationdb/bindings/go/src/fdb/subspace"
)
// DirectorySubspace represents a Directory that may also be used as a Subspace

View File

@ -23,8 +23,8 @@
package directory
import (
"fdb"
"fdb/subspace"
"github.com/apple/foundationdb/bindings/go/src/fdb"
"github.com/apple/foundationdb/bindings/go/src/fdb/subspace"
"bytes"
)

View File

@ -39,7 +39,7 @@ A basic interaction with the FoundationDB API is demonstrated below:
package main
import (
"github.com/apple/foundationdb/bindings/go/fdb"
"github.com/apple/foundationdb/bindings/go/src/fdb"
"log"
"fmt"
)

View File

@ -23,7 +23,7 @@
package fdb
/*
#define FDB_API_VERSION 200
#define FDB_API_VERSION 500
#include <foundationdb/fdb_c.h>
*/
import "C"

View File

@ -23,7 +23,7 @@
package fdb_test
import (
"fdb"
"github.com/apple/foundationdb/bindings/go/src/fdb"
"fmt"
"testing"
)

View File

@ -33,8 +33,8 @@
package subspace
import (
"fdb"
"fdb/tuple"
"github.com/apple/foundationdb/bindings/go/src/fdb"
"github.com/apple/foundationdb/bindings/go/src/fdb/tuple"
"bytes"
"errors"
)

View File

@ -38,7 +38,7 @@ import (
"fmt"
"encoding/binary"
"bytes"
"fdb"
"github.com/apple/foundationdb/bindings/go/src/fdb"
)
// A TupleElement is one of the types that may be encoded in FoundationDB

View File

@ -21,10 +21,10 @@
package main
import (
"github.com/FoundationDB/fdb-go/fdb"
"github.com/FoundationDB/fdb-go/fdb/directory"
"github.com/FoundationDB/fdb-go/fdb/subspace"
"github.com/FoundationDB/fdb-go/fdb/tuple"
"github.com/apple/foundationdb/bindings/go/src/fdb"
"github.com/apple/foundationdb/bindings/go/src/fdb/directory"
"github.com/apple/foundationdb/bindings/go/src/fdb/subspace"
"github.com/apple/foundationdb/bindings/go/src/fdb/tuple"
"fmt"
)
@ -76,7 +76,7 @@ func read_blob(t fdb.ReadTransactor, blob_subspace subspace.Subspace) ([]byte, e
}
func main() {
fdb.MustAPIVersion(300)
fdb.MustAPIVersion(500)
db := fdb.MustOpenDefault()

View File

@ -21,44 +21,44 @@
package main
import (
"fmt"
"fmt"
"io/ioutil"
"math/rand"
"encoding/json"
"github.com/FoundationDB/fdb-go/fdb"
"github.com/FoundationDB/fdb-go/fdb/directory"
"github.com/FoundationDB/fdb-go/fdb/subspace"
"github.com/FoundationDB/fdb-go/fdb/tuple"
"github.com/apple/foundationdb/bindings/go/src/fdb"
"github.com/apple/foundationdb/bindings/go/src/fdb/directory"
"github.com/apple/foundationdb/bindings/go/src/fdb/subspace"
"github.com/apple/foundationdb/bindings/go/src/fdb/tuple"
)
func clear_subspace(trtr fdb.Transactor, sub subspace.Subspace) error {
_, err := trtr.Transact(func(tr fdb.Transaction) (interface{}, error) {
tr.ClearRange(sub)
return nil, nil
})
return err
_, err := trtr.Transact(func(tr fdb.Transaction) (interface{}, error) {
tr.ClearRange(sub)
return nil, nil
})
return err
}
func print_subspace(trtr fdb.Transactor, sub subspace.Subspace) {
trtr.Transact(func(tr fdb.Transaction) (interface{}, error) {
k := tr.GetRange(sub, fdb.RangeOptions{0, -1, false}).Iterator()
trtr.Transact(func(tr fdb.Transaction) (interface{}, error) {
k := tr.GetRange(sub, fdb.RangeOptions{0, -1, false}).Iterator()
for k.Advance() {
fmt.Println(_unpack(k.MustGet().Value))
}
return nil, nil
})
for k.Advance() {
fmt.Println(_unpack(k.MustGet().Value))
}
return nil, nil
})
}
func _pack(t interface{}) []byte {
return tuple.Tuple{t}.Pack()
return tuple.Tuple{t}.Pack()
}
func _unpack(t []byte) tuple.Tuple {
i, e := tuple.Unpack(t)
if e != nil {return nil}
return i
i, e := tuple.Unpack(t)
if e != nil {return nil}
return i
}
const EmptyObject int = -1
@ -67,16 +67,16 @@ const EmptyList int = -2
func ToTuples(item interface{}) []tuple.Tuple {
switch i := item.(type) {
case []interface{}:
if len(i) == 0 {return []tuple.Tuple{tuple.Tuple{EmptyList}}}
if len(i) == 0 {return []tuple.Tuple{tuple.Tuple{EmptyList}}}
tuples := make([]tuple.Tuple, 0)
for i, v := range i {
for _, t := range ToTuples(v) {
tuples = append(tuples, append(tuple.Tuple{i}, t...))
}
}
return tuples
return tuples
case map[string]interface{}:
if len(i) == 0 {return []tuple.Tuple{tuple.Tuple{EmptyObject}}}
if len(i) == 0 {return []tuple.Tuple{tuple.Tuple{EmptyObject}}}
tuples := make([]tuple.Tuple, 0)
for k, v := range i {
for _, t := range ToTuples(v) {
@ -91,44 +91,44 @@ func ToTuples(item interface{}) []tuple.Tuple {
}
func FromTuples(tuples []tuple.Tuple) interface{} {
//fmt.Println(tuples)
if len(tuples) == 0 {return nil}
first := tuples[0]
if len(first) == 1 {return first[0]}
if first[0] == EmptyObject {return make(map[string]interface{}, 0)}
if first[0] == EmptyList {return make([]interface{}, 0)}
//fmt.Println(tuples)
if len(tuples) == 0 {return nil}
first := tuples[0]
if len(first) == 1 {return first[0]}
if first[0] == EmptyObject {return make(map[string]interface{}, 0)}
if first[0] == EmptyList {return make([]interface{}, 0)}
group := make(map[string][]tuple.Tuple)
group := make(map[string][]tuple.Tuple)
for _, t := range tuples {
k := string(_pack(t[0]))
_, ok := group[k]
if !ok {group[k] = make([]tuple.Tuple, 0)}
group[k] = append(group[k], t[0:len(t)])
}
for _, t := range tuples {
k := string(_pack(t[0]))
_, ok := group[k]
if !ok {group[k] = make([]tuple.Tuple, 0)}
group[k] = append(group[k], t[0:len(t)])
}
switch first[0].(type) {
case int64:
res := make([]interface{}, 0)
for _, g := range group {
subtup := make([]tuple.Tuple, 0)
for _, t := range g {
subtup = append(subtup, t[1:len(t)])
}
res = append(res, FromTuples(subtup))
}
return res
default:
res := make(map[string]interface{})
for _, g := range group {
subtup := make([]tuple.Tuple, 0)
for _, t := range g {
subtup = append(subtup, t[1:len(t)])
}
res[g[0][0].(string)] = FromTuples(subtup)
}
return res
}
switch first[0].(type) {
case int64:
res := make([]interface{}, 0)
for _, g := range group {
subtup := make([]tuple.Tuple, 0)
for _, t := range g {
subtup = append(subtup, t[1:len(t)])
}
res = append(res, FromTuples(subtup))
}
return res
default:
res := make(map[string]interface{})
for _, g := range group {
subtup := make([]tuple.Tuple, 0)
for _, t := range g {
subtup = append(subtup, t[1:len(t)])
}
res[g[0][0].(string)] = FromTuples(subtup)
}
return res
}
}
type Doc struct {
@ -138,16 +138,16 @@ type Doc struct {
func (doc Doc) InsertDoc(trtr fdb.Transactor, docdata []byte) int {
var data interface{}
json.Unmarshal(docdata, &data)
docid := 0
docid := 0
switch d := data.(type) {
case map[string]interface{}:
temp, ok := d["doc_id"]
if !ok {
docid = doc._GetNewID(trtr)
d["doc_id"] = docid
} else {
docid = temp.(int)
}
docid = doc._GetNewID(trtr)
d["doc_id"] = docid
} else {
docid = temp.(int)
}
tuples := ToTuples(d)
trtr.Transact(func(tr fdb.Transaction) (interface{}, error) {
for _, t := range tuples {
@ -156,7 +156,7 @@ func (doc Doc) InsertDoc(trtr fdb.Transactor, docdata []byte) int {
return nil, nil
})
}
return docid
return docid
}
func (doc Doc) _GetNewID(trtr fdb.Transactor) int {
@ -178,49 +178,40 @@ func (doc Doc) _GetNewID(trtr fdb.Transactor) int {
}
func (doc Doc) GetDoc(trtr fdb.Transactor, doc_id int) interface{} {
tuples := make([]tuple.Tuple, 0)
trtr.ReadTransact(func(tr fdb.ReadTransaction) (interface{}, error) {
kr, err := fdb.PrefixRange(doc.DocSS.Pack(tuple.Tuple{doc_id}))
if err != nil {panic(err)}
tuples := make([]tuple.Tuple, 0)
trtr.ReadTransact(func(tr fdb.ReadTransaction) (interface{}, error) {
kr, err := fdb.PrefixRange(doc.DocSS.Pack(tuple.Tuple{doc_id}))
if err != nil {panic(err)}
items := tr.GetRange(kr, fdb.RangeOptions{}).Iterator()
items := tr.GetRange(kr, fdb.RangeOptions{}).Iterator()
for items.Advance() {
v := items.MustGet()
tup, err := doc.DocSS.Unpack(v.Key)
if err != nil {panic(err)}
tuples = append(tuples, append(tup[1:len(tup)], _unpack(v.Value)))
}
return nil, nil
})
for items.Advance() {
v := items.MustGet()
tup, err := doc.DocSS.Unpack(v.Key)
if err != nil {panic(err)}
tuples = append(tuples, append(tup[1:len(tup)], _unpack(v.Value)))
}
return nil, nil
})
return FromTuples(tuples)
return FromTuples(tuples)
}
func main() {
fdb.MustAPIVersion(300)
fdb.MustAPIVersion(500)
db := fdb.MustOpenDefault()
DocDemoDir, err := directory.CreateOrOpen(db, []string{"docdemo"}, nil)
if err != nil {panic(err)}
clear_subspace(db, DocDemoDir)
clear_subspace(db, DocDemoDir)
mydoc := Doc{DocDemoDir}
docdata, err := ioutil.ReadFile("./doctestjson.json")
id := mydoc.InsertDoc(db, docdata)
fmt.Println(mydoc.GetDoc(db, id), id)
fmt.Println(mydoc.GetDoc(db, id), id)
}

View File

@ -21,10 +21,10 @@
package main
import (
"github.com/FoundationDB/fdb-go/fdb"
"github.com/FoundationDB/fdb-go/fdb/directory"
"github.com/FoundationDB/fdb-go/fdb/subspace"
"github.com/FoundationDB/fdb-go/fdb/tuple"
"github.com/apple/foundationdb/bindings/go/src/fdb"
"github.com/apple/foundationdb/bindings/go/src/fdb/directory"
"github.com/apple/foundationdb/bindings/go/src/fdb/subspace"
"github.com/apple/foundationdb/bindings/go/src/fdb/tuple"
"log"
"fmt"
)
@ -116,7 +116,7 @@ func (graph *Graph) get_in_neighbors(trtr fdb.Transactor, node int) ([]int, erro
}
func main() {
fdb.MustAPIVersion(300)
fdb.MustAPIVersion(500)
db := fdb.MustOpenDefault()

View File

@ -21,20 +21,20 @@
package main
import (
"log"
"fmt"
"github.com/FoundationDB/fdb-go/fdb"
"github.com/FoundationDB/fdb-go/fdb/directory"
"github.com/FoundationDB/fdb-go/fdb/subspace"
"github.com/FoundationDB/fdb-go/fdb/tuple"
"log"
"fmt"
"github.com/apple/foundationdb/bindings/go/src/fdb"
"github.com/apple/foundationdb/bindings/go/src/fdb/directory"
"github.com/apple/foundationdb/bindings/go/src/fdb/subspace"
"github.com/apple/foundationdb/bindings/go/src/fdb/tuple"
)
func clear_subspace(trtr fdb.Transactor, sub subspace.Subspace) error {
_, err := trtr.Transact(func(tr fdb.Transaction) (interface{}, error) {
tr.ClearRange(sub)
return nil, nil
})
return err
_, err := trtr.Transact(func(tr fdb.Transaction) (interface{}, error) {
tr.ClearRange(sub)
return nil, nil
})
return err
}
func print_subspace(trtr fdb.Transactor, sub subspace.Subspace) {
@ -49,13 +49,13 @@ func print_subspace(trtr fdb.Transactor, sub subspace.Subspace) {
}
func _pack(t interface{}) []byte {
return tuple.Tuple{t}.Pack()
return tuple.Tuple{t}.Pack()
}
func _unpack(t []byte) tuple.Tuple {
i, e := tuple.Unpack(t)
if e != nil {return nil}
return i
i, e := tuple.Unpack(t)
if e != nil {return nil}
return i
}
type Workspace struct {
@ -87,7 +87,7 @@ func (wrkspc Workspace) Session(foo func(directory.DirectorySubspace)) (err erro
}
func main() {
fdb.MustAPIVersion(300)
fdb.MustAPIVersion(500)
db := fdb.MustOpenDefault()

View File

@ -24,10 +24,10 @@ import (
"fmt"
//"log"
//"time"
"github.com/FoundationDB/fdb-go/fdb"
"github.com/FoundationDB/fdb-go/fdb/directory"
"github.com/FoundationDB/fdb-go/fdb/subspace"
"github.com/FoundationDB/fdb-go/fdb/tuple"
"github.com/apple/foundationdb/bindings/go/src/fdb"
"github.com/apple/foundationdb/bindings/go/src/fdb/directory"
"github.com/apple/foundationdb/bindings/go/src/fdb/subspace"
"github.com/apple/foundationdb/bindings/go/src/fdb/tuple"
)
func clear_subspace(db fdb.Transactor, ss subspace.Subspace) {
@ -70,21 +70,21 @@ func (multi MultiMap) MultiSubtract(trtr fdb.Transactor, index, value interface{
}
func (multi MultiMap) MultiGet(tr fdb.ReadTransactor, index int) (ret []interface{}, e error) {
_, e = tr.ReadTransact(func(tr fdb.ReadTransaction) (interface{}, error) {
pr, err := fdb.PrefixRange(multi.MapSS.Pack(tuple.Tuple{index}))
if err != nil {return nil, err}
kvs := tr.GetRange(pr, fdb.RangeOptions{0, -1, false}).GetSliceOrPanic()
ret := make([]interface{}, len(kvs))
i := 0
for _, kv := range kvs {
temp, err := multi.MapSS.Unpack(kv.Key)
if err != nil {return nil, err}
ret[i] = temp[1]
i++
}
return nil, nil
})
return
_, e = tr.ReadTransact(func(tr fdb.ReadTransaction) (interface{}, error) {
pr, err := fdb.PrefixRange(multi.MapSS.Pack(tuple.Tuple{index}))
if err != nil {return nil, err}
kvs := tr.GetRange(pr, fdb.RangeOptions{0, -1, false}).GetSliceOrPanic()
ret := make([]interface{}, len(kvs))
i := 0
for _, kv := range kvs {
temp, err := multi.MapSS.Unpack(kv.Key)
if err != nil {return nil, err}
ret[i] = temp[1]
i++
}
return nil, nil
})
return
}
func (multi MultiMap) MultiGetCounts(trtr fdb.Transactor, index interface{}) (map[interface{}]int, error) {
@ -124,7 +124,7 @@ func (multi MultiMap) MultiIsElement(trtr fdb.Transactor, index, value interface
func main() {
fdb.MustAPIVersion(300)
fdb.MustAPIVersion(500)
db := fdb.MustOpenDefault()
@ -144,8 +144,3 @@ func main() {
fmt.Println(m.MultiIsElement(db, 1, 2))
fmt.Println(m.MultiGetCounts(db, 1))
}

View File

@ -21,31 +21,31 @@
package main
import (
"log"
"fmt"
"log"
"fmt"
"math/rand"
"github.com/FoundationDB/fdb-go/fdb"
"github.com/FoundationDB/fdb-go/fdb/directory"
"github.com/FoundationDB/fdb-go/fdb/subspace"
"github.com/FoundationDB/fdb-go/fdb/tuple"
"github.com/apple/foundationdb/bindings/go/src/fdb"
"github.com/apple/foundationdb/bindings/go/src/fdb/directory"
"github.com/apple/foundationdb/bindings/go/src/fdb/subspace"
"github.com/apple/foundationdb/bindings/go/src/fdb/tuple"
)
func clear_subspace(trtr fdb.Transactor, sub subspace.Subspace) error {
_, err := trtr.Transact(func(tr fdb.Transaction) (interface{}, error) {
tr.ClearRange(sub)
return nil, nil
})
return err
_, err := trtr.Transact(func(tr fdb.Transaction) (interface{}, error) {
tr.ClearRange(sub)
return nil, nil
})
return err
}
func _pack(t interface{}) []byte {
return tuple.Tuple{t}.Pack()
return tuple.Tuple{t}.Pack()
}
func _unpack(t []byte) tuple.Tuple {
i, e := tuple.Unpack(t)
if e != nil {return nil}
return i
i, e := tuple.Unpack(t)
if e != nil {return nil}
return i
}
type Priority struct {
@ -100,7 +100,7 @@ func (prty Priority) Peek(trtr fdb.Transactor, max bool) interface{} {
func main() {
fdb.MustAPIVersion(300)
fdb.MustAPIVersion(500)
db := fdb.MustOpenDefault()
@ -131,13 +131,3 @@ func main() {
fmt.Println(p.Pop(db, false))
fmt.Println(p.Pop(db, false))
}

View File

@ -21,10 +21,10 @@
package main
import (
"github.com/FoundationDB/fdb-go/fdb"
"github.com/FoundationDB/fdb-go/fdb/directory"
"github.com/FoundationDB/fdb-go/fdb/subspace"
"github.com/FoundationDB/fdb-go/fdb/tuple"
"github.com/apple/foundationdb/bindings/go/src/fdb"
"github.com/apple/foundationdb/bindings/go/src/fdb/directory"
"github.com/apple/foundationdb/bindings/go/src/fdb/subspace"
"github.com/apple/foundationdb/bindings/go/src/fdb/tuple"
"log"
"fmt"
)
@ -101,7 +101,7 @@ func (q *Queue) FirstItem(trtr fdb.Transactor) (interface{}, error) {
func main() {
fmt.Println("Queue Example Program")
fdb.MustAPIVersion(300)
fdb.MustAPIVersion(500)
db := fdb.MustOpenDefault()

View File

@ -23,18 +23,18 @@ package main
import (
"log"
"fmt"
"github.com/FoundationDB/fdb-go/fdb"
"github.com/FoundationDB/fdb-go/fdb/directory"
"github.com/FoundationDB/fdb-go/fdb/subspace"
"github.com/FoundationDB/fdb-go/fdb/tuple"
"github.com/apple/foundationdb/bindings/go/src/fdb"
"github.com/apple/foundationdb/bindings/go/src/fdb/directory"
"github.com/apple/foundationdb/bindings/go/src/fdb/subspace"
"github.com/apple/foundationdb/bindings/go/src/fdb/tuple"
)
func clear_subspace(trtr fdb.Transactor, sub subspace.Subspace) error {
_, err := trtr.Transact(func(tr fdb.Transaction) (interface{}, error) {
tr.ClearRange(sub)
return nil, nil
})
return err
_, err := trtr.Transact(func(tr fdb.Transaction) (interface{}, error) {
tr.ClearRange(sub)
return nil, nil
})
return err
}
func _pack(t interface{}) []byte {
@ -53,7 +53,7 @@ type Table struct {
func (tbl *Table) NewTable(ss subspace.Subspace) {
tbl.row = ss.Sub("row")
tbl.col = ss.Sub("col")
tbl.col = ss.Sub("col")
}
func (tbl Table) TableSetCell(trtr fdb.Transactor, row, column int, value interface{}) {
@ -128,9 +128,9 @@ func (tbl Table) TableGetCol(tr fdb.ReadTransactor, col int) ([]interface{}, err
}
func main() {
fdb.MustAPIVersion(300)
fdb.MustAPIVersion(500)
db := fdb.MustOpenDefault()
db := fdb.MustOpenDefault()
TableDemoDir, err := directory.CreateOrOpen(db, []string{"Graph"}, nil)
if err != nil {log.Fatal(err)}
@ -150,9 +150,3 @@ func main() {
g.TableSetRow(db, 1, "Hello", "World", "Again!", 1)
fmt.Println(g.TableGetRow(db, 1))
}