lessmore/main.go

78 lines
1.7 KiB
Go

package main
import (
"flag"
"os"
"github.com/idec-net/lessmore-node/node"
log "github.com/sirupsen/logrus"
)
var (
listen string
es string
esMessagesIndex string
esMessagesType string
add string
email string
templatesDir string
serveStatic bool
staticDir string
debug bool
)
// init ...
func init() {
flag.StringVar(&listen, "listen", "127.0.0.1:15582", "Address to listen")
flag.StringVar(&es, "es", "http://127.0.0.1:9200", "ES host")
flag.StringVar(&esMessagesIndex, "esindex", "", "ES index")
flag.StringVar(&esMessagesType, "estype", "", "ES index type")
flag.StringVar(&add, "add", "", "User to add")
flag.StringVar(&email, "email", "", "User email address")
flag.StringVar(&templatesDir, "templates-dir", "/usr/local/share/lessmore/templates", "Path to templates dir")
flag.StringVar(&staticDir, "static-dir", "/usr/local/share/lessmore/static", "Path to static dir")
flag.BoolVar(&serveStatic, "static-serve", false, "Serve static files")
flag.BoolVar(&debug, "debug", false, "Debug output")
flag.Parse()
if debug {
log.SetLevel(log.DebugLevel)
}
}
// main ...
func main() {
esconf := node.ESConf{}
esconf.Host = es
esconf.Index = esMessagesIndex
esconf.Type = esMessagesType
if add != "" {
addUser(add, esconf)
}
opts := &node.ServeOpts{
Listen: listen,
ES: esconf,
TemplatesDir: templatesDir,
ServeStatic: serveStatic,
StaticDir: staticDir,
}
node.Serve(opts)
}
func addUser(name string, esconf node.ESConf) {
user, err := esconf.AddNewUser(add, email)
if err != nil {
log.Fatal(err)
os.Exit(2)
}
log.Infof("Created: %+v", user)
os.Exit(0)
}