mirror of
https://github.com/vbatts/imgsrv.git
synced 2024-11-27 02:25:41 +00:00
*: bubble the dbhandler up to cli
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
parent
51545d2e46
commit
f768d2f9f6
3 changed files with 31 additions and 13 deletions
|
@ -2,6 +2,7 @@ package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
|
||||||
"launchpad.net/goyaml"
|
"launchpad.net/goyaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -9,6 +10,7 @@ type Config struct {
|
||||||
Server bool // Run as server, if different than false (server)
|
Server bool // Run as server, if different than false (server)
|
||||||
Ip string // Bind address, if different than 0.0.0.0 (server)
|
Ip string // Bind address, if different than 0.0.0.0 (server)
|
||||||
Port string // listen port, if different than '7777' (server)
|
Port string // listen port, if different than '7777' (server)
|
||||||
|
DbHandler string // "mongo" (server)
|
||||||
MongoHost string // mongoDB host, if different than 'localhost' (server)
|
MongoHost string // mongoDB host, if different than 'localhost' (server)
|
||||||
MongoDbName string // mongoDB db name, if different than 'filesrv' (server)
|
MongoDbName string // mongoDB db name, if different than 'filesrv' (server)
|
||||||
MongoUsername string // mongoDB username, if any (server)
|
MongoUsername string // mongoDB username, if any (server)
|
||||||
|
@ -52,6 +54,9 @@ func (c *Config) Merge(other *Config) error {
|
||||||
if len(other.Port) > 0 {
|
if len(other.Port) > 0 {
|
||||||
c.Port = other.Port
|
c.Port = other.Port
|
||||||
}
|
}
|
||||||
|
if len(other.DbHandler) > 0 {
|
||||||
|
c.DbHandler = other.DbHandler
|
||||||
|
}
|
||||||
if len(other.MongoHost) > 0 {
|
if len(other.MongoHost) > 0 {
|
||||||
c.MongoHost = other.MongoHost
|
c.MongoHost = other.MongoHost
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ var (
|
||||||
Server: false,
|
Server: false,
|
||||||
Ip: "0.0.0.0",
|
Ip: "0.0.0.0",
|
||||||
Port: "7777",
|
Port: "7777",
|
||||||
|
DbHandler: "mongo",
|
||||||
MongoHost: "localhost",
|
MongoHost: "localhost",
|
||||||
MongoDbName: "filesrv",
|
MongoDbName: "filesrv",
|
||||||
MongoUsername: "",
|
MongoUsername: "",
|
||||||
|
@ -124,6 +125,11 @@ func init() {
|
||||||
DefaultConfig.Port,
|
DefaultConfig.Port,
|
||||||
"Port to listen on (if running as a server)('port' in the config)")
|
"Port to listen on (if running as a server)('port' in the config)")
|
||||||
|
|
||||||
|
flag.StringVar(&DefaultConfig.DbHandler,
|
||||||
|
"dbhandler",
|
||||||
|
DefaultConfig.DbHandler,
|
||||||
|
"Database backend handler (if runnint as a server)")
|
||||||
|
|
||||||
/* MongoDB settings */
|
/* MongoDB settings */
|
||||||
flag.StringVar(&DefaultConfig.MongoHost,
|
flag.StringVar(&DefaultConfig.MongoHost,
|
||||||
"mongo-host",
|
"mongo-host",
|
||||||
|
|
11
server.go
11
server.go
|
@ -33,8 +33,14 @@ var (
|
||||||
func runServer(c *config.Config) {
|
func runServer(c *config.Config) {
|
||||||
serverConfig = *c
|
serverConfig = *c
|
||||||
|
|
||||||
du = dbutil.Handles["mongo"]
|
var duConfig interface{}
|
||||||
duConfig := struct {
|
var ok bool
|
||||||
|
if du, ok = dbutil.Handles[serverConfig.DbHandler]; !ok {
|
||||||
|
log.Fatalf("DbHandler %q not found", serverConfig.DbHandler)
|
||||||
|
}
|
||||||
|
|
||||||
|
if serverConfig.DbHandler == "mongo" {
|
||||||
|
duConfig = struct {
|
||||||
Seed string
|
Seed string
|
||||||
User string
|
User string
|
||||||
Pass string
|
Pass string
|
||||||
|
@ -45,6 +51,7 @@ func runServer(c *config.Config) {
|
||||||
serverConfig.MongoPassword,
|
serverConfig.MongoPassword,
|
||||||
serverConfig.MongoDbName,
|
serverConfig.MongoDbName,
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if err := du.Init(json.Marshal(duConfig)); err != nil {
|
if err := du.Init(json.Marshal(duConfig)); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
|
Loading…
Reference in a new issue