diff --git a/README.md b/README.md index c8fdb81b..2152ec8f 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,15 @@ # context -context上下文,像进程上下文一样,为服务提供一个智能化的运行环境,动态接口、消息处理、服务管理、自动级联、路径搜索 。 +context: 通过提供动态接口,自由组合功能模块,让开发变得更简单。 + +## 模块设计原则 +* 必须让自己容易知道想做什么 +* 必须让研发容易知道能做什么 +* 必须让用户容易知道会做什么 + +## 模块设计接口 +* 模块管理context +* 命令管理command +* 配置管理config +* 缓存管理cache +* 服务管理server + diff --git a/etc/hi.sh b/etc/hi.sh index c10ba31b..edf0d8d8 100644 --- a/etc/hi.sh +++ b/etc/hi.sh @@ -5,6 +5,6 @@ alias $ cache alias & server alias * message -~ssh -@client no -& +#~ssh +#@client no +#& diff --git a/etc/note.ctx b/etc/note.ctx new file mode 100644 index 00000000..02852b1a --- /dev/null +++ b/etc/note.ctx @@ -0,0 +1,12 @@ +golang +help tool version env +get list doc fmt fix vet +run build test install clean + +git +help init clone +status add rm mv diff grep show reset commit +branch merge rebase log tag checkout +remote pull push fetch + + diff --git a/src/context/cli/cli.go b/src/context/cli/cli.go index 7d23aa6f..4d4ecef4 100644 --- a/src/context/cli/cli.go +++ b/src/context/cli/cli.go @@ -8,6 +8,7 @@ import ( // {{{ "log" "os" "os/exec" + "runtime/debug" "strconv" "strings" "time" @@ -145,6 +146,7 @@ func (cli *CLI) deal(msg *ctx.Message) bool { // {{{ defer func() { if e := recover(); e != nil { msg.Echo("%s", e) + debug.PrintStack() log.Println(e) } }() @@ -256,7 +258,7 @@ func (cli *CLI) Spawn(c *ctx.Context, key string) ctx.Server { // {{{ // }}} -var Index = &ctx.Context{Name: "cli", Help: "命文", +var Index = &ctx.Context{Name: "cli", Help: "本地控制", Caches: map[string]*ctx.Cache{}, Configs: map[string]*ctx.Config{ "开场白": &ctx.Config{"开场白", "你好,命令行", "开场白", nil}, @@ -425,7 +427,7 @@ var Index = &ctx.Context{Name: "cli", Help: "命文", return "" }}, "server": &ctx.Command{"server start|stop|switch", "服务启动停止切换", func(c *ctx.Context, msg *ctx.Message, arg ...string) string { - cli := c.Server.(*CLI) + cli := c.Server.(*CLI) // {{{ switch len(arg) { case 1: go cli.target.Start() @@ -439,6 +441,7 @@ var Index = &ctx.Context{Name: "cli", Help: "命文", } } return "" + // }}} }}, "context": &ctx.Command{"context [find|search name [switch]]|root|back|home", "查看上下文", func(c *ctx.Context, msg *ctx.Message, arg ...string) string { cli := c.Server.(*CLI) // {{{ diff --git a/src/context/ctx.go b/src/context/ctx.go index f8ce6eee..3873ad49 100644 --- a/src/context/ctx.go +++ b/src/context/ctx.go @@ -101,8 +101,8 @@ func (m *Message) Echo(str string, arg ...interface{}) string { // {{{ type Server interface { // {{{ Begin() bool Start() bool - Fork(c *Context, key string) Server Spawn(c *Context, key string) Server + Fork(c *Context, key string) Server } // }}} @@ -524,15 +524,20 @@ func (c *Context) Del(arg ...string) { // {{{ // }}} // }}} -var Index = &Context{Name: "ctx", Help: "根文", +var Index = &Context{Name: "ctx", Help: "根文", // {{{ Caches: map[string]*Cache{}, Configs: map[string]*Config{ - "开场白": &Config{"开场白", "你好,上下文", "开场白", nil}, - "结束语": &Config{"结束语", "再见,上下文", "结束语", nil}, + "开场白": &Config{"开场白", "你好,上下文", "开场白", nil}, + "结束语": &Config{"结束语", "再见,上下文", "结束语", nil}, + "debug": &Config{"debug", "on", "调试模式", nil}, }, Commands: map[string]*Command{}, } -func init() { +// }}} + +func init() { // {{{ Index.Root = Index } + +// }}} diff --git a/src/context/ssh/ssh.go b/src/context/ssh/ssh.go index 4d26f502..766fa908 100644 --- a/src/context/ssh/ssh.go +++ b/src/context/ssh/ssh.go @@ -89,7 +89,6 @@ func (ssh *SSH) Print(str string, arg ...interface{}) { // {{{ } // }}} - func (ssh *SSH) End() { // {{{ ssh.Echo("len", ssh.len) fmt.Fprintln(ssh.w) @@ -228,7 +227,7 @@ func (ssh *SSH) Spawn(c *ctx.Context, key string) ctx.Server { // {{{ // }}} -var Index = &ctx.Context{Name: "ssh", Help: "运程连接", +var Index = &ctx.Context{Name: "ssh", Help: "远程控制", Caches: map[string]*ctx.Cache{ "status": &ctx.Cache{"status", "stop", "服务器状态", nil}, }, diff --git a/src/context/web/web.go b/src/context/web/web.go new file mode 100644 index 00000000..248d763e --- /dev/null +++ b/src/context/web/web.go @@ -0,0 +1,49 @@ +package web + +import ( + "context" + "net/http" +) + +type WEB struct { + *ctx.Context +} + +func (web *WEB) Begin() bool { + + return true +} +func (web *WEB) Start() bool { + if web.Cap("status") == "start" { + return true + } + web.Cap("status", "start") + defer web.Cap("status", "stop") + + http.Handle("/", http.FileServer(http.Dir(web.Conf("path")))) + http.ListenAndServe(web.Conf("address"), nil) + return true +} +func (web *WEB) Spawn(c *ctx.Context, key string) ctx.Server { + + return nil +} +func (web *WEB) Fork(c *ctx.Context, key string) ctx.Server { + return nil +} + +var Index = &ctx.Context{Name: "web", Help: "网页服务", + Caches: map[string]*ctx.Cache{ + "status": &ctx.Cache{"status", "stop", "服务运行状态", nil}, + }, + Configs: map[string]*ctx.Config{ + "path": &ctx.Config{"path", "srv", "监听地址", nil}, + "address": &ctx.Config{"address", ":9494", "监听地址", nil}, + }, +} + +func init() { + web := &WEB{} + web.Context = Index + ctx.Index.Register(Index, web) +} diff --git a/bench.go b/src/toolkit/bench.go similarity index 93% rename from bench.go rename to src/toolkit/bench.go index b735a205..0ef248dd 100644 --- a/bench.go +++ b/src/toolkit/bench.go @@ -4,6 +4,7 @@ import ( _ "context" "context/cli" _ "context/ssh" + _ "context/web" "os" )