Don't rename imports unless necessary

This commit is contained in:
kortschak 2014-06-26 09:20:22 +09:30
parent 0c9de61413
commit d37c6caa8e
7 changed files with 37 additions and 36 deletions

View file

@ -19,7 +19,7 @@ import (
"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/memstore"
"github.com/google/cayley/http"
@ -28,11 +28,11 @@ import (
func init() {
glog.SetToStderr(true)
config := cfg.ParseConfigFromFile("cayley_appengine.cfg")
cfg := config.ParseConfigFromFile("cayley_appengine.cfg")
ts := memstore.NewMemTripleStore()
glog.Errorln(config)
LoadTriplesFromFileInto(ts, config.DatabasePath, config.LoadSize)
http.SetupRoutes(ts, config)
glog.Errorln(cfg)
LoadTriplesFromFileInto(ts, cfg.DatabasePath, cfg.LoadSize)
http.SetupRoutes(ts, cfg)
}
func ReadTriplesFromFile(c chan *graph.Triple, tripleFile string) {

View file

@ -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 {

View file

@ -23,7 +23,7 @@ import (
"github.com/barakmich/glog"
"github.com/julienschmidt/httprouter"
cfg "github.com/google/cayley/config"
"github.com/google/cayley/config"
"github.com/google/cayley/graph"
)
@ -71,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
}
@ -84,7 +84,7 @@ 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, config *config.CayleyConfig) {
r := httprouter.New()
var templates = template.Must(template.ParseGlob("templates/*.tmpl"))
templates.ParseGlob("templates/*.html")
@ -102,7 +102,7 @@ func SetupRoutes(ts graph.TripleStore, config *cfg.CayleyConfig) {
http.Handle("/", r)
}
func CayleyHTTP(ts graph.TripleStore, config *cfg.CayleyConfig) {
func CayleyHTTP(ts graph.TripleStore, config *config.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)

14
init.go
View file

@ -15,25 +15,25 @@
package cayley
import (
cfg "github.com/google/cayley/config"
"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 = mongo.CreateNewMongoGraph(dbpath, config.DatabaseOptions)
created = mongo.CreateNewMongoGraph(dbpath, cfg.DatabaseOptions)
case "leveldb":
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

14
load.go
View file

@ -19,26 +19,26 @@ import (
"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/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.(*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)
}
}

16
open.go
View file

@ -17,24 +17,24 @@ package cayley
import (
"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/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 mongo.NewMongoTripleStore(config.DatabasePath, config.DatabaseOptions)
return mongo.NewMongoTripleStore(cfg.DatabasePath, cfg.DatabaseOptions)
case "leveldb":
return leveldb.NewDefaultLevelDBTripleStore(config.DatabasePath, config.DatabaseOptions)
return leveldb.NewDefaultLevelDBTripleStore(cfg.DatabasePath, cfg.DatabaseOptions)
case "mem":
ts := memstore.NewMemTripleStore()
CayleyLoad(ts, config, config.DatabasePath, true)
CayleyLoad(ts, cfg, cfg.DatabasePath, true)
return ts
}
panic("Unsupported database backend " + config.DatabaseType)
panic("Unsupported database backend " + cfg.DatabaseType)
}

View file

@ -22,7 +22,7 @@ import (
"strings"
"time"
cfg "github.com/google/cayley/config"
"github.com/google/cayley/config"
"github.com/google/cayley/graph"
"github.com/google/cayley/graph/sexp"
"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
switch queryLanguage {
case "sexp":
@ -70,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 := ""