diff --git a/.gitignore b/.gitignore index 8c613ec..17c43e6 100644 --- a/.gitignore +++ b/.gitignore @@ -2,8 +2,4 @@ main *.test *.peg.go -cayley cayley.cfg -leveldb/ -snappy/ -pkg/ diff --git a/Makefile b/Makefile deleted file mode 100644 index 3a28444..0000000 --- a/Makefile +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright 2014 The Cayley Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -default: build - -build: - ./make.sh build - -deps: - ./make.sh deps - -test: - ls ./src | grep -v "\." | sed 's/\///g' | xargs go test -cover - -convey: - ./bin/goconvey --depth=2 - - diff --git a/README.md b/README.md index d2b2163..b656bee 100644 --- a/README.md +++ b/README.md @@ -52,10 +52,7 @@ Make sure you have the right packages installed. Mostly, this is just Go as a de Now you can clone the repository and build the project. ```bash -git clone git@github.com:google/cayley.git -cd cayley -make deps -make +go get github.com/google/cayley/cmd/cayley ``` And the `cayley` binary will be built and ready. diff --git a/activate.sh b/activate.sh deleted file mode 100644 index 6d8cabd..0000000 --- a/activate.sh +++ /dev/null @@ -1,9 +0,0 @@ -# Absolute path this script is in. /home/user/bin -cd "`dirname '${BASH_SOURCE:-$0}'`" -SCRIPTPATH="`pwd`" -echo $dir -cd - > /dev/null - -export GOPATH=$SCRIPTPATH -#export GOOS="linux" -#export GOARCH="amd64" diff --git a/appengine/cayley-appengine.go b/appengine/appengine.go similarity index 78% rename from appengine/cayley-appengine.go rename to appengine/appengine.go index 77a0e23..c15a2bc 100644 --- a/appengine/cayley-appengine.go +++ b/appengine/appengine.go @@ -15,22 +15,24 @@ package cayleyappengine import ( - "cayley_config" - "cayley_http" - "github.com/barakmich/glog" - "graph" - "graph_memstore" - "nquads" "os" + + "github.com/barakmich/glog" + + "github.com/google/cayley/config" + "github.com/google/cayley/graph" + "github.com/google/cayley/graph/memstore" + "github.com/google/cayley/http" + "github.com/google/cayley/nquads" ) func init() { glog.SetToStderr(true) - config := cayley_config.ParseConfigFromFile("cayley_appengine.cfg") - ts := graph_memstore.NewMemTripleStore() - glog.Errorln(config) - LoadTriplesFromFileInto(ts, config.DatabasePath, config.LoadSize) - cayley_http.SetupRoutes(ts, config) + cfg := config.ParseConfigFromFile("cayley_appengine.cfg") + ts := memstore.NewMemTripleStore() + glog.Errorln(cfg) + LoadTriplesFromFileInto(ts, cfg.DatabasePath, cfg.LoadSize) + http.SetupRoutes(ts, cfg) } func ReadTriplesFromFile(c chan *graph.Triple, tripleFile string) { diff --git a/src/cayley/main.go b/cayley.go similarity index 83% rename from src/cayley/main.go rename to cayley.go index c2354d9..06af4f2 100644 --- a/src/cayley/main.go +++ b/cayley.go @@ -15,15 +15,17 @@ package main import ( - cayley "cayley_cmd" - cfg "cayley_config" - cayley_http "cayley_http" "flag" "fmt" - "github.com/barakmich/glog" - "graph" "os" "runtime" + + "github.com/barakmich/glog" + + "github.com/google/cayley/config" + "github.com/google/cayley/db" + "github.com/google/cayley/graph" + "github.com/google/cayley/http" ) var tripleFile = flag.String("triples", "", "Triple File to load before going to REPL.") @@ -58,7 +60,7 @@ func main() { os.Args = newargs flag.Parse() var ts graph.TripleStore - config := cfg.ParseConfigFromFlagsAndFile(*configFile) + cfg := config.ParseConfigFromFlagsAndFile(*configFile) if os.Getenv("GOMAXPROCS") == "" { runtime.GOMAXPROCS(runtime.NumCPU()) glog.Infoln("Setting GOMAXPROCS to", runtime.NumCPU()) @@ -67,18 +69,18 @@ func main() { } switch cmd { case "init": - cayley.CayleyInit(config, *tripleFile) + db.CayleyInit(cfg, *tripleFile) case "load": - ts = cayley.OpenTSFromConfig(config) - cayley.CayleyLoad(ts, config, *tripleFile, false) + ts = db.OpenTSFromConfig(cfg) + db.CayleyLoad(ts, cfg, *tripleFile, false) ts.Close() case "repl": - ts = cayley.OpenTSFromConfig(config) - cayley.CayleyRepl(ts, *queryLanguage, config) + ts = db.OpenTSFromConfig(cfg) + db.CayleyRepl(ts, *queryLanguage, cfg) ts.Close() case "http": - ts = cayley.OpenTSFromConfig(config) - cayley_http.CayleyHTTP(ts, config) + ts = db.OpenTSFromConfig(cfg) + http.CayleyHTTP(ts, cfg) ts.Close() default: fmt.Println("No command", cmd) diff --git a/src/cayley_config/cayley-config.go b/config/config.go similarity index 99% rename from src/cayley_config/cayley-config.go rename to config/config.go index 8e19d6c..6432dd6 100644 --- a/src/cayley_config/cayley-config.go +++ b/config/config.go @@ -12,13 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -package cayley_config +package config import ( "encoding/json" "flag" - "github.com/barakmich/glog" "os" + + "github.com/barakmich/glog" ) type CayleyConfig struct { diff --git a/src/cayley_cmd/cayley-init.go b/db/init.go similarity index 64% rename from src/cayley_cmd/cayley-init.go rename to db/init.go index 74226c3..d3ab8a8 100644 --- a/src/cayley_cmd/cayley-init.go +++ b/db/init.go @@ -12,28 +12,28 @@ // See the License for the specific language governing permissions and // limitations under the License. -package cayley +package db import ( - cfg "cayley_config" - "graph_leveldb" - "graph_mongo" + "github.com/google/cayley/config" + "github.com/google/cayley/graph/leveldb" + "github.com/google/cayley/graph/mongo" ) -func CayleyInit(config *cfg.CayleyConfig, triplePath string) bool { +func CayleyInit(cfg *config.CayleyConfig, triplePath string) bool { created := false - dbpath := config.DatabasePath - switch config.DatabaseType { + dbpath := cfg.DatabasePath + switch cfg.DatabaseType { case "mongo", "mongodb": - created = graph_mongo.CreateNewMongoGraph(dbpath, config.DatabaseOptions) + created = mongo.CreateNewMongoGraph(dbpath, cfg.DatabaseOptions) case "leveldb": - created = graph_leveldb.CreateNewLevelDB(dbpath) + created = leveldb.CreateNewLevelDB(dbpath) case "mem": return true } if created && triplePath != "" { - ts := OpenTSFromConfig(config) - CayleyLoad(ts, config, triplePath, true) + ts := OpenTSFromConfig(cfg) + CayleyLoad(ts, cfg, triplePath, true) ts.Close() } return created diff --git a/src/cayley_cmd/cayley-load.go b/db/load.go similarity index 73% rename from src/cayley_cmd/cayley-load.go rename to db/load.go index 19b242c..ff232a0 100644 --- a/src/cayley_cmd/cayley-load.go +++ b/db/load.go @@ -12,36 +12,38 @@ // See the License for the specific language governing permissions and // limitations under the License. -package cayley +package db import ( - cfg "cayley_config" - "github.com/barakmich/glog" - "graph" - "graph_mongo" - "nquads" "os" + + "github.com/barakmich/glog" + + "github.com/google/cayley/config" + "github.com/google/cayley/graph" + "github.com/google/cayley/graph/mongo" + "github.com/google/cayley/nquads" ) -func CayleyLoad(ts graph.TripleStore, config *cfg.CayleyConfig, triplePath string, firstTime bool) { - switch config.DatabaseType { +func CayleyLoad(ts graph.TripleStore, cfg *config.CayleyConfig, triplePath string, firstTime bool) { + switch cfg.DatabaseType { case "mongo", "mongodb": if firstTime { - loadMongo(ts.(*graph_mongo.MongoTripleStore), triplePath) + loadMongo(ts.(*mongo.MongoTripleStore), triplePath) } else { - LoadTriplesFromFileInto(ts, triplePath, config.LoadSize) + LoadTriplesFromFileInto(ts, triplePath, cfg.LoadSize) } case "rethink", "rethinkdb": - LoadTriplesFromFileInto(ts, triplePath, config.LoadSize) + LoadTriplesFromFileInto(ts, triplePath, cfg.LoadSize) case "leveldb": - LoadTriplesFromFileInto(ts, triplePath, config.LoadSize) + LoadTriplesFromFileInto(ts, triplePath, cfg.LoadSize) case "mem": - LoadTriplesFromFileInto(ts, triplePath, config.LoadSize) + LoadTriplesFromFileInto(ts, triplePath, cfg.LoadSize) } } -func loadMongo(ts *graph_mongo.MongoTripleStore, path string) { +func loadMongo(ts *mongo.MongoTripleStore, path string) { tChan := make(chan *graph.Triple) go ReadTriplesFromFile(tChan, path) ts.BulkLoad(tChan) diff --git a/src/cayley_cmd/cayley-open.go b/db/open.go similarity index 52% rename from src/cayley_cmd/cayley-open.go rename to db/open.go index c262571..7095739 100644 --- a/src/cayley_cmd/cayley-open.go +++ b/db/open.go @@ -12,29 +12,29 @@ // See the License for the specific language governing permissions and // limitations under the License. -package cayley +package db import ( - "graph" - - cfg "cayley_config" "github.com/barakmich/glog" - "graph_leveldb" - "graph_memstore" - "graph_mongo" + + "github.com/google/cayley/config" + "github.com/google/cayley/graph" + "github.com/google/cayley/graph/leveldb" + "github.com/google/cayley/graph/memstore" + "github.com/google/cayley/graph/mongo" ) -func OpenTSFromConfig(config *cfg.CayleyConfig) graph.TripleStore { - glog.Infof("Opening database \"%s\" at %s", config.DatabaseType, config.DatabasePath) - switch config.DatabaseType { +func OpenTSFromConfig(cfg *config.CayleyConfig) graph.TripleStore { + glog.Infof("Opening database \"%s\" at %s", cfg.DatabaseType, cfg.DatabasePath) + switch cfg.DatabaseType { case "mongo", "mongodb": - return graph_mongo.NewMongoTripleStore(config.DatabasePath, config.DatabaseOptions) + return mongo.NewMongoTripleStore(cfg.DatabasePath, cfg.DatabaseOptions) case "leveldb": - return graph_leveldb.NewDefaultLevelDBTripleStore(config.DatabasePath, config.DatabaseOptions) + return leveldb.NewDefaultLevelDBTripleStore(cfg.DatabasePath, cfg.DatabaseOptions) case "mem": - ts := graph_memstore.NewMemTripleStore() - CayleyLoad(ts, config, config.DatabasePath, true) + ts := memstore.NewMemTripleStore() + CayleyLoad(ts, cfg, cfg.DatabasePath, true) return ts } - panic("Unsupported database backend " + config.DatabaseType) + panic("Unsupported database backend " + cfg.DatabaseType) } diff --git a/src/cayley_cmd/cayley-repl.go b/db/repl.go similarity index 87% rename from src/cayley_cmd/cayley-repl.go rename to db/repl.go index 9c4757a..405d61e 100644 --- a/src/cayley_cmd/cayley-repl.go +++ b/db/repl.go @@ -12,21 +12,22 @@ // See the License for the specific language governing permissions and // limitations under the License. -package cayley +package db import ( "bufio" - cfg "cayley_config" "fmt" - "graph" - sexp "graph_sexp" - "gremlin" "io" - "mql" - "nquads" "os" "strings" "time" + + "github.com/google/cayley/config" + "github.com/google/cayley/graph" + "github.com/google/cayley/graph/sexp" + "github.com/google/cayley/nquads" + "github.com/google/cayley/query/gremlin" + "github.com/google/cayley/query/mql" ) func trace(s string) (string, time.Time) { @@ -59,7 +60,7 @@ func RunQuery(query string, ses graph.Session) { } } -func CayleyRepl(ts graph.TripleStore, queryLanguage string, config *cfg.CayleyConfig) { +func CayleyRepl(ts graph.TripleStore, queryLanguage string, cfg *config.CayleyConfig) { var ses graph.Session switch queryLanguage { case "sexp": @@ -69,7 +70,7 @@ func CayleyRepl(ts graph.TripleStore, queryLanguage string, config *cfg.CayleyCo case "gremlin": fallthrough default: - ses = gremlin.NewGremlinSession(ts, config.GremlinTimeout, true) + ses = gremlin.NewGremlinSession(ts, cfg.GremlinTimeout, true) } inputBf := bufio.NewReader(os.Stdin) line := "" diff --git a/src/graph/all-iterator.go b/graph/all_iterator.go similarity index 100% rename from src/graph/all-iterator.go rename to graph/all_iterator.go diff --git a/src/graph/and-iterator.go b/graph/and_iterator.go similarity index 100% rename from src/graph/and-iterator.go rename to graph/and_iterator.go diff --git a/src/graph/and-iterator-optimize.go b/graph/and_iterator_optimize.go similarity index 100% rename from src/graph/and-iterator-optimize.go rename to graph/and_iterator_optimize.go diff --git a/src/graph/and-iterator-optimize_test.go b/graph/and_iterator_optimize_test.go similarity index 100% rename from src/graph/and-iterator-optimize_test.go rename to graph/and_iterator_optimize_test.go diff --git a/src/graph/and-iterator_test.go b/graph/and_iterator_test.go similarity index 100% rename from src/graph/and-iterator_test.go rename to graph/and_iterator_test.go diff --git a/src/graph/fixed-iterator.go b/graph/fixed_iterator.go similarity index 100% rename from src/graph/fixed-iterator.go rename to graph/fixed_iterator.go diff --git a/src/graph/hasa-iterator.go b/graph/hasa_iterator.go similarity index 100% rename from src/graph/hasa-iterator.go rename to graph/hasa_iterator.go diff --git a/src/graph/iterator.go b/graph/iterator.go similarity index 100% rename from src/graph/iterator.go rename to graph/iterator.go diff --git a/src/graph_leveldb/leveldb-all-iterator.go b/graph/leveldb/leveldb_all_iterator.go similarity index 98% rename from src/graph_leveldb/leveldb-all-iterator.go rename to graph/leveldb/leveldb_all_iterator.go index 78f9bdc..4fad9d8 100644 --- a/src/graph_leveldb/leveldb-all-iterator.go +++ b/graph/leveldb/leveldb_all_iterator.go @@ -12,15 +12,17 @@ // See the License for the specific language governing permissions and // limitations under the License. -package graph_leveldb +package leveldb import ( "bytes" "fmt" + "strings" + leveldb_it "github.com/syndtr/goleveldb/leveldb/iterator" leveldb_opt "github.com/syndtr/goleveldb/leveldb/opt" - "graph" - "strings" + + "github.com/google/cayley/graph" ) type LevelDBAllIterator struct { diff --git a/src/graph_leveldb/leveldb-iterator.go b/graph/leveldb/leveldb_iterator.go similarity index 98% rename from src/graph_leveldb/leveldb-iterator.go rename to graph/leveldb/leveldb_iterator.go index 0e611f1..b657073 100644 --- a/src/graph_leveldb/leveldb-iterator.go +++ b/graph/leveldb/leveldb_iterator.go @@ -12,16 +12,18 @@ // See the License for the specific language governing permissions and // limitations under the License. -package graph_leveldb +package leveldb import ( "bytes" _ "encoding/binary" "fmt" + "strings" + leveldb_it "github.com/syndtr/goleveldb/leveldb/iterator" leveldb_opt "github.com/syndtr/goleveldb/leveldb/opt" - "graph" - "strings" + + "github.com/google/cayley/graph" ) type LevelDBIterator struct { diff --git a/src/graph_leveldb/leveldb_test.go b/graph/leveldb/leveldb_test.go similarity index 99% rename from src/graph_leveldb/leveldb_test.go rename to graph/leveldb/leveldb_test.go index 4b17827..0412c94 100644 --- a/src/graph_leveldb/leveldb_test.go +++ b/graph/leveldb/leveldb_test.go @@ -12,15 +12,17 @@ // See the License for the specific language governing permissions and // limitations under the License. -package graph_leveldb +package leveldb import ( - . "github.com/smartystreets/goconvey/convey" - "graph" "io/ioutil" "os" "sort" "testing" + + . "github.com/smartystreets/goconvey/convey" + + "github.com/google/cayley/graph" ) func makeTripleSet() []*graph.Triple { @@ -136,7 +138,7 @@ func TestLoadDatabase(t *testing.T) { } -func TestAllIterator(t *testing.T) { +func TestIterator(t *testing.T) { var ts *LevelDBTripleStore Convey("Given a prepared database", t, func() { diff --git a/src/graph_leveldb/leveldb-triplestore.go b/graph/leveldb/leveldb_triplestore.go similarity index 99% rename from src/graph_leveldb/leveldb-triplestore.go rename to graph/leveldb/leveldb_triplestore.go index e459bfd..edc2e10 100644 --- a/src/graph_leveldb/leveldb-triplestore.go +++ b/graph/leveldb/leveldb_triplestore.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package graph_leveldb +package leveldb import ( "bytes" @@ -20,13 +20,15 @@ import ( "encoding/binary" "encoding/json" "fmt" + "hash" + "github.com/barakmich/glog" "github.com/syndtr/goleveldb/leveldb" leveldb_cache "github.com/syndtr/goleveldb/leveldb/cache" leveldb_opt "github.com/syndtr/goleveldb/leveldb/opt" leveldb_util "github.com/syndtr/goleveldb/leveldb/util" - "graph" - "hash" + + "github.com/google/cayley/graph" ) const DefaultCacheSize = 2 diff --git a/src/graph_leveldb/leveldb-triplestore-iterator-optimize.go b/graph/leveldb/leveldb_triplestore_iterator_optimize.go similarity index 96% rename from src/graph_leveldb/leveldb-triplestore-iterator-optimize.go rename to graph/leveldb/leveldb_triplestore_iterator_optimize.go index 99ae611..243afba 100644 --- a/src/graph_leveldb/leveldb-triplestore-iterator-optimize.go +++ b/graph/leveldb/leveldb_triplestore_iterator_optimize.go @@ -12,10 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -package graph_leveldb +package leveldb import ( - "graph" + "github.com/google/cayley/graph" ) func (ts *LevelDBTripleStore) OptimizeIterator(it graph.Iterator) (graph.Iterator, bool) { diff --git a/src/graph/linksto-iterator.go b/graph/linksto_iterator.go similarity index 100% rename from src/graph/linksto-iterator.go rename to graph/linksto_iterator.go diff --git a/src/graph/linksto-iterator_test.go b/graph/linksto_iterator_test.go similarity index 100% rename from src/graph/linksto-iterator_test.go rename to graph/linksto_iterator_test.go diff --git a/src/graph_memstore/llrb-iterator.go b/graph/memstore/llrb_iterator.go similarity index 98% rename from src/graph_memstore/llrb-iterator.go rename to graph/memstore/llrb_iterator.go index fed4272..692a3c6 100644 --- a/src/graph_memstore/llrb-iterator.go +++ b/graph/memstore/llrb_iterator.go @@ -12,14 +12,16 @@ // See the License for the specific language governing permissions and // limitations under the License. -package graph_memstore +package memstore import ( "fmt" - "github.com/petar/GoLLRB/llrb" - "graph" "math" "strings" + + "github.com/petar/GoLLRB/llrb" + + "github.com/google/cayley/graph" ) type LlrbIterator struct { diff --git a/src/graph_memstore/memstore-all-iterator.go b/graph/memstore/memstore_all_iterator.go similarity index 95% rename from src/graph_memstore/memstore-all-iterator.go rename to graph/memstore/memstore_all_iterator.go index 21245a0..99cf734 100644 --- a/src/graph_memstore/memstore-all-iterator.go +++ b/graph/memstore/memstore_all_iterator.go @@ -12,10 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -package graph_memstore +package memstore import ( - "graph" + "github.com/google/cayley/graph" ) type MemstoreAllIterator struct { diff --git a/src/graph_memstore/memtriplestore.go b/graph/memstore/memtriplestore.go similarity index 99% rename from src/graph_memstore/memtriplestore.go rename to graph/memstore/memtriplestore.go index 83f5c17..7c7882e 100644 --- a/src/graph_memstore/memtriplestore.go +++ b/graph/memstore/memtriplestore.go @@ -12,13 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -package graph_memstore +package memstore import ( "fmt" + "github.com/barakmich/glog" + "github.com/google/cayley/graph" + "github.com/petar/GoLLRB/llrb" - "graph" ) type TripleDirectionIndex struct { diff --git a/src/graph_memstore/memtriplestore-iterator-optimize.go b/graph/memstore/memtriplestore_iterator_optimize.go similarity index 96% rename from src/graph_memstore/memtriplestore-iterator-optimize.go rename to graph/memstore/memtriplestore_iterator_optimize.go index 2fd913b..7c895fc 100644 --- a/src/graph_memstore/memtriplestore-iterator-optimize.go +++ b/graph/memstore/memtriplestore_iterator_optimize.go @@ -12,10 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -package graph_memstore +package memstore import ( - "graph" + "github.com/google/cayley/graph" ) func (ts *MemTripleStore) OptimizeIterator(it graph.Iterator) (graph.Iterator, bool) { diff --git a/src/graph_memstore/memtriplestore_test.go b/graph/memstore/memtriplestore_test.go similarity index 98% rename from src/graph_memstore/memtriplestore_test.go rename to graph/memstore/memtriplestore_test.go index 0321028..71d7016 100644 --- a/src/graph_memstore/memtriplestore_test.go +++ b/graph/memstore/memtriplestore_test.go @@ -12,13 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -package graph_memstore +package memstore import ( - . "github.com/smartystreets/goconvey/convey" - "graph" "sort" "testing" + + . "github.com/smartystreets/goconvey/convey" + + "github.com/google/cayley/graph" ) func TestMemstore(t *testing.T) { diff --git a/src/graph_memstore/testing_memstore.go b/graph/memstore/testing_memstore.go similarity index 96% rename from src/graph_memstore/testing_memstore.go rename to graph/memstore/testing_memstore.go index d32d838..b33c95f 100644 --- a/src/graph_memstore/testing_memstore.go +++ b/graph/memstore/testing_memstore.go @@ -12,9 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -package graph_memstore +package memstore -import "graph" +import "github.com/google/cayley/graph" // +---+ +---+ // | A |------- ->| F |<-- diff --git a/src/graph/mock_ts.go b/graph/mock_ts.go similarity index 100% rename from src/graph/mock_ts.go rename to graph/mock_ts.go diff --git a/src/graph_mongo/lru.go b/graph/mongo/lru.go similarity index 98% rename from src/graph_mongo/lru.go rename to graph/mongo/lru.go index c856a5a..90220e4 100644 --- a/src/graph_mongo/lru.go +++ b/graph/mongo/lru.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package graph_mongo +package mongo import ( "container/list" diff --git a/src/graph_mongo/mongo-iterator.go b/graph/mongo/mongo_iterator.go similarity index 98% rename from src/graph_mongo/mongo-iterator.go rename to graph/mongo/mongo_iterator.go index 6d7f84a..addcfb0 100644 --- a/src/graph_mongo/mongo-iterator.go +++ b/graph/mongo/mongo_iterator.go @@ -12,15 +12,17 @@ // See the License for the specific language governing permissions and // limitations under the License. -package graph_mongo +package mongo import ( "fmt" + "strings" + "github.com/barakmich/glog" - "graph" "labix.org/v2/mgo" "labix.org/v2/mgo/bson" - "strings" + + "github.com/google/cayley/graph" ) type MongoIterator struct { diff --git a/src/graph_mongo/mongo-triplestore.go b/graph/mongo/mongo_triplestore.go similarity index 99% rename from src/graph_mongo/mongo-triplestore.go rename to graph/mongo/mongo_triplestore.go index fa4ea25..917ab4d 100644 --- a/src/graph_mongo/mongo-triplestore.go +++ b/graph/mongo/mongo_triplestore.go @@ -12,17 +12,19 @@ // See the License for the specific language governing permissions and // limitations under the License. -package graph_mongo +package mongo import ( "crypto/sha1" "encoding/hex" - "github.com/barakmich/glog" - "graph" "hash" + "log" + "labix.org/v2/mgo" "labix.org/v2/mgo/bson" - "log" + + "github.com/barakmich/glog" + "github.com/google/cayley/graph" ) const DefaultDBName = "cayley" diff --git a/src/graph_mongo/mongo-triplestore-iterator-optimize.go b/graph/mongo/mongo_triplestore_iterator_optimize.go similarity index 96% rename from src/graph_mongo/mongo-triplestore-iterator-optimize.go rename to graph/mongo/mongo_triplestore_iterator_optimize.go index ea35602..d10bc22 100644 --- a/src/graph_mongo/mongo-triplestore-iterator-optimize.go +++ b/graph/mongo/mongo_triplestore_iterator_optimize.go @@ -12,10 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -package graph_mongo +package mongo import ( - "graph" + "github.com/google/cayley/graph" ) func (ts *MongoTripleStore) OptimizeIterator(it graph.Iterator) (graph.Iterator, bool) { diff --git a/src/graph/optional-iterator.go b/graph/optional_iterator.go similarity index 100% rename from src/graph/optional-iterator.go rename to graph/optional_iterator.go diff --git a/src/graph/or-iterator.go b/graph/or_iterator.go similarity index 100% rename from src/graph/or-iterator.go rename to graph/or_iterator.go diff --git a/src/graph/or-iterator_test.go b/graph/or_iterator_test.go similarity index 100% rename from src/graph/or-iterator_test.go rename to graph/or_iterator_test.go diff --git a/src/graph/query-shape.go b/graph/query_shape.go similarity index 100% rename from src/graph/query-shape.go rename to graph/query_shape.go diff --git a/src/graph/query-shape_test.go b/graph/query_shape_test.go similarity index 100% rename from src/graph/query-shape_test.go rename to graph/query_shape_test.go diff --git a/src/graph/result-tree-evaluator.go b/graph/result_tree_evaluator.go similarity index 100% rename from src/graph/result-tree-evaluator.go rename to graph/result_tree_evaluator.go diff --git a/src/graph/result-tree-evaluator_test.go b/graph/result_tree_evaluator_test.go similarity index 100% rename from src/graph/result-tree-evaluator_test.go rename to graph/result_tree_evaluator_test.go diff --git a/src/graph/session.go b/graph/session.go similarity index 100% rename from src/graph/session.go rename to graph/session.go diff --git a/src/graph_sexp/parser.go b/graph/sexp/parser.go similarity index 99% rename from src/graph_sexp/parser.go rename to graph/sexp/parser.go index 529b854..2efcf49 100644 --- a/src/graph_sexp/parser.go +++ b/graph/sexp/parser.go @@ -12,11 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -package graph_sexp +package sexp import ( "github.com/badgerodon/peg" - "graph" + + "github.com/google/cayley/graph" ) func BuildIteratorTreeForQuery(ts graph.TripleStore, query string) graph.Iterator { diff --git a/src/graph_sexp/parser_test.go b/graph/sexp/parser_test.go similarity index 93% rename from src/graph_sexp/parser_test.go rename to graph/sexp/parser_test.go index 90233c5..f72239c 100644 --- a/src/graph_sexp/parser_test.go +++ b/graph/sexp/parser_test.go @@ -12,13 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -package graph_sexp +package sexp import ( - . "github.com/smartystreets/goconvey/convey" - "graph" - "graph_memstore" "testing" + + . "github.com/smartystreets/goconvey/convey" + + "github.com/google/cayley/graph" + "github.com/google/cayley/graph/memstore" ) func TestBadParse(t *testing.T) { @@ -30,7 +32,7 @@ func TestBadParse(t *testing.T) { func TestParseSexpWithMemstore(t *testing.T) { Convey("With a Memstore", t, func() { - ts := graph_memstore.NewMemTripleStore() + ts := memstore.NewMemTripleStore() Convey("It should parse an empty query", func() { it := BuildIteratorTreeForQuery(ts, "()") @@ -62,7 +64,7 @@ func TestParseSexpWithMemstore(t *testing.T) { } func TestTreeConstraintParse(t *testing.T) { - ts := graph_memstore.NewMemTripleStore() + ts := memstore.NewMemTripleStore() ts.AddTriple(graph.MakeTriple("i", "like", "food", "")) ts.AddTriple(graph.MakeTriple("food", "is", "good", "")) query := "(\"i\"\n" + @@ -82,7 +84,7 @@ func TestTreeConstraintParse(t *testing.T) { } func TestTreeConstraintTagParse(t *testing.T) { - ts := graph_memstore.NewMemTripleStore() + ts := memstore.NewMemTripleStore() ts.AddTriple(graph.MakeTriple("i", "like", "food", "")) ts.AddTriple(graph.MakeTriple("food", "is", "good", "")) query := "(\"i\"\n" + @@ -102,7 +104,7 @@ func TestTreeConstraintTagParse(t *testing.T) { } func TestMultipleConstraintParse(t *testing.T) { - ts := graph_memstore.NewMemTripleStore() + ts := memstore.NewMemTripleStore() ts.AddTriple(graph.MakeTriple("i", "like", "food", "")) ts.AddTriple(graph.MakeTriple("i", "like", "beer", "")) ts.AddTriple(graph.MakeTriple("you", "like", "beer", "")) diff --git a/src/graph_sexp/sexp-session.go b/graph/sexp/sexp_session.go similarity index 98% rename from src/graph_sexp/sexp-session.go rename to graph/sexp/sexp_session.go index 161e5ae..7065e02 100644 --- a/src/graph_sexp/sexp-session.go +++ b/graph/sexp/sexp_session.go @@ -12,15 +12,16 @@ // See the License for the specific language governing permissions and // limitations under the License. -package graph_sexp +package sexp // Defines a running session of the sexp query language. import ( "errors" "fmt" - "graph" "sort" + + "github.com/google/cayley/graph" ) type SexpSession struct { diff --git a/src/graph/triple.go b/graph/triple.go similarity index 100% rename from src/graph/triple.go rename to graph/triple.go diff --git a/src/graph/triplestore.go b/graph/triplestore.go similarity index 100% rename from src/graph/triplestore.go rename to graph/triplestore.go diff --git a/src/graph/value-comparison-iterator.go b/graph/value_comparison_iterator.go similarity index 100% rename from src/graph/value-comparison-iterator.go rename to graph/value_comparison_iterator.go diff --git a/src/graph/value-comparison-iterator_test.go b/graph/value_comparison_iterator_test.go similarity index 100% rename from src/graph/value-comparison-iterator_test.go rename to graph/value_comparison_iterator_test.go diff --git a/src/cayley_http/cayley-http.go b/http/cayley_http.go similarity index 85% rename from src/cayley_http/cayley-http.go rename to http/cayley_http.go index 35acab1..f4ad6fa 100644 --- a/src/cayley_http/cayley-http.go +++ b/http/cayley_http.go @@ -12,17 +12,19 @@ // See the License for the specific language governing permissions and // limitations under the License. -package cayley_http +package http import ( - cfg "cayley_config" "fmt" - "github.com/barakmich/glog" - "github.com/julienschmidt/httprouter" - "graph" "html/template" "net/http" "time" + + "github.com/barakmich/glog" + "github.com/julienschmidt/httprouter" + + "github.com/google/cayley/config" + "github.com/google/cayley/graph" ) type ResponseHandler func(http.ResponseWriter, *http.Request, httprouter.Params) int @@ -69,7 +71,7 @@ func (h *TemplateRequestHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques } type Api struct { - config *cfg.CayleyConfig + config *config.CayleyConfig ts graph.TripleStore } @@ -82,13 +84,13 @@ func (api *Api) ApiV1(r *httprouter.Router) { r.POST("/api/v1/delete", LogRequest(api.ServeV1Delete)) } -func SetupRoutes(ts graph.TripleStore, config *cfg.CayleyConfig) { +func SetupRoutes(ts graph.TripleStore, cfg *config.CayleyConfig) { r := httprouter.New() var templates = template.Must(template.ParseGlob("templates/*.tmpl")) templates.ParseGlob("templates/*.html") root := &TemplateRequestHandler{templates: templates} docs := &DocRequestHandler{} - api := &Api{config: config, ts: ts} + api := &Api{config: cfg, ts: ts} api.ApiV1(r) //m.Use(martini.Static("static", martini.StaticOptions{Prefix: "/static", SkipLogging: true})) @@ -100,11 +102,11 @@ func SetupRoutes(ts graph.TripleStore, config *cfg.CayleyConfig) { http.Handle("/", r) } -func CayleyHTTP(ts graph.TripleStore, config *cfg.CayleyConfig) { - SetupRoutes(ts, config) - glog.Infof("Cayley now listening on %s:%s\n", config.ListenHost, config.ListenPort) - fmt.Printf("Cayley now listening on %s:%s\n", config.ListenHost, config.ListenPort) - err := http.ListenAndServe(fmt.Sprintf("%s:%s", config.ListenHost, config.ListenPort), nil) +func CayleyHTTP(ts graph.TripleStore, cfg *config.CayleyConfig) { + SetupRoutes(ts, cfg) + glog.Infof("Cayley now listening on %s:%s\n", cfg.ListenHost, cfg.ListenPort) + fmt.Printf("Cayley now listening on %s:%s\n", cfg.ListenHost, cfg.ListenPort) + err := http.ListenAndServe(fmt.Sprintf("%s:%s", cfg.ListenHost, cfg.ListenPort), nil) if err != nil { glog.Fatal("ListenAndServe: ", err) } diff --git a/src/cayley_http/cayley-http-docs.go b/http/cayley_http_docs.go similarity index 99% rename from src/cayley_http/cayley-http-docs.go rename to http/cayley_http_docs.go index d90e8d9..45e747d 100644 --- a/src/cayley_http/cayley-http-docs.go +++ b/http/cayley_http_docs.go @@ -12,15 +12,16 @@ // See the License for the specific language governing permissions and // limitations under the License. -package cayley_http +package http import ( "fmt" - "github.com/julienschmidt/httprouter" - "github.com/russross/blackfriday" "io/ioutil" "net/http" "os" + + "github.com/julienschmidt/httprouter" + "github.com/russross/blackfriday" ) type DocRequestHandler struct { diff --git a/src/cayley_http/cayley-http-query.go b/http/cayley_http_query.go similarity index 96% rename from src/cayley_http/cayley-http-query.go rename to http/cayley_http_query.go index c3a91e6..8170e13 100644 --- a/src/cayley_http/cayley-http-query.go +++ b/http/cayley_http_query.go @@ -12,17 +12,19 @@ // See the License for the specific language governing permissions and // limitations under the License. -package cayley_http +package http import ( "encoding/json" "fmt" - "github.com/julienschmidt/httprouter" - "graph" - "gremlin" "io/ioutil" - "mql" "net/http" + + "github.com/julienschmidt/httprouter" + + "github.com/google/cayley/graph" + "github.com/google/cayley/query/gremlin" + "github.com/google/cayley/query/mql" ) type SuccessQueryWrapper struct { diff --git a/src/cayley_http/cayley-http_test.go b/http/cayley_http_test.go similarity index 98% rename from src/cayley_http/cayley-http_test.go rename to http/cayley_http_test.go index 941b6da..d59749f 100644 --- a/src/cayley_http/cayley-http_test.go +++ b/http/cayley_http_test.go @@ -12,11 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -package cayley_http +package http import ( - . "github.com/smartystreets/goconvey/convey" "testing" + . "github.com/smartystreets/goconvey/convey" ) func TestParseJSONOkay(t *testing.T) { diff --git a/src/cayley_http/cayley-http-write.go b/http/cayley_http_write.go similarity index 97% rename from src/cayley_http/cayley-http-write.go rename to http/cayley_http_write.go index a6fdcb6..20fb60d 100644 --- a/src/cayley_http/cayley-http-write.go +++ b/http/cayley_http_write.go @@ -12,19 +12,21 @@ // See the License for the specific language governing permissions and // limitations under the License. -package cayley_http +package http import ( "encoding/json" "errors" "fmt" - "github.com/barakmich/glog" - "github.com/julienschmidt/httprouter" - "graph" "io/ioutil" "net/http" - "nquads" "strconv" + + "github.com/barakmich/glog" + "github.com/julienschmidt/httprouter" + + "github.com/google/cayley/graph" + "github.com/google/cayley/nquads" ) func ParseJsonToTripleList(jsonBody []byte) ([]*graph.Triple, error) { diff --git a/make.sh b/make.sh deleted file mode 100755 index 395a277..0000000 --- a/make.sh +++ /dev/null @@ -1,65 +0,0 @@ -#!/usr/bin/env bash - -# Copyright 2014 The Cayley Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -set -e - -cd "`dirname '$0'`" -SCRIPTPATH="`pwd`" -cd - > /dev/null - -export GOPATH=$SCRIPTPATH -export GOBIN= - -function deps { -echo "Fetching dependencies to $SCRIPTPATH..." -printf " (00/15)\r" - go get -u -t github.com/smartystreets/goconvey -printf "# (01/15)\r" - go get -u github.com/badgerodon/peg -printf "## (02/15)\r" - go get -u github.com/barakmich/glog -printf "#### (03/15)\r" - go get -u github.com/julienschmidt/httprouter -printf "##### (04/15)\r" - go get -u github.com/petar/GoLLRB/llrb -printf "###### (05/15)\r" - go get -u github.com/robertkrimen/otto -printf "####### (06/15)\r" - go get -u github.com/stretchrcom/testify -printf "######## (07/15)\r" - go get -u github.com/syndtr/goleveldb/leveldb -printf "######### (08/15)\r" - go get -u github.com/syndtr/goleveldb/leveldb/cache -printf "########## (09/15)\r" - go get -u github.com/syndtr/goleveldb/leveldb/iterator -printf "########### (10/15)\r" - go get -u github.com/syndtr/goleveldb/leveldb/opt -printf "############ (11/15)\r" - go get -u github.com/syndtr/goleveldb/leveldb/util -printf "############# (12/15)\r" - go get -u labix.org/v2/mgo -printf "############## (13/15)\r" - go get -u labix.org/v2/mgo/bson -printf "############### (14/15)\r" - go get -u github.com/russross/blackfriday -printf "################ (15/15)\r" -printf "\n" -} - -function build { - go build cayley -} - -$1 diff --git a/src/nquads/nquads.go b/nquads/nquads.go similarity index 99% rename from src/nquads/nquads.go rename to nquads/nquads.go index 63ec89c..f4032b3 100644 --- a/src/nquads/nquads.go +++ b/nquads/nquads.go @@ -16,10 +16,12 @@ package nquads import ( "bufio" - "github.com/barakmich/glog" - "graph" "io" "strings" + + "github.com/barakmich/glog" + + "github.com/google/cayley/graph" ) func isWhitespace(s uint8) bool { diff --git a/src/nquads/nquads_test.go b/nquads/nquads_test.go similarity index 99% rename from src/nquads/nquads_test.go rename to nquads/nquads_test.go index 47e02a5..f5b61ee 100644 --- a/src/nquads/nquads_test.go +++ b/nquads/nquads_test.go @@ -15,9 +15,11 @@ package nquads import ( - . "github.com/smartystreets/goconvey/convey" - "graph" "testing" + + . "github.com/smartystreets/goconvey/convey" + + "github.com/google/cayley/graph" ) func TestParsingNTriples(t *testing.T) { diff --git a/src/gremlin/gremlin-build-iterator.go b/query/gremlin/gremlin_build_iterator.go similarity index 99% rename from src/gremlin/gremlin-build-iterator.go rename to query/gremlin/gremlin_build_iterator.go index 823c568..b6e9a45 100644 --- a/src/gremlin/gremlin-build-iterator.go +++ b/query/gremlin/gremlin_build_iterator.go @@ -15,10 +15,12 @@ package gremlin import ( + "strconv" + "github.com/barakmich/glog" "github.com/robertkrimen/otto" - "graph" - "strconv" + + "github.com/google/cayley/graph" ) func getStrings(obj *otto.Object, field string) []string { diff --git a/src/gremlin/gremlin-env.go b/query/gremlin/gremlin_env.go similarity index 100% rename from src/gremlin/gremlin-env.go rename to query/gremlin/gremlin_env.go diff --git a/src/gremlin/gremlin-finals.go b/query/gremlin/gremlin_finals.go similarity index 99% rename from src/gremlin/gremlin-finals.go rename to query/gremlin/gremlin_finals.go index 08bdd6d..f8c978d 100644 --- a/src/gremlin/gremlin-finals.go +++ b/query/gremlin/gremlin_finals.go @@ -17,7 +17,8 @@ package gremlin import ( "github.com/barakmich/glog" "github.com/robertkrimen/otto" - "graph" + + "github.com/google/cayley/graph" ) const GremlinTopResultTag = "id" diff --git a/src/gremlin/gremlin-functional_test.go b/query/gremlin/gremlin_functional_test.go similarity index 98% rename from src/gremlin/gremlin-functional_test.go rename to query/gremlin/gremlin_functional_test.go index f516965..f6c65fb 100644 --- a/src/gremlin/gremlin-functional_test.go +++ b/query/gremlin/gremlin_functional_test.go @@ -15,10 +15,12 @@ package gremlin import ( - . "github.com/smartystreets/goconvey/convey" - "graph_memstore" "sort" "testing" + + . "github.com/smartystreets/goconvey/convey" + + "github.com/google/cayley/graph/memstore" ) // +---+ +---+ @@ -34,8 +36,8 @@ import ( // func buildTripleStore() *GremlinSession { - ts := graph_memstore.MakeTestingMemstore() - return NewGremlinSession(ts, -1) + ts := memstore.MakeTestingMemstore() + return NewGremlinSession(ts, -1, false) } func shouldBeUnordered(actual interface{}, expected ...interface{}) string { diff --git a/src/gremlin/gremlin-session.go b/query/gremlin/gremlin_session.go similarity index 99% rename from src/gremlin/gremlin-session.go rename to query/gremlin/gremlin_session.go index 25b3fbb..a0b0483 100644 --- a/src/gremlin/gremlin-session.go +++ b/query/gremlin/gremlin_session.go @@ -17,10 +17,12 @@ package gremlin import ( "errors" "fmt" - "github.com/robertkrimen/otto" - "graph" "sort" "time" + + "github.com/robertkrimen/otto" + + "github.com/google/cayley/graph" ) type GremlinSession struct { diff --git a/src/gremlin/gremlin_test.nt b/query/gremlin/gremlin_test.nt similarity index 100% rename from src/gremlin/gremlin_test.nt rename to query/gremlin/gremlin_test.nt diff --git a/src/gremlin/gremlin-traversals.go b/query/gremlin/gremlin_traversals.go similarity index 100% rename from src/gremlin/gremlin-traversals.go rename to query/gremlin/gremlin_traversals.go diff --git a/src/mql/mql-build-iterator.go b/query/mql/mql_build_iterator.go similarity index 99% rename from src/mql/mql-build-iterator.go rename to query/mql/mql_build_iterator.go index 8f7d8d1..6273696 100644 --- a/src/mql/mql-build-iterator.go +++ b/query/mql/mql_build_iterator.go @@ -17,10 +17,11 @@ package mql import ( "errors" "fmt" - "graph" "log" "math" "strings" + + "github.com/google/cayley/graph" ) func (m *MqlQuery) buildFixed(s string) graph.Iterator { diff --git a/src/mql/mql-fill.go b/query/mql/mql_fill.go similarity index 98% rename from src/mql/mql-fill.go rename to query/mql/mql_fill.go index 72fb2b4..26de32a 100644 --- a/src/mql/mql-fill.go +++ b/query/mql/mql_fill.go @@ -15,8 +15,9 @@ package mql import ( - "graph" "sort" + + "github.com/google/cayley/graph" ) func (m *MqlQuery) treeifyResult(tags map[string]graph.TSVal) map[MqlResultPath]string { diff --git a/src/mql/mql-functional_test.go b/query/mql/mql_functional_test.go similarity index 98% rename from src/mql/mql-functional_test.go rename to query/mql/mql_functional_test.go index 396e75c..97c2eac 100644 --- a/src/mql/mql-functional_test.go +++ b/query/mql/mql_functional_test.go @@ -16,9 +16,11 @@ package mql import ( "encoding/json" - . "github.com/smartystreets/goconvey/convey" - "graph_memstore" "testing" + + . "github.com/smartystreets/goconvey/convey" + + "github.com/google/cayley/graph/memstore" ) // +---+ +---+ @@ -34,7 +36,7 @@ import ( // func buildTripleStore() *MqlSession { - ts := graph_memstore.MakeTestingMemstore() + ts := memstore.MakeTestingMemstore() return NewMqlSession(ts) } diff --git a/src/mql/mql-query.go b/query/mql/mql_query.go similarity index 98% rename from src/mql/mql-query.go rename to query/mql/mql_query.go index a56ad5f..66d8179 100644 --- a/src/mql/mql-query.go +++ b/query/mql/mql_query.go @@ -16,8 +16,9 @@ package mql import ( "fmt" - "graph" "strings" + + "github.com/google/cayley/graph" ) type MqlPath string diff --git a/src/mql/mql-session.go b/query/mql/mql_session.go similarity index 98% rename from src/mql/mql-session.go rename to query/mql/mql_session.go index e08e75e..96d88bf 100644 --- a/src/mql/mql-session.go +++ b/query/mql/mql_session.go @@ -17,9 +17,11 @@ package mql import ( "encoding/json" "fmt" - "github.com/barakmich/glog" - "graph" "sort" + + "github.com/barakmich/glog" + + "github.com/google/cayley/graph" ) type MqlSession struct {