Simplify names in cmd source

This commit is contained in:
kortschak 2014-06-28 12:38:51 +09:30
parent 47c9752e5e
commit c4a19a4e35
6 changed files with 17 additions and 17 deletions

View file

@ -69,18 +69,18 @@ func main() {
} }
switch cmd { switch cmd {
case "init": case "init":
db.CayleyInit(cfg, *tripleFile) db.Init(cfg, *tripleFile)
case "load": case "load":
ts = db.OpenTSFromConfig(cfg) ts = db.OpenTSFrom(cfg)
db.CayleyLoad(ts, cfg, *tripleFile, false) db.Load(ts, cfg, *tripleFile, false)
ts.Close() ts.Close()
case "repl": case "repl":
ts = db.OpenTSFromConfig(cfg) ts = db.OpenTSFrom(cfg)
db.CayleyRepl(ts, *queryLanguage, cfg) db.Repl(ts, *queryLanguage, cfg)
ts.Close() ts.Close()
case "http": case "http":
ts = db.OpenTSFromConfig(cfg) ts = db.OpenTSFrom(cfg)
http.CayleyHTTP(ts, cfg) http.Serve(ts, cfg)
ts.Close() ts.Close()
default: default:
fmt.Println("No command", cmd) fmt.Println("No command", cmd)

View file

@ -20,7 +20,7 @@ import (
"github.com/google/cayley/graph/mongo" "github.com/google/cayley/graph/mongo"
) )
func CayleyInit(cfg *config.CayleyConfig, triplePath string) bool { func Init(cfg *config.CayleyConfig, triplePath string) bool {
created := false created := false
dbpath := cfg.DatabasePath dbpath := cfg.DatabasePath
switch cfg.DatabaseType { switch cfg.DatabaseType {
@ -32,8 +32,8 @@ func CayleyInit(cfg *config.CayleyConfig, triplePath string) bool {
return true return true
} }
if created && triplePath != "" { if created && triplePath != "" {
ts := OpenTSFromConfig(cfg) ts := OpenTSFrom(cfg)
CayleyLoad(ts, cfg, triplePath, true) Load(ts, cfg, triplePath, true)
ts.Close() ts.Close()
} }
return created return created

View file

@ -25,7 +25,7 @@ import (
"github.com/google/cayley/nquads" "github.com/google/cayley/nquads"
) )
func CayleyLoad(ts graph.TripleStore, cfg *config.CayleyConfig, triplePath string, firstTime bool) { func Load(ts graph.TripleStore, cfg *config.CayleyConfig, triplePath string, firstTime bool) {
switch cfg.DatabaseType { switch cfg.DatabaseType {
case "mongo", "mongodb": case "mongo", "mongodb":
if firstTime { if firstTime {

View file

@ -24,7 +24,7 @@ import (
"github.com/google/cayley/graph/mongo" "github.com/google/cayley/graph/mongo"
) )
func OpenTSFromConfig(cfg *config.CayleyConfig) graph.TripleStore { func OpenTSFrom(cfg *config.CayleyConfig) graph.TripleStore {
glog.Infof("Opening database \"%s\" at %s", cfg.DatabaseType, cfg.DatabasePath) glog.Infof("Opening database \"%s\" at %s", cfg.DatabaseType, cfg.DatabasePath)
switch cfg.DatabaseType { switch cfg.DatabaseType {
case "mongo", "mongodb": case "mongo", "mongodb":
@ -33,7 +33,7 @@ func OpenTSFromConfig(cfg *config.CayleyConfig) graph.TripleStore {
return leveldb.NewDefaultLevelDBTripleStore(cfg.DatabasePath, cfg.DatabaseOptions) return leveldb.NewDefaultLevelDBTripleStore(cfg.DatabasePath, cfg.DatabaseOptions)
case "mem": case "mem":
ts := memstore.NewMemTripleStore() ts := memstore.NewMemTripleStore()
CayleyLoad(ts, cfg, cfg.DatabasePath, true) Load(ts, cfg, cfg.DatabasePath, true)
return ts return ts
} }
panic("Unsupported database backend " + cfg.DatabaseType) panic("Unsupported database backend " + cfg.DatabaseType)

View file

@ -40,7 +40,7 @@ func un(s string, startTime time.Time) {
fmt.Printf(s, float64(endTime.UnixNano()-startTime.UnixNano())/float64(1E6)) fmt.Printf(s, float64(endTime.UnixNano()-startTime.UnixNano())/float64(1E6))
} }
func RunQuery(query string, ses graph.Session) { func Run(query string, ses graph.Session) {
nResults := 0 nResults := 0
startTrace, startTime := trace("Elapsed time: %g ms\n\n") startTrace, startTime := trace("Elapsed time: %g ms\n\n")
defer func() { defer func() {
@ -60,7 +60,7 @@ func RunQuery(query string, ses graph.Session) {
} }
} }
func CayleyRepl(ts graph.TripleStore, queryLanguage string, cfg *config.CayleyConfig) { func Repl(ts graph.TripleStore, queryLanguage string, cfg *config.CayleyConfig) {
var ses graph.Session var ses graph.Session
switch queryLanguage { switch queryLanguage {
case "sexp": case "sexp":
@ -131,7 +131,7 @@ func CayleyRepl(ts graph.TripleStore, queryLanguage string, cfg *config.CayleyCo
result, err := ses.InputParses(line) result, err := ses.InputParses(line)
switch result { switch result {
case graph.Parsed: case graph.Parsed:
RunQuery(line, ses) Run(line, ses)
line = "" line = ""
case graph.ParseFail: case graph.ParseFail:
fmt.Println("Error: ", err) fmt.Println("Error: ", err)

View file

@ -141,7 +141,7 @@ func SetupRoutes(ts graph.TripleStore, cfg *config.CayleyConfig) {
http.Handle("/", r) http.Handle("/", r)
} }
func CayleyHTTP(ts graph.TripleStore, cfg *config.CayleyConfig) { func Serve(ts graph.TripleStore, cfg *config.CayleyConfig) {
SetupRoutes(ts, cfg) SetupRoutes(ts, cfg)
glog.Infof("Cayley now listening on %s:%s\n", cfg.ListenHost, cfg.ListenPort) 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) fmt.Printf("Cayley now listening on %s:%s\n", cfg.ListenHost, cfg.ListenPort)