lessmore/main.go

78 lines
1.7 KiB
Go
Raw Normal View History

2017-02-12 13:19:02 +03:00
package main
import (
"flag"
2018-11-05 18:24:46 +03:00
"os"
2021-03-25 18:11:00 +03:00
"github.com/idec-net/lessmore-node/node"
2018-11-12 15:06:39 +03:00
log "github.com/sirupsen/logrus"
2017-02-12 13:19:02 +03:00
)
var (
listen string
es string
esMessagesIndex string
esMessagesType string
2018-11-05 18:24:46 +03:00
add string
email string
2021-04-02 17:11:12 +03:00
templatesDir string
serveStatic bool
staticDir string
debug bool
2017-02-12 13:19:02 +03:00
)
// init ...
func init() {
flag.StringVar(&listen, "listen", "127.0.0.1:15582", "Address to listen")
2017-02-13 10:24:21 +03:00
flag.StringVar(&es, "es", "http://127.0.0.1:9200", "ES host")
2021-03-25 18:11:00 +03:00
flag.StringVar(&esMessagesIndex, "esindex", "", "ES index")
flag.StringVar(&esMessagesType, "estype", "", "ES index type")
2018-11-05 18:24:46 +03:00
flag.StringVar(&add, "add", "", "User to add")
flag.StringVar(&email, "email", "", "User email address")
2021-04-02 17:11:12 +03:00
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")
2018-11-06 14:19:40 +03:00
flag.BoolVar(&debug, "debug", false, "Debug output")
2017-02-12 13:19:02 +03:00
flag.Parse()
2018-11-06 08:23:15 +03:00
2018-11-06 14:19:40 +03:00
if debug {
log.SetLevel(log.DebugLevel)
}
2017-02-12 13:19:02 +03:00
}
// main ...
func main() {
esconf := node.ESConf{}
esconf.Host = es
esconf.Index = esMessagesIndex
esconf.Type = esMessagesType
2018-11-05 18:24:46 +03:00
if add != "" {
addUser(add, esconf)
}
2021-04-02 17:11:12 +03:00
opts := &node.ServeOpts{
Listen: listen,
ES: esconf,
TemplatesDir: templatesDir,
ServeStatic: serveStatic,
StaticDir: staticDir,
}
node.Serve(opts)
2017-02-12 13:19:02 +03:00
}
2018-11-05 18:24:46 +03:00
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)
}