lessmore/main.go

58 lines
1.2 KiB
Go
Raw Permalink Normal View History

2017-02-12 13:19:02 +03:00
package main
import (
"flag"
2018-11-05 18:24:46 +03:00
"os"
2017-02-12 13:19:02 +03:00
"gitea.difrex.ru/Umbrella/lessmore/node"
2018-11-05 18:24:46 +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
2018-11-06 14:19:40 +03:00
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")
2017-02-12 13:19:02 +03:00
flag.StringVar(&esMessagesIndex, "esindex", "idec3", "ES index")
flag.StringVar(&esMessagesType, "estype", "post", "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")
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)
}
2017-02-12 13:19:02 +03:00
node.Serve(listen, esconf)
}
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)
}