1
0
forked from x/icebergs
icebergs/misc/es/es.go
2020-08-29 16:30:42 +08:00

84 lines
3.2 KiB
Go

package es
import (
ice "github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/base/web"
"github.com/shylinux/icebergs/core/code"
kit "github.com/shylinux/toolkits"
"path"
"runtime"
"strings"
)
const ES = "es"
var Index = &ice.Context{Name: ES, Help: "搜索",
Configs: map[string]*ice.Config{
ES: {Name: ES, Help: "搜索", Value: kit.Data(
"address", "http://localhost:9200",
"windows", "https://elasticsearch.thans.cn/downloads/elasticsearch/elasticsearch-7.3.2-windows-x86_64.zip",
"darwin", "https://elasticsearch.thans.cn/downloads/elasticsearch/elasticsearch-7.3.2-darwin-x86_64.tar.gz",
"linux", "https://elasticsearch.thans.cn/downloads/elasticsearch/elasticsearch-7.3.2-linux-x86_64.tar.gz",
)},
},
Commands: map[string]*ice.Command{
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}},
ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}},
ES: {Name: "es port=auto path=auto auto 启动:button 下载", Help: "搜索", Action: map[string]*ice.Action{
"download": {Name: "download", Help: "下载", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(code.INSTALL, "download", m.Conf(ES, kit.Keys(kit.MDB_META, runtime.GOOS)))
}},
"start": {Name: "start", Help: "启动", Hand: func(m *ice.Message, arg ...string) {
m.Option("install", ".")
name := path.Base(m.Conf(ES, kit.Keys(kit.MDB_META, runtime.GOOS)))
name = strings.Join(strings.Split(name, "-")[:2], "-")
m.Cmdy(code.INSTALL, "start", name, "bin/elasticsearch")
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
name := path.Base(m.Conf(ES, kit.Keys(kit.MDB_META, runtime.GOOS)))
name = strings.Join(strings.Split(name, "-")[:2], "-")
m.Cmdy(code.INSTALL, name, arg)
}},
"GET": {Name: "GET 查看:button cmd:text=/", Help: "命令", Action: map[string]*ice.Action{}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if pod := m.Option("_pod"); pod != "" {
m.Option("_pod", "")
m.Cmdy(web.SPACE, pod, m.Prefix(cmd), arg)
if m.Result(0) != ice.ErrWarn || m.Result(1) != ice.ErrNotFound {
return
}
m.Set(ice.MSG_RESULT)
}
m.Option(web.SPIDE_HEADER, web.ContentType, web.ContentJSON)
m.Echo(kit.Formats(kit.UnMarshal(m.Cmdx(web.SPIDE, web.SPIDE_DEV, web.SPIDE_RAW,
web.SPIDE_GET, kit.MergeURL2(m.Conf(ES, "meta.address"), kit.Select("/", arg, 0))))))
}},
"CMD": {Name: "CMD 执行:button method:select=GET|PUT|POST|DELETE cmd:text=/ data:textarea", Help: "命令", Action: map[string]*ice.Action{}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if pod := m.Option("_pod"); pod != "" {
m.Option("_pod", "")
m.Cmdy(web.SPACE, pod, m.Prefix(cmd), arg)
if m.Result(0) != ice.ErrWarn || m.Result(1) != ice.ErrNotFound {
return
}
m.Set(ice.MSG_RESULT)
}
m.Option(web.SPIDE_HEADER, web.ContentType, web.ContentJSON)
prefix := []string{web.SPIDE, web.SPIDE_DEV, web.SPIDE_RAW, arg[0], kit.MergeURL2(m.Conf(ES, "meta.address"), arg[1])}
if len(arg) > 2 {
prefix = append(prefix, web.SPIDE_DATA, arg[2])
}
m.Echo(kit.Formats(kit.UnMarshal(m.Cmdx(prefix))))
}},
},
}
func init() { code.Index.Register(Index, nil) }