mirror of
https://github.com/vbatts/imgsrv.git
synced 2024-11-23 08:35:43 +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
|
||||||
}
|
}
|
||||||
|
|
10
imgsrv.go
10
imgsrv.go
|
@ -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: "",
|
||||||
|
@ -78,9 +79,9 @@ func main() {
|
||||||
log.Println("Please provide files to be uploaded!")
|
log.Println("Please provide files to be uploaded!")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
params := map[string]string{}
|
params := map[string]string{}
|
||||||
if len(FileKeywords) > 0 {
|
if len(FileKeywords) > 0 {
|
||||||
params["keywords"] = FileKeywords
|
params["keywords"] = FileKeywords
|
||||||
} else {
|
} else {
|
||||||
log.Println("WARN: you didn't provide any keywords :-(")
|
log.Println("WARN: you didn't provide any keywords :-(")
|
||||||
}
|
}
|
||||||
|
@ -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",
|
||||||
|
|
29
server.go
29
server.go
|
@ -33,17 +33,24 @@ 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
|
||||||
Seed string
|
if du, ok = dbutil.Handles[serverConfig.DbHandler]; !ok {
|
||||||
User string
|
log.Fatalf("DbHandler %q not found", serverConfig.DbHandler)
|
||||||
Pass string
|
}
|
||||||
DbName string
|
|
||||||
}{
|
if serverConfig.DbHandler == "mongo" {
|
||||||
serverConfig.MongoHost,
|
duConfig = struct {
|
||||||
serverConfig.MongoUsername,
|
Seed string
|
||||||
serverConfig.MongoPassword,
|
User string
|
||||||
serverConfig.MongoDbName,
|
Pass string
|
||||||
|
DbName string
|
||||||
|
}{
|
||||||
|
serverConfig.MongoHost,
|
||||||
|
serverConfig.MongoUsername,
|
||||||
|
serverConfig.MongoPassword,
|
||||||
|
serverConfig.MongoDbName,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := du.Init(json.Marshal(duConfig)); err != nil {
|
if err := du.Init(json.Marshal(duConfig)); err != nil {
|
||||||
|
|
Loading…
Reference in a new issue