mirror of
https://shylinux.com/x/ContextOS
synced 2025-04-26 01:04:06 +08:00
vpn add context.web 添加网页服务
This commit is contained in:
parent
9911e98f8a
commit
afa38f685f
15
README.md
15
README.md
@ -1,2 +1,15 @@
|
||||
# context
|
||||
context上下文,像进程上下文一样,为服务提供一个智能化的运行环境,动态接口、消息处理、服务管理、自动级联、路径搜索 。
|
||||
context: 通过提供动态接口,自由组合功能模块,让开发变得更简单。
|
||||
|
||||
## 模块设计原则
|
||||
* 必须让自己容易知道想做什么
|
||||
* 必须让研发容易知道能做什么
|
||||
* 必须让用户容易知道会做什么
|
||||
|
||||
## 模块设计接口
|
||||
* 模块管理context
|
||||
* 命令管理command
|
||||
* 配置管理config
|
||||
* 缓存管理cache
|
||||
* 服务管理server
|
||||
|
||||
|
@ -5,6 +5,6 @@ alias $ cache
|
||||
alias & server
|
||||
alias * message
|
||||
|
||||
~ssh
|
||||
@client no
|
||||
&
|
||||
#~ssh
|
||||
#@client no
|
||||
#&
|
||||
|
12
etc/note.ctx
Normal file
12
etc/note.ctx
Normal file
@ -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
|
||||
|
||||
|
@ -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) // {{{
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
@ -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},
|
||||
},
|
||||
|
49
src/context/web/web.go
Normal file
49
src/context/web/web.go
Normal file
@ -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)
|
||||
}
|
@ -4,6 +4,7 @@ import (
|
||||
_ "context"
|
||||
"context/cli"
|
||||
_ "context/ssh"
|
||||
_ "context/web"
|
||||
"os"
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user