Don't rename imports unless necessary
This commit is contained in:
parent
0c9de61413
commit
d37c6caa8e
7 changed files with 37 additions and 36 deletions
|
|
@ -19,7 +19,7 @@ import (
|
||||||
|
|
||||||
"github.com/barakmich/glog"
|
"github.com/barakmich/glog"
|
||||||
|
|
||||||
cfg "github.com/google/cayley/config"
|
"github.com/google/cayley/config"
|
||||||
"github.com/google/cayley/graph"
|
"github.com/google/cayley/graph"
|
||||||
"github.com/google/cayley/graph/memstore"
|
"github.com/google/cayley/graph/memstore"
|
||||||
"github.com/google/cayley/http"
|
"github.com/google/cayley/http"
|
||||||
|
|
@ -28,11 +28,11 @@ import (
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
glog.SetToStderr(true)
|
glog.SetToStderr(true)
|
||||||
config := cfg.ParseConfigFromFile("cayley_appengine.cfg")
|
cfg := config.ParseConfigFromFile("cayley_appengine.cfg")
|
||||||
ts := memstore.NewMemTripleStore()
|
ts := memstore.NewMemTripleStore()
|
||||||
glog.Errorln(config)
|
glog.Errorln(cfg)
|
||||||
LoadTriplesFromFileInto(ts, config.DatabasePath, config.LoadSize)
|
LoadTriplesFromFileInto(ts, cfg.DatabasePath, cfg.LoadSize)
|
||||||
http.SetupRoutes(ts, config)
|
http.SetupRoutes(ts, cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReadTriplesFromFile(c chan *graph.Triple, tripleFile string) {
|
func ReadTriplesFromFile(c chan *graph.Triple, tripleFile string) {
|
||||||
|
|
|
||||||
|
|
@ -12,13 +12,14 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package cayley_config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
"github.com/barakmich/glog"
|
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/barakmich/glog"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CayleyConfig struct {
|
type CayleyConfig struct {
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ import (
|
||||||
"github.com/barakmich/glog"
|
"github.com/barakmich/glog"
|
||||||
"github.com/julienschmidt/httprouter"
|
"github.com/julienschmidt/httprouter"
|
||||||
|
|
||||||
cfg "github.com/google/cayley/config"
|
"github.com/google/cayley/config"
|
||||||
"github.com/google/cayley/graph"
|
"github.com/google/cayley/graph"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -71,7 +71,7 @@ func (h *TemplateRequestHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
|
||||||
}
|
}
|
||||||
|
|
||||||
type Api struct {
|
type Api struct {
|
||||||
config *cfg.CayleyConfig
|
config *config.CayleyConfig
|
||||||
ts graph.TripleStore
|
ts graph.TripleStore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -84,7 +84,7 @@ func (api *Api) ApiV1(r *httprouter.Router) {
|
||||||
r.POST("/api/v1/delete", LogRequest(api.ServeV1Delete))
|
r.POST("/api/v1/delete", LogRequest(api.ServeV1Delete))
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetupRoutes(ts graph.TripleStore, config *cfg.CayleyConfig) {
|
func SetupRoutes(ts graph.TripleStore, config *config.CayleyConfig) {
|
||||||
r := httprouter.New()
|
r := httprouter.New()
|
||||||
var templates = template.Must(template.ParseGlob("templates/*.tmpl"))
|
var templates = template.Must(template.ParseGlob("templates/*.tmpl"))
|
||||||
templates.ParseGlob("templates/*.html")
|
templates.ParseGlob("templates/*.html")
|
||||||
|
|
@ -102,7 +102,7 @@ func SetupRoutes(ts graph.TripleStore, config *cfg.CayleyConfig) {
|
||||||
http.Handle("/", r)
|
http.Handle("/", r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CayleyHTTP(ts graph.TripleStore, config *cfg.CayleyConfig) {
|
func CayleyHTTP(ts graph.TripleStore, config *config.CayleyConfig) {
|
||||||
SetupRoutes(ts, config)
|
SetupRoutes(ts, config)
|
||||||
glog.Infof("Cayley now listening on %s:%s\n", config.ListenHost, config.ListenPort)
|
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)
|
fmt.Printf("Cayley now listening on %s:%s\n", config.ListenHost, config.ListenPort)
|
||||||
|
|
|
||||||
14
init.go
14
init.go
|
|
@ -15,25 +15,25 @@
|
||||||
package cayley
|
package cayley
|
||||||
|
|
||||||
import (
|
import (
|
||||||
cfg "github.com/google/cayley/config"
|
"github.com/google/cayley/config"
|
||||||
"github.com/google/cayley/graph/leveldb"
|
"github.com/google/cayley/graph/leveldb"
|
||||||
"github.com/google/cayley/graph/mongo"
|
"github.com/google/cayley/graph/mongo"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CayleyInit(config *cfg.CayleyConfig, triplePath string) bool {
|
func CayleyInit(cfg *config.CayleyConfig, triplePath string) bool {
|
||||||
created := false
|
created := false
|
||||||
dbpath := config.DatabasePath
|
dbpath := cfg.DatabasePath
|
||||||
switch config.DatabaseType {
|
switch cfg.DatabaseType {
|
||||||
case "mongo", "mongodb":
|
case "mongo", "mongodb":
|
||||||
created = mongo.CreateNewMongoGraph(dbpath, config.DatabaseOptions)
|
created = mongo.CreateNewMongoGraph(dbpath, cfg.DatabaseOptions)
|
||||||
case "leveldb":
|
case "leveldb":
|
||||||
created = leveldb.CreateNewLevelDB(dbpath)
|
created = leveldb.CreateNewLevelDB(dbpath)
|
||||||
case "mem":
|
case "mem":
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if created && triplePath != "" {
|
if created && triplePath != "" {
|
||||||
ts := OpenTSFromConfig(config)
|
ts := OpenTSFromConfig(cfg)
|
||||||
CayleyLoad(ts, config, triplePath, true)
|
CayleyLoad(ts, cfg, triplePath, true)
|
||||||
ts.Close()
|
ts.Close()
|
||||||
}
|
}
|
||||||
return created
|
return created
|
||||||
|
|
|
||||||
14
load.go
14
load.go
|
|
@ -19,26 +19,26 @@ import (
|
||||||
|
|
||||||
"github.com/barakmich/glog"
|
"github.com/barakmich/glog"
|
||||||
|
|
||||||
cfg "github.com/google/cayley/config"
|
"github.com/google/cayley/config"
|
||||||
"github.com/google/cayley/graph"
|
"github.com/google/cayley/graph"
|
||||||
"github.com/google/cayley/graph/mongo"
|
"github.com/google/cayley/graph/mongo"
|
||||||
"github.com/google/cayley/nquads"
|
"github.com/google/cayley/nquads"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CayleyLoad(ts graph.TripleStore, config *cfg.CayleyConfig, triplePath string, firstTime bool) {
|
func CayleyLoad(ts graph.TripleStore, cfg *config.CayleyConfig, triplePath string, firstTime bool) {
|
||||||
switch config.DatabaseType {
|
switch cfg.DatabaseType {
|
||||||
case "mongo", "mongodb":
|
case "mongo", "mongodb":
|
||||||
if firstTime {
|
if firstTime {
|
||||||
loadMongo(ts.(*mongo.MongoTripleStore), triplePath)
|
loadMongo(ts.(*mongo.MongoTripleStore), triplePath)
|
||||||
} else {
|
} else {
|
||||||
LoadTriplesFromFileInto(ts, triplePath, config.LoadSize)
|
LoadTriplesFromFileInto(ts, triplePath, cfg.LoadSize)
|
||||||
}
|
}
|
||||||
case "rethink", "rethinkdb":
|
case "rethink", "rethinkdb":
|
||||||
LoadTriplesFromFileInto(ts, triplePath, config.LoadSize)
|
LoadTriplesFromFileInto(ts, triplePath, cfg.LoadSize)
|
||||||
case "leveldb":
|
case "leveldb":
|
||||||
LoadTriplesFromFileInto(ts, triplePath, config.LoadSize)
|
LoadTriplesFromFileInto(ts, triplePath, cfg.LoadSize)
|
||||||
case "mem":
|
case "mem":
|
||||||
LoadTriplesFromFileInto(ts, triplePath, config.LoadSize)
|
LoadTriplesFromFileInto(ts, triplePath, cfg.LoadSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
16
open.go
16
open.go
|
|
@ -17,24 +17,24 @@ package cayley
|
||||||
import (
|
import (
|
||||||
"github.com/barakmich/glog"
|
"github.com/barakmich/glog"
|
||||||
|
|
||||||
cfg "github.com/google/cayley/config"
|
"github.com/google/cayley/config"
|
||||||
"github.com/google/cayley/graph"
|
"github.com/google/cayley/graph"
|
||||||
"github.com/google/cayley/graph/leveldb"
|
"github.com/google/cayley/graph/leveldb"
|
||||||
"github.com/google/cayley/graph/memstore"
|
"github.com/google/cayley/graph/memstore"
|
||||||
"github.com/google/cayley/graph/mongo"
|
"github.com/google/cayley/graph/mongo"
|
||||||
)
|
)
|
||||||
|
|
||||||
func OpenTSFromConfig(config *cfg.CayleyConfig) graph.TripleStore {
|
func OpenTSFromConfig(cfg *config.CayleyConfig) graph.TripleStore {
|
||||||
glog.Infof("Opening database \"%s\" at %s", config.DatabaseType, config.DatabasePath)
|
glog.Infof("Opening database \"%s\" at %s", cfg.DatabaseType, cfg.DatabasePath)
|
||||||
switch config.DatabaseType {
|
switch cfg.DatabaseType {
|
||||||
case "mongo", "mongodb":
|
case "mongo", "mongodb":
|
||||||
return mongo.NewMongoTripleStore(config.DatabasePath, config.DatabaseOptions)
|
return mongo.NewMongoTripleStore(cfg.DatabasePath, cfg.DatabaseOptions)
|
||||||
case "leveldb":
|
case "leveldb":
|
||||||
return leveldb.NewDefaultLevelDBTripleStore(config.DatabasePath, config.DatabaseOptions)
|
return leveldb.NewDefaultLevelDBTripleStore(cfg.DatabasePath, cfg.DatabaseOptions)
|
||||||
case "mem":
|
case "mem":
|
||||||
ts := memstore.NewMemTripleStore()
|
ts := memstore.NewMemTripleStore()
|
||||||
CayleyLoad(ts, config, config.DatabasePath, true)
|
CayleyLoad(ts, cfg, cfg.DatabasePath, true)
|
||||||
return ts
|
return ts
|
||||||
}
|
}
|
||||||
panic("Unsupported database backend " + config.DatabaseType)
|
panic("Unsupported database backend " + cfg.DatabaseType)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
6
repl.go
6
repl.go
|
|
@ -22,7 +22,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
cfg "github.com/google/cayley/config"
|
"github.com/google/cayley/config"
|
||||||
"github.com/google/cayley/graph"
|
"github.com/google/cayley/graph"
|
||||||
"github.com/google/cayley/graph/sexp"
|
"github.com/google/cayley/graph/sexp"
|
||||||
"github.com/google/cayley/gremlin"
|
"github.com/google/cayley/gremlin"
|
||||||
|
|
@ -60,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
|
var ses graph.Session
|
||||||
switch queryLanguage {
|
switch queryLanguage {
|
||||||
case "sexp":
|
case "sexp":
|
||||||
|
|
@ -70,7 +70,7 @@ func CayleyRepl(ts graph.TripleStore, queryLanguage string, config *cfg.CayleyCo
|
||||||
case "gremlin":
|
case "gremlin":
|
||||||
fallthrough
|
fallthrough
|
||||||
default:
|
default:
|
||||||
ses = gremlin.NewGremlinSession(ts, config.GremlinTimeout, true)
|
ses = gremlin.NewGremlinSession(ts, cfg.GremlinTimeout, true)
|
||||||
}
|
}
|
||||||
inputBf := bufio.NewReader(os.Stdin)
|
inputBf := bufio.NewReader(os.Stdin)
|
||||||
line := ""
|
line := ""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue