mirror of
https://shylinux.com/x/icebergs
synced 2025-04-26 01:24:05 +08:00
opt some
This commit is contained in:
parent
ce9151ae30
commit
e5bac606f1
@ -22,7 +22,7 @@ func (f *Frame) Spawn(m *ice.Message, c *ice.Context, arg ...string) ice.Server
|
||||
}
|
||||
func (f *Frame) Begin(m *ice.Message, arg ...string) ice.Server {
|
||||
f.p = make(chan *Log, ice.MOD_BUFS)
|
||||
ice.Log = func(msg *ice.Message, p, l, s string) {
|
||||
ice.Info.Log = func(msg *ice.Message, p, l, s string) {
|
||||
f.p <- &Log{m: msg, p: p, l: l, s: s}
|
||||
}
|
||||
return f
|
||||
@ -132,7 +132,7 @@ var Index = &ice.Context{Name: "log", Help: "日志模块",
|
||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if f, ok := m.Target().Server().(*Frame); ok {
|
||||
// 关闭日志
|
||||
ice.Log = nil
|
||||
ice.Info.Log = nil
|
||||
close(f.p)
|
||||
}
|
||||
}},
|
||||
|
20
info.go
20
info.go
@ -28,11 +28,23 @@ var Info = struct {
|
||||
UserName string
|
||||
}
|
||||
|
||||
Pack map[string][]byte
|
||||
names map[string]interface{}
|
||||
Help string
|
||||
Pack map[string][]byte
|
||||
names map[string]interface{}
|
||||
render map[string]func(*Message, string, ...interface{}) string
|
||||
Log func(m *Message, p, l, s string)
|
||||
}{
|
||||
Pack: map[string][]byte{},
|
||||
names: map[string]interface{}{},
|
||||
Help: `
|
||||
^_^ 欢迎使用冰山框架 ^_^
|
||||
^_^ Welcome to Icebergs World ^_^
|
||||
|
||||
report: shylinuxc@gmail.com
|
||||
server: https://shylinux.com
|
||||
source: https://shylinux.com/x/icebergs
|
||||
`,
|
||||
Pack: map[string][]byte{},
|
||||
names: map[string]interface{}{},
|
||||
render: map[string]func(*Message, string, ...interface{}) string{},
|
||||
}
|
||||
|
||||
func Dump(w io.Writer, name string, cb func(string)) bool {
|
||||
|
14
init.go
14
init.go
@ -7,6 +7,7 @@ import (
|
||||
"time"
|
||||
|
||||
kit "shylinux.com/x/toolkits"
|
||||
log "shylinux.com/x/toolkits/logs"
|
||||
)
|
||||
|
||||
type Frame struct {
|
||||
@ -59,7 +60,7 @@ func (f *Frame) Close(m *Message, arg ...string) bool {
|
||||
var Index = &Context{Name: "ice", Help: "冰山模块", Caches: map[string]*Cache{
|
||||
CTX_FOLLOW: {Value: ICE}, CTX_STREAM: {Value: SHY}, CTX_STATUS: {Value: CTX_BEGIN},
|
||||
}, Configs: map[string]*Config{
|
||||
HELP: {Value: kit.Data("index", _help)},
|
||||
HELP: {Value: kit.Data("index", Info.Help)},
|
||||
}, Commands: map[string]*Command{
|
||||
CTX_INIT: {Hand: func(m *Message, c *Context, cmd string, arg ...string) {
|
||||
defer m.Cost(CTX_INIT)
|
||||
@ -124,7 +125,7 @@ func Run(arg ...string) string {
|
||||
|
||||
switch kit.Select("", arg, 0) {
|
||||
case "space", "serve":
|
||||
if _log_disable = false; frame.Begin(Pulse.Spawn(), arg...).Start(Pulse, arg...) {
|
||||
if log.LogDisable = false; frame.Begin(Pulse.Spawn(), arg...).Start(Pulse, arg...) {
|
||||
frame.Close(Pulse.Spawn(), arg...)
|
||||
}
|
||||
|
||||
@ -142,12 +143,3 @@ func Run(arg ...string) string {
|
||||
|
||||
return Pulse.Result()
|
||||
}
|
||||
|
||||
var _help = `
|
||||
^_^ 欢迎使用冰山框架 ^_^
|
||||
^_^ Welcome to Icebergs World ^_^
|
||||
|
||||
report: shylinuxc@gmail.com
|
||||
server: https://shylinux.com
|
||||
source: https://shylinux.com/x/icebergs
|
||||
`
|
||||
|
9
logs.go
9
logs.go
@ -10,15 +10,12 @@ import (
|
||||
log "shylinux.com/x/toolkits/logs"
|
||||
)
|
||||
|
||||
var _log_disable = true
|
||||
var Log func(m *Message, p, l, s string)
|
||||
|
||||
func (m *Message) log(level string, str string, arg ...interface{}) *Message {
|
||||
if _log_disable {
|
||||
if log.LogDisable {
|
||||
return m // 禁用日志
|
||||
}
|
||||
if str = strings.TrimSpace(kit.Format(str, arg...)); Log != nil {
|
||||
Log(m, m.Format(kit.MDB_PREFIX), level, str) // 日志分流
|
||||
if str = strings.TrimSpace(kit.Format(str, arg...)); Info.Log != nil {
|
||||
Info.Log(m, m.Format(kit.MDB_PREFIX), level, str) // 日志分流
|
||||
}
|
||||
|
||||
// 日志颜色
|
||||
|
@ -11,6 +11,7 @@ import (
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
psh "shylinux.com/x/icebergs/base/ssh"
|
||||
"shylinux.com/x/icebergs/base/tcp"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
@ -66,7 +67,7 @@ func _ssh_watch(m *ice.Message, meta map[string]string, h string, input io.Reade
|
||||
const CHANNEL = "channel"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{
|
||||
psh.Index.Merge(&ice.Context{
|
||||
Configs: map[string]*ice.Config{
|
||||
CHANNEL: {Name: "channel", Help: "通道", Value: kit.Data()},
|
||||
},
|
||||
|
@ -16,6 +16,7 @@ import (
|
||||
"shylinux.com/x/icebergs/base/gdb"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
psh "shylinux.com/x/icebergs/base/ssh"
|
||||
"shylinux.com/x/icebergs/base/tcp"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
@ -150,10 +151,11 @@ func _ssh_conn(m *ice.Message, cb func(*ssh.Client), arg ...string) {
|
||||
tcp.PORT, m.Option(tcp.PORT), tcp.HOST, m.Option(tcp.HOST), arg)
|
||||
}
|
||||
|
||||
const SSH = "ssh"
|
||||
const CONNECT = "connect"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{
|
||||
psh.Index.Merge(&ice.Context{
|
||||
Configs: map[string]*ice.Config{
|
||||
CONNECT: {Name: CONNECT, Help: "连接", Value: kit.Data()},
|
||||
},
|
||||
|
@ -10,14 +10,15 @@ import (
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/crypto/ssh"
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
psh "shylinux.com/x/icebergs/base/ssh"
|
||||
"shylinux.com/x/icebergs/base/tcp"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
"golang.org/x/crypto/ssh"
|
||||
)
|
||||
|
||||
func _ssh_meta(conn ssh.ConnMetadata) map[string]string {
|
||||
@ -99,7 +100,7 @@ const (
|
||||
const SERVICE = "service"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{
|
||||
psh.Index.Merge(&ice.Context{
|
||||
Configs: map[string]*ice.Config{
|
||||
SERVICE: {Name: SERVICE, Help: "服务", Value: kit.Data(
|
||||
WELCOME, "\r\nwelcome to context world\r\n",
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
psh "shylinux.com/x/icebergs/base/ssh"
|
||||
"shylinux.com/x/icebergs/base/tcp"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
@ -57,7 +58,7 @@ const (
|
||||
const SESSION = "session"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{
|
||||
psh.Index.Merge(&ice.Context{
|
||||
Configs: map[string]*ice.Config{
|
||||
SESSION: {Name: SESSION, Help: "会话", Value: kit.Data()},
|
||||
},
|
||||
|
@ -8,13 +8,11 @@ import (
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
var renderList = map[string]func(*Message, string, ...interface{}) string{}
|
||||
|
||||
func AddRender(key string, render func(*Message, string, ...interface{}) string) {
|
||||
renderList[key] = render
|
||||
Info.render[key] = render
|
||||
}
|
||||
func Render(m *Message, cmd string, args ...interface{}) string {
|
||||
if render, ok := renderList[cmd]; ok {
|
||||
if render, ok := Info.render[cmd]; ok {
|
||||
m.Debug("render: %v %v", cmd, kit.FileLine(render, 3))
|
||||
return render(m, cmd, args...)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user