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 (
|
||||
"io/ioutil"
|
||||
|
||||
"launchpad.net/goyaml"
|
||||
)
|
||||
|
||||
|
@ -9,6 +10,7 @@ type Config struct {
|
|||
Server bool // Run as server, if different than false (server)
|
||||
Ip string // Bind address, if different than 0.0.0.0 (server)
|
||||
Port string // listen port, if different than '7777' (server)
|
||||
DbHandler string // "mongo" (server)
|
||||
MongoHost string // mongoDB host, if different than 'localhost' (server)
|
||||
MongoDbName string // mongoDB db name, if different than 'filesrv' (server)
|
||||
MongoUsername string // mongoDB username, if any (server)
|
||||
|
@ -52,6 +54,9 @@ func (c *Config) Merge(other *Config) error {
|
|||
if len(other.Port) > 0 {
|
||||
c.Port = other.Port
|
||||
}
|
||||
if len(other.DbHandler) > 0 {
|
||||
c.DbHandler = other.DbHandler
|
||||
}
|
||||
if len(other.MongoHost) > 0 {
|
||||
c.MongoHost = other.MongoHost
|
||||
}
|
||||
|
|
10
imgsrv.go
10
imgsrv.go
|
@ -26,6 +26,7 @@ var (
|
|||
Server: false,
|
||||
Ip: "0.0.0.0",
|
||||
Port: "7777",
|
||||
DbHandler: "mongo",
|
||||
MongoHost: "localhost",
|
||||
MongoDbName: "filesrv",
|
||||
MongoUsername: "",
|
||||
|
@ -78,9 +79,9 @@ func main() {
|
|||
log.Println("Please provide files to be uploaded!")
|
||||
return
|
||||
}
|
||||
params := map[string]string{}
|
||||
params := map[string]string{}
|
||||
if len(FileKeywords) > 0 {
|
||||
params["keywords"] = FileKeywords
|
||||
params["keywords"] = FileKeywords
|
||||
} else {
|
||||
log.Println("WARN: you didn't provide any keywords :-(")
|
||||
}
|
||||
|
@ -124,6 +125,11 @@ func init() {
|
|||
DefaultConfig.Port,
|
||||
"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 */
|
||||
flag.StringVar(&DefaultConfig.MongoHost,
|
||||
"mongo-host",
|
||||
|
|
29
server.go
29
server.go
|
@ -33,17 +33,24 @@ var (
|
|||
func runServer(c *config.Config) {
|
||||
serverConfig = *c
|
||||
|
||||
du = dbutil.Handles["mongo"]
|
||||
duConfig := struct {
|
||||
Seed string
|
||||
User string
|
||||
Pass string
|
||||
DbName string
|
||||
}{
|
||||
serverConfig.MongoHost,
|
||||
serverConfig.MongoUsername,
|
||||
serverConfig.MongoPassword,
|
||||
serverConfig.MongoDbName,
|
||||
var duConfig interface{}
|
||||
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
|
||||
User string
|
||||
Pass string
|
||||
DbName string
|
||||
}{
|
||||
serverConfig.MongoHost,
|
||||
serverConfig.MongoUsername,
|
||||
serverConfig.MongoPassword,
|
||||
serverConfig.MongoDbName,
|
||||
}
|
||||
}
|
||||
|
||||
if err := du.Init(json.Marshal(duConfig)); err != nil {
|
||||
|
|
Loading…
Reference in a new issue