Destutter cayley/config
This commit is contained in:
parent
c4a19a4e35
commit
388618bfa7
6 changed files with 11 additions and 11 deletions
|
|
@ -22,7 +22,7 @@ import (
|
||||||
"github.com/barakmich/glog"
|
"github.com/barakmich/glog"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CayleyConfig struct {
|
type Config struct {
|
||||||
DatabaseType string `json:"database"`
|
DatabaseType string `json:"database"`
|
||||||
DatabasePath string `json:"db_path"`
|
DatabasePath string `json:"db_path"`
|
||||||
DatabaseOptions map[string]interface{} `json:"db_options"`
|
DatabaseOptions map[string]interface{} `json:"db_options"`
|
||||||
|
|
@ -41,8 +41,8 @@ var port = flag.String("port", "64210", "Port to listen on.")
|
||||||
var readOnly = flag.Bool("read_only", false, "Disable writing via HTTP.")
|
var readOnly = flag.Bool("read_only", false, "Disable writing via HTTP.")
|
||||||
var gremlinTimeout = flag.Int("gremlin_timeout", 30, "Number of seconds until an individual query times out.")
|
var gremlinTimeout = flag.Int("gremlin_timeout", 30, "Number of seconds until an individual query times out.")
|
||||||
|
|
||||||
func ParseConfigFromFile(filename string) *CayleyConfig {
|
func ParseConfigFromFile(filename string) *Config {
|
||||||
config := &CayleyConfig{}
|
config := &Config{}
|
||||||
if filename == "" {
|
if filename == "" {
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
@ -61,7 +61,7 @@ func ParseConfigFromFile(filename string) *CayleyConfig {
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseConfigFromFlagsAndFile(fileFlag string) *CayleyConfig {
|
func ParseConfigFromFlagsAndFile(fileFlag string) *Config {
|
||||||
// Find the file...
|
// Find the file...
|
||||||
var trueFilename string
|
var trueFilename string
|
||||||
if fileFlag != "" {
|
if fileFlag != "" {
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ import (
|
||||||
"github.com/google/cayley/graph/mongo"
|
"github.com/google/cayley/graph/mongo"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Init(cfg *config.CayleyConfig, triplePath string) bool {
|
func Init(cfg *config.Config, triplePath string) bool {
|
||||||
created := false
|
created := false
|
||||||
dbpath := cfg.DatabasePath
|
dbpath := cfg.DatabasePath
|
||||||
switch cfg.DatabaseType {
|
switch cfg.DatabaseType {
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ import (
|
||||||
"github.com/google/cayley/nquads"
|
"github.com/google/cayley/nquads"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Load(ts graph.TripleStore, cfg *config.CayleyConfig, triplePath string, firstTime bool) {
|
func Load(ts graph.TripleStore, cfg *config.Config, triplePath string, firstTime bool) {
|
||||||
switch cfg.DatabaseType {
|
switch cfg.DatabaseType {
|
||||||
case "mongo", "mongodb":
|
case "mongo", "mongodb":
|
||||||
if firstTime {
|
if firstTime {
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ import (
|
||||||
"github.com/google/cayley/graph/mongo"
|
"github.com/google/cayley/graph/mongo"
|
||||||
)
|
)
|
||||||
|
|
||||||
func OpenTSFrom(cfg *config.CayleyConfig) graph.TripleStore {
|
func OpenTSFrom(cfg *config.Config) 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":
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ func Run(query string, ses graph.Session) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Repl(ts graph.TripleStore, queryLanguage string, cfg *config.CayleyConfig) {
|
func Repl(ts graph.TripleStore, queryLanguage string, cfg *config.Config) {
|
||||||
var ses graph.Session
|
var ses graph.Session
|
||||||
switch queryLanguage {
|
switch queryLanguage {
|
||||||
case "sexp":
|
case "sexp":
|
||||||
|
|
|
||||||
|
|
@ -106,7 +106,7 @@ func (h *TemplateRequestHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
|
||||||
}
|
}
|
||||||
|
|
||||||
type Api struct {
|
type Api struct {
|
||||||
config *config.CayleyConfig
|
config *config.Config
|
||||||
ts graph.TripleStore
|
ts graph.TripleStore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -119,7 +119,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, cfg *config.CayleyConfig) {
|
func SetupRoutes(ts graph.TripleStore, cfg *config.Config) {
|
||||||
r := httprouter.New()
|
r := httprouter.New()
|
||||||
assets := findAssetsPath()
|
assets := findAssetsPath()
|
||||||
if glog.V(2) {
|
if glog.V(2) {
|
||||||
|
|
@ -141,7 +141,7 @@ func SetupRoutes(ts graph.TripleStore, cfg *config.CayleyConfig) {
|
||||||
http.Handle("/", r)
|
http.Handle("/", r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Serve(ts graph.TripleStore, cfg *config.CayleyConfig) {
|
func Serve(ts graph.TripleStore, cfg *config.Config) {
|
||||||
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)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue