mirror of
https://shylinux.com/x/icebergs
synced 2025-04-26 09:34:05 +08:00
opt search
This commit is contained in:
parent
3c0f0b7890
commit
baff30a214
@ -31,7 +31,6 @@ func init() {
|
|||||||
for _, k := range strings.Split(arg[0], ",") {
|
for _, k := range strings.Split(arg[0], ",") {
|
||||||
for _, kk := range strings.Split(arg[1], ",") {
|
for _, kk := range strings.Split(arg[1], ",") {
|
||||||
m.Richs(SEARCH, nil, k, func(key string, value map[string]interface{}) {
|
m.Richs(SEARCH, nil, k, func(key string, value map[string]interface{}) {
|
||||||
m.Debug("what %v --- %v %v ", k, kk, key)
|
|
||||||
m.Cmdy(kit.Keys(value[kit.MDB_TEXT], value[kit.MDB_NAME]), SEARCH, k, kk, kit.Select("", arg, 2))
|
m.Cmdy(kit.Keys(value[kit.MDB_TEXT], value[kit.MDB_NAME]), SEARCH, k, kk, kit.Select("", arg, 2))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -22,10 +23,10 @@ func Render(msg *ice.Message, cmd string, args ...interface{}) {
|
|||||||
switch arg := kit.Simple(args...); cmd {
|
switch arg := kit.Simple(args...); cmd {
|
||||||
case ice.RENDER_VOID:
|
case ice.RENDER_VOID:
|
||||||
case ice.RENDER_RESULT:
|
case ice.RENDER_RESULT:
|
||||||
fmt.Fprintf(msg.O, msg.Result())
|
fmt.Fprint(msg.O, msg.Result())
|
||||||
|
|
||||||
case ice.RENDER_QRCODE:
|
case ice.RENDER_QRCODE:
|
||||||
fmt.Fprintf(msg.O, msg.Cmdx(cli.PYTHON, "qrcode", kit.Format(args[0], args[1:]...)))
|
fmt.Fprint(msg.O, msg.Cmdx(cli.PYTHON, "qrcode", kit.Format(args[0], args[1:]...)))
|
||||||
|
|
||||||
case ice.RENDER_DOWNLOAD:
|
case ice.RENDER_DOWNLOAD:
|
||||||
if f, e := os.Open(arg[0]); e == nil {
|
if f, e := os.Open(arg[0]); e == nil {
|
||||||
@ -43,8 +44,8 @@ func Render(msg *ice.Message, cmd string, args ...interface{}) {
|
|||||||
args = append(args, "length:", len(res))
|
args = append(args, "length:", len(res))
|
||||||
|
|
||||||
// 输出结果
|
// 输出结果
|
||||||
if fmt.Fprintf(msg.O, res); !strings.HasSuffix(res, "\n") {
|
if fmt.Fprint(msg.O, res); !strings.HasSuffix(res, "\n") {
|
||||||
fmt.Fprintf(msg.O, "\n")
|
fmt.Fprint(msg.O, "\n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -386,6 +387,18 @@ func init() {
|
|||||||
cb()
|
cb()
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
|
|
||||||
|
"hi": {Name: "hi", Help: "hi", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
|
cb := func() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
t := reflect.TypeOf(cb)
|
||||||
|
v := reflect.ValueOf(cb)
|
||||||
|
m.Echo("what %#v", t.Kind())
|
||||||
|
m.Echo("what %#v", t)
|
||||||
|
m.Echo("what %v", v)
|
||||||
|
}},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -151,7 +151,7 @@ func _space_handle(m *ice.Message, safe bool, send map[string]*ice.Message, c *w
|
|||||||
} else if msg.Richs(SPACE, nil, target[0], func(key string, value map[string]interface{}) {
|
} else if msg.Richs(SPACE, nil, target[0], func(key string, value map[string]interface{}) {
|
||||||
if s, ok := value[tcp.SOCKET].(*websocket.Conn); ok {
|
if s, ok := value[tcp.SOCKET].(*websocket.Conn); ok {
|
||||||
socket, source, target = s, source, target[1:]
|
socket, source, target = s, source, target[1:]
|
||||||
_space_echo(msg, source, target, socket, target[0])
|
_space_echo(msg, source, target, socket, kit.Select("", target))
|
||||||
return // 转发报文
|
return // 转发报文
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ const CHAT = "chat"
|
|||||||
var Index = &ice.Context{Name: CHAT, Help: "聊天中心",
|
var Index = &ice.Context{Name: CHAT, Help: "聊天中心",
|
||||||
Commands: map[string]*ice.Command{
|
Commands: map[string]*ice.Command{
|
||||||
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
|
m.Cmd(mdb.SEARCH, mdb.CREATE, P_SEARCH, m.Prefix(P_SEARCH))
|
||||||
m.Cmd(mdb.SEARCH, mdb.CREATE, EMAIL, m.Prefix(EMAIL))
|
m.Cmd(mdb.SEARCH, mdb.CREATE, EMAIL, m.Prefix(EMAIL))
|
||||||
m.Load()
|
m.Load()
|
||||||
m.Cmd(web.SERVE, aaa.WHITE, "header", "river", "action", "footer")
|
m.Cmd(web.SERVE, aaa.WHITE, "header", "river", "action", "footer")
|
||||||
|
@ -2,22 +2,41 @@ package chat
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
ice "github.com/shylinux/icebergs"
|
ice "github.com/shylinux/icebergs"
|
||||||
|
"github.com/shylinux/icebergs/base/ctx"
|
||||||
"github.com/shylinux/icebergs/base/mdb"
|
"github.com/shylinux/icebergs/base/mdb"
|
||||||
kit "github.com/shylinux/toolkits"
|
kit "github.com/shylinux/toolkits"
|
||||||
)
|
)
|
||||||
|
|
||||||
const SEARCHS = "searchs"
|
const P_SEARCH = "/search"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
Index.Merge(&ice.Context{
|
Index.Merge(&ice.Context{
|
||||||
Configs: map[string]*ice.Config{
|
Configs: map[string]*ice.Config{
|
||||||
SEARCHS: {Name: "searchs", Help: "搜索", Value: kit.Data(kit.MDB_SHORT, kit.MDB_NAME)},
|
P_SEARCH: {Name: "/search", Help: "搜索", Value: kit.Data(kit.MDB_SHORT, kit.MDB_NAME)},
|
||||||
},
|
},
|
||||||
Commands: map[string]*ice.Command{
|
Commands: map[string]*ice.Command{
|
||||||
"/search": {Name: "/search", Help: "搜索引擎", Action: map[string]*ice.Action{
|
P_SEARCH: {Name: "/search", Help: "搜索引擎", Action: map[string]*ice.Action{
|
||||||
mdb.RENDER: {Name: "render", Help: "渲染", Hand: func(m *ice.Message, arg ...string) {
|
mdb.RENDER: {Name: "render", Help: "渲染", Hand: func(m *ice.Message, arg ...string) {
|
||||||
m.Cmdy(m.Space(m.Option(POD)), mdb.RENDER, arg[1:])
|
m.Cmdy(m.Space(m.Option(POD)), mdb.RENDER, arg[1:])
|
||||||
}},
|
}},
|
||||||
|
mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
if arg[0] != P_SEARCH && arg[0] != kit.MDB_FOREACH {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
m.Richs(P_SEARCH, "", kit.MDB_FOREACH, func(key string, value map[string]interface{}) {
|
||||||
|
if value = kit.GetMeta(value); arg[1] != "" && !kit.Contains(value[kit.MDB_NAME], arg[1]) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
m.PushSearch(kit.SSH_CMD, P_SEARCH, value)
|
||||||
|
})
|
||||||
|
}},
|
||||||
|
ctx.COMMAND: {Name: "command", Help: "命令", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
if len(arg) > 0 && arg[0] == "run" {
|
||||||
|
m.Cmdy(arg[1:])
|
||||||
|
return
|
||||||
|
}
|
||||||
|
m.Cmdy(ctx.COMMAND, arg)
|
||||||
|
}},
|
||||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
if kit.Contains(arg[1], ";") {
|
if kit.Contains(arg[1], ";") {
|
||||||
arg = kit.Split(arg[1], ";", ";", ";")
|
arg = kit.Split(arg[1], ";", ";", ";")
|
||||||
@ -26,8 +45,8 @@ func init() {
|
|||||||
if m.Cmdy(m.Space(m.Option(POD)), mdb.SEARCH, arg); arg[1] == "" {
|
if m.Cmdy(m.Space(m.Option(POD)), mdb.SEARCH, arg); arg[1] == "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
m.Cmd(mdb.INSERT, m.Prefix(SEARCHS), "", mdb.HASH,
|
m.Cmd(mdb.INSERT, m.Prefix(P_SEARCH), "", mdb.HASH,
|
||||||
"name", arg[1], "type", arg[0], "text", kit.Select("", arg, 2))
|
kit.MDB_NAME, arg[1], kit.MDB_TYPE, arg[0], kit.MDB_TEXT, kit.Select("", arg, 2))
|
||||||
}},
|
}},
|
||||||
}})
|
}})
|
||||||
}
|
}
|
||||||
|
@ -107,6 +107,19 @@ func _task_inputs(m *ice.Message, field, value string) {
|
|||||||
m.Cmdy(mdb.INPUTS, TASK, _sub_key(m, m.Option(kit.MDB_ZONE)), mdb.LIST, field, value)
|
m.Cmdy(mdb.INPUTS, TASK, _sub_key(m, m.Option(kit.MDB_ZONE)), mdb.LIST, field, value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
func _task_search(m *ice.Message, kind, name, text string) {
|
||||||
|
if kind != TASK && kind != kit.MDB_FOREACH {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
m.Cmd(mdb.SELECT, m.Prefix(TASK), "", mdb.ZONE, kit.MDB_FOREACH, func(key string, value map[string]interface{}, val map[string]interface{}) {
|
||||||
|
if name != "" && !kit.Contains(value[kit.MDB_NAME], name) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
m.PushSearch(kit.SSH_CMD, TASK, kit.MDB_TYPE, val[kit.MDB_ZONE], kit.MDB_NAME, kit.Format(value[kit.MDB_ID]),
|
||||||
|
kit.MDB_TEXT, kit.Format("%v:%v", value[kit.MDB_NAME], value[kit.MDB_TEXT]), value)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
var TaskField = struct{ LEVEL, STATUS, SCORE, BEGIN_TIME, CLOSE_TIME string }{
|
var TaskField = struct{ LEVEL, STATUS, SCORE, BEGIN_TIME, CLOSE_TIME string }{
|
||||||
LEVEL: "level",
|
LEVEL: "level",
|
||||||
@ -163,6 +176,9 @@ func init() {
|
|||||||
mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
|
mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
|
||||||
_task_inputs(m, kit.Select("", arg, 0), kit.Select("", arg, 1))
|
_task_inputs(m, kit.Select("", arg, 0), kit.Select("", arg, 1))
|
||||||
}},
|
}},
|
||||||
|
mdb.SEARCH: {Name: "search", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
_task_search(m, arg[0], arg[1], arg[2])
|
||||||
|
}},
|
||||||
|
|
||||||
gdb.BEGIN: {Name: "begin", Help: "开始", Hand: func(m *ice.Message, arg ...string) {
|
gdb.BEGIN: {Name: "begin", Help: "开始", Hand: func(m *ice.Message, arg ...string) {
|
||||||
_task_modify(m, m.Option(kit.MDB_ZONE), m.Option(kit.MDB_ID), TaskField.STATUS, TaskStatus.PROCESS)
|
_task_modify(m, m.Option(kit.MDB_ZONE), m.Option(kit.MDB_ID), TaskField.STATUS, TaskStatus.PROCESS)
|
||||||
|
@ -2,6 +2,7 @@ package team
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
ice "github.com/shylinux/icebergs"
|
ice "github.com/shylinux/icebergs"
|
||||||
|
"github.com/shylinux/icebergs/base/mdb"
|
||||||
"github.com/shylinux/icebergs/base/web"
|
"github.com/shylinux/icebergs/base/web"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -9,7 +10,10 @@ const TEAM = "team"
|
|||||||
|
|
||||||
var Index = &ice.Context{Name: TEAM, Help: "团队中心",
|
var Index = &ice.Context{Name: TEAM, Help: "团队中心",
|
||||||
Commands: map[string]*ice.Command{
|
Commands: map[string]*ice.Command{
|
||||||
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Load() }},
|
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
|
m.Cmd(mdb.SEARCH, mdb.CREATE, TASK, m.Prefix(TASK))
|
||||||
|
m.Load()
|
||||||
|
}},
|
||||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Save() }},
|
ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Save() }},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
12
type.go
12
type.go
@ -7,6 +7,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
@ -618,6 +619,17 @@ func (m *Message) Search(key string, cb interface{}) *Message {
|
|||||||
|
|
||||||
func (m *Message) _hand(arg ...interface{}) *Message {
|
func (m *Message) _hand(arg ...interface{}) *Message {
|
||||||
list := kit.Simple(arg...)
|
list := kit.Simple(arg...)
|
||||||
|
if len(arg) > 0 {
|
||||||
|
switch cb := arg[len(arg)-1]; cbs := cb.(type) {
|
||||||
|
case string:
|
||||||
|
default:
|
||||||
|
if reflect.Func == reflect.TypeOf(cbs).Kind() {
|
||||||
|
m.Optionv(list[0]+".cb", cbs)
|
||||||
|
list = list[:len(list)-1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if len(list) == 0 && m.Hand == false {
|
if len(list) == 0 && m.Hand == false {
|
||||||
list = m.meta[MSG_DETAIL]
|
list = m.meta[MSG_DETAIL]
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user