ice

package module
v0.2.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 7, 2020 License: MIT Imports: 19 Imported by: 30

README

icebergs

icebergs是一个应用框架,通过模块化、集群化、自动化,快速搭建起完整的个人云计算平台。

  • 使用icebergs可以将各种模块或项目集成到一起,快速开发出集中式的服务器。
  • 使用icebergs可以将各种设备自由的组合在一起,快速搭建起分布式的服务器。

0. 搭建服务

0.1 一键部署
mkdir miss; cd miss && curl -s https://shylinux.com/publish/ice.sh | sh

脚本会根据当前系统类型,自动下载程序文件ice.bin,并自动启动服务。

0.2 使用方式

终端交互

启动后的进程,像bash一样是一个可交互的shell,可以执行各种模块命令或系统命令。

网页交互

默认还会启动一个web服务,访问地址 http://localhost:9020 ,就可以通过网页进行操作。

重启服务

在终端按Ctrl+C,就可以重新启动服务。

结束服务

在终端按Ctrl+\,就可以停止服务。

0.3 使用示例

1. 项目开发

icebergs是一个应用框架,如果官方模块无法满足使用需求,还可以搜集第三方模块,自行编译程序。

如果第三方模块也无法满足使用需求,还可以自己开发模块, icebergs提供了模板,可以一键创建新模块,快速添加自己的功能模块。

1.1 部署环境

开发环境,需要提前安装好git和golang

mkdir miss; cd miss && curl -s https://shylinux.com/publish/template.sh | sh

template.sh会自动创建出项目模板,并自动编译生成程序,然后启动服务。

为了方便以后创建项目与模块。 可以将辅助脚本template.sh下载,并添加到可执行目录中。

1.2 添加第三方模块

在src/main.go文件中,就可以import任意的第三方模块, 执行一下make命令,就会重新生成ice.bin。 重新启动服务,就可以使用第三方模块了。

1.3 开发模块
template.sh tutor hello

使用之前下载的template.sh,调用tutor命令,并指定模块名称hello,就可以一键创建模块了。

在src/main.go 中import新加的模块, 执行make命令,程序编译完成后, 重启服务,就可以使用新模块了。

1.4 开发框架

如果现有的框架,无法满足需求,还可以下载框架源码自行更改。

git clone https://github.com/shylinux/icebergs usr/icebergs

修改go.mod文件,引用本地框架。

replace github.com/shylinux/icebergs => ./usr/icebergs

2 原型 type.go

2.1 msg.Detail
2.2 msg.Option
2.3 msg.Append
2.4 msg.Result
2.5 msg.Travel
2.7 msg.Conf
2.8 msg.Cmd
2.9 msg.Cap

3 框架 base.go

3.1 注册模块 Register
3.2 创建资源 Begin
3.3 加载配置 _init
3.4 启动服务 Start
3.5 保存配置 _exit
3.6 释放资源 Close

4 基础模块 base/

4.1 模块中心 base/ctx/
4.2 命令中心 base/cli/
4.3 认证中心 base/aaa/
4.4 网页中心 base/web/
4.5 词法中心 base/lex/
4.6 语法中心 base/yac/
4.7 事件中心 base/gdb/
4.8 日志中心 base/log/
4.9 网络中心 base/tcp/
4.10 文件中心 base/nfs/
4.11 终端中心 base/ssh/
4.12 数据中心 base/mdb/

5 核心模块 core/

5.1 编程中心 core/code/
5.2 文档中心 core/wiki/
5.3 聊天中心 core/chat/
5.4 团队中心 core/team/
5.5 贸易中心 core/mall/

6 其它模块 misc/

6.1 终端管理 misc/zsh/
6.1 终端管理 misc/tmux/
6.1 容器管理 misc/docker/
6.1 代码管理 misc/git/
6.1 代码管理 misc/vim/
6.1 公众号 misc/mp/
6.1 小程序 misc/wx/
6.1 浏览器 misc/chrome/
6.1 机器人 misc/lark/
6.1 开发板 misc/pi/

Documentation

Index

Constants

View Source
const (
	MOD_DIR  = 0750
	MOD_FILE = 0640

	MOD_CHAN = 16
	MOD_BUF  = 1024

	MOD_DATE = "2006-01-02"
	MOD_TIME = "2006-01-02 15:04:05"
)
View Source
const (
	MSG_DETAIL = "detail"
	MSG_OPTION = "option"
	MSG_APPEND = "append"
	MSG_RESULT = "result"

	MSG_ALIAS  = "_alias"
	MSG_SOURCE = "_source"
	MSG_TARGET = "_target"
	MSG_HANDLE = "_handle"
	MSG_ACTION = "_action"
	MSG_OUTPUT = "_output"
	MSG_ARGS   = "_args"

	MSG_CMDS     = "cmds"
	MSG_SESSID   = "sessid"
	MSG_DOMAIN   = "domain"
	MSG_USERIP   = "user.ip"
	MSG_USERUA   = "user.ua"
	MSG_USERURL  = "user.url"
	MSG_USERWEB  = "user.web"
	MSG_USERPOD  = "user.pod"
	MSG_USERNICK = "user.nick"
	MSG_USERNAME = "user.name"
	MSG_USERZONE = "user.zone"
	MSG_USERROLE = "user.role"
	MSG_USERDATA = "user.data"
	MSG_USERADDR = "user.addr"

	MSG_RIVER  = "sess.river"
	MSG_STORM  = "sess.storm"
	MSG_ACTIVE = "sess.active"
)
View Source
const (
	CTX_STREAM = "stream"
	CTX_STATUS = "status"
	CTX_FOLLOW = "follow"

	CTX_INIT = "_init"
	CTX_EXIT = "_exit"

	CTX_BEGIN = "begin"
	CTX_START = "start"
	CTX_SERVE = "serve"
	CTX_CLOSE = "close"
)
View Source
const (
	// 数据
	LOG_IMPORT = "import"
	LOG_EXPORT = "export"
	LOG_CREATE = "create"
	LOG_REMOVE = "remove"
	LOG_INSERT = "insert"
	LOG_DELETE = "delete"
	LOG_SELECT = "select"
	LOG_MODIFY = "modify"

	// 事件
	LOG_ENABLE = "enable"
	LOG_STATUS = "status"
	LOG_LISTEN = "listen"
	LOG_ACCEPT = "accept"
	LOG_FINISH = "finish"
	LOG_SIGNAL = "signal"
	LOG_TIMERS = "timers"
	LOG_EVENTS = "events"

	// 状态
	LOG_BEGIN = "begin"
	LOG_START = "start"
	LOG_SERVE = "serve"
	LOG_CLOSE = "close"

	// 分类
	LOG_CONF  = "conf"
	LOG_CMDS  = "cmds"
	LOG_AUTH  = "auth"
	LOG_COST  = "cost"
	LOG_INFO  = "info"
	LOG_WARN  = "warn"
	LOG_ERROR = "error"
	LOG_TRACE = "trace"
	LOG_DEBUG = "debug"
)
View Source
const (
	RENDER_VOID     = "_void"
	RENDER_OUTPUT   = "_output"
	RENDER_RESULT   = "_result"
	RENDER_QRCODE   = "_qrcode"
	RENDER_TEMPLATE = "_template"
	RENDER_DOWNLOAD = "_download"
)
View Source
const (
	EXPORT_LABEL = "lab"
	EXPORT_GROUP = "grp"
	FIELD_RELOAD = "field.reload"
	FIELD_DETAIL = "field.detail"
)

Variables

View Source
var ErrNameExists = "name already exists:"
View Source
var ErrNotAuth = "not auth: "
View Source
var ErrNotFound = "not found: "
View Source
var ErrWarn = "warn: "
View Source
var Index = &Context{Name: "ice", Help: "冰山模块",
	Caches: map[string]*Cache{
		CTX_FOLLOW: {Value: ""},
		CTX_STREAM: {Value: "shy"},
		CTX_STATUS: {Value: "begin"},
	},
	Configs: map[string]*Config{
		"help": {Value: map[string]interface{}{
			"index": []interface{}{
				"^_^      欢迎使用冰山框架       ^_^",
				"^_^  Welcome to Icebergs world  ^_^",
				"",
				"Meet: shylinuxc@gmail.com",
				"More: https://shylinux.com",
				"More: https://github.com/shylinux/icebergs",
				"",
			},
		}},
		"task": {Value: kit.Dict(
			kit.MDB_STORE, "var/data",
			kit.MDB_LIMIT, "110",
			kit.MDB_LEAST, "100",
		)},
	},
	Commands: map[string]*Command{
		CTX_INIT: {Hand: func(m *Message, c *Context, cmd string, arg ...string) {
			defer m.Cost("_init ice")
			m.Travel(func(p *Context, c *Context) {
				if cmd, ok := c.Commands[CTX_INIT]; ok && p != nil {
					c.cmd(m.Spawns(c), cmd, CTX_INIT, arg...)
				}
			})
		}},
		"init": {Name: "init", Help: "启动", Hand: func(m *Message, c *Context, cmd string, arg ...string) {
			m.root.Cmd(CTX_INIT)

			m.target.root.wg = &sync.WaitGroup{}
			for _, k := range kit.Split(kit.Select("gdb,log,ssh,ctx", os.Getenv("ctx_mod"))) {
				m.Start(k)
			}

			m.Cmd("ssh.source", "etc/init.shy", "init.shy", "启动配置")
			m.Cmdy(arg)
		}},
		"help": {Name: "help", Help: "帮助", Hand: func(m *Message, c *Context, cmd string, arg ...string) {
			m.Echo(strings.Join(kit.Simple(m.Confv("help", "index")), "\n"))
		}},
		"name": {Name: "name", Help: "命名", Hand: func(m *Message, c *Context, cmd string, arg ...string) {
			for k, v := range names {
				m.Push("key", k)
				switch v := v.(type) {
				case *Context:
					m.Push("value", v.Name)
				default:
					m.Push("value", "")
				}
			}
			m.Sort("key")
		}},
		"exit": {Name: "exit", Help: "结束", Hand: func(m *Message, c *Context, cmd string, arg ...string) {
			m.root.target.server.(*Frame).code = kit.Int(kit.Select("0", arg, 0))
			m.Cmd("ssh.source", "etc/exit.shy", "exit.shy", "退出配置")

			m.root.Cmd(CTX_EXIT)
		}},
		CTX_EXIT: {Hand: func(m *Message, c *Context, cmd string, arg ...string) {
			defer m.Cost(CTX_EXIT)
			m.root.Travel(func(p *Context, c *Context) {
				if cmd, ok := c.Commands[CTX_EXIT]; ok && p != nil {
					m.TryCatch(m.Spawns(c), true, func(msg *Message) {
						c.cmd(msg, cmd, CTX_EXIT, arg...)
					})
				}
			})
			wait <- true
		}},
	},
}
View Source
var Log func(*Message, string, string)
View Source
var Loop func()
View Source
var Pulse = &Message{
	time: time.Now(), code: 0,
	meta: map[string][]string{},
	data: map[string]interface{}{},

	source: Index, target: Index, Hand: true,
	messages: []*Message{}, message: nil, root: nil,
}

Functions

func Name added in v0.2.3

func Name(name string, value interface{}) string

func Run

func Run(arg ...string) string

Types

type Action added in v0.2.3

type Action struct {
	Name string
	Help string
	Hand func(m *Message, arg ...string)
}

type Cache

type Cache struct {
	Name  string
	Help  string
	Value string
}

type Command

type Command struct {
	Name   interface{} // string []string
	Help   interface{} // string []string
	List   []interface{}
	Meta   map[string]interface{}
	Hand   func(m *Message, c *Context, key string, arg ...string)
	Action map[string]*Action
}

type Config

type Config struct {
	Name  string
	Help  string
	Value interface{}
}

type Context

type Context struct {
	Name string
	Help interface{} // string []string
	Test interface{} // string []string

	Caches   map[string]*Cache
	Configs  map[string]*Config
	Commands map[string]*Command
	// contains filtered or unexported fields
}

func (*Context) Begin

func (c *Context) Begin(m *Message, arg ...string) *Context

func (*Context) Cap

func (c *Context) Cap(key string, arg ...interface{}) string

func (*Context) Close

func (c *Context) Close(m *Message, arg ...string) bool

func (*Context) Cmd added in v0.2.3

func (c *Context) Cmd(m *Message, cmd string, key string, arg ...string) *Message

func (*Context) ID

func (c *Context) ID() int32

func (*Context) Merge added in v0.2.3

func (c *Context) Merge(s *Context, x Server) *Context

func (*Context) Register

func (c *Context) Register(s *Context, x Server, name ...string) *Context

func (*Context) Server

func (c *Context) Server() Server

func (*Context) Spawn added in v0.0.18

func (c *Context) Spawn(m *Message, name string, help string, arg ...string) *Context

func (*Context) Start

func (c *Context) Start(m *Message, arg ...string) bool

type Error added in v0.2.3

type Error struct {
	Arg      []interface{}
	FileLine string
}

func NewError added in v0.2.3

func NewError(n int, arg ...interface{}) *Error

func (*Error) Error added in v0.2.3

func (e *Error) Error() string

type Frame

type Frame struct {
	// contains filtered or unexported fields
}

func (*Frame) Begin

func (f *Frame) Begin(m *Message, arg ...string) Server

func (*Frame) Close

func (f *Frame) Close(m *Message, arg ...string) bool

func (*Frame) Spawn

func (f *Frame) Spawn(m *Message, c *Context, arg ...string) Server

func (*Frame) Start

func (f *Frame) Start(m *Message, arg ...string) bool

type Message

type Message struct {
	Hand bool

	W http.ResponseWriter
	R *http.Request
	O io.Writer
	I io.Reader
	// contains filtered or unexported fields
}

func (*Message) Add

func (m *Message) Add(key string, arg ...string) *Message

func (*Message) AddCmd added in v0.2.1

func (m *Message) AddCmd(cmd *Command) string

func (*Message) Append

func (m *Message) Append(key string, arg ...interface{}) string

func (*Message) Appendv

func (m *Message) Appendv(key string, arg ...interface{}) []string

func (*Message) Assert

func (m *Message) Assert(arg interface{}) bool

func (*Message) Back

func (m *Message) Back(res *Message) *Message

func (*Message) CSV added in v0.0.18

func (m *Message) CSV(text string, head ...string) *Message

func (*Message) Call

func (m *Message) Call(sync bool, cb func(*Message) *Message) *Message

func (*Message) Cap

func (m *Message) Cap(arg ...interface{}) string

func (*Message) Capv

func (m *Message) Capv(arg ...interface{}) interface{}

func (*Message) Cmd

func (m *Message) Cmd(arg ...interface{}) *Message

func (*Message) Cmdx

func (m *Message) Cmdx(arg ...interface{}) string

func (*Message) Cmdy

func (m *Message) Cmdy(arg ...interface{}) *Message

func (*Message) Conf

func (m *Message) Conf(arg ...interface{}) string

func (*Message) Confi

func (m *Message) Confi(arg ...interface{}) int

func (*Message) Confm

func (m *Message) Confm(key string, chain interface{}, cbs ...interface{}) map[string]interface{}

func (*Message) Confv

func (m *Message) Confv(arg ...interface{}) (val interface{})

func (*Message) Copy

func (m *Message) Copy(msg *Message, arg ...string) *Message

func (*Message) Cost

func (m *Message) Cost(str string, arg ...interface{}) *Message

func (*Message) Debug added in v0.2.3

func (m *Message) Debug(str string, arg ...interface{})

func (*Message) Detail

func (m *Message) Detail(arg ...interface{}) string

func (*Message) Detailv

func (m *Message) Detailv(arg ...interface{}) []string

func (*Message) Done

func (m *Message) Done() bool

func (*Message) Echo

func (m *Message) Echo(str string, arg ...interface{}) *Message

func (*Message) Error

func (m *Message) Error(err bool, str string, arg ...interface{}) bool

func (*Message) Event added in v0.0.4

func (m *Message) Event(key string, arg ...string) *Message

func (*Message) Format

func (m *Message) Format(key interface{}) string

func (*Message) Formats

func (m *Message) Formats(key string) string

func (*Message) Gos

func (m *Message) Gos(msg *Message, cb func(*Message)) *Message

func (*Message) Grow

func (m *Message) Grow(key string, chain interface{}, data interface{}) int

func (*Message) Grows

func (m *Message) Grows(key string, chain interface{}, match string, value string, cb interface{}) map[string]interface{}

func (*Message) Hold added in v0.0.18

func (m *Message) Hold(n int) *Message

func (*Message) Info

func (m *Message) Info(str string, arg ...interface{}) *Message

func (*Message) Load added in v0.0.18

func (m *Message) Load(arg ...string) *Message

func (*Message) Log

func (m *Message) Log(level string, str string, arg ...interface{}) *Message

func (*Message) Log_AUTH added in v0.2.3

func (m *Message) Log_AUTH(arg ...interface{}) *Message

func (*Message) Log_CONF added in v0.2.3

func (m *Message) Log_CONF(arg ...interface{}) *Message

func (*Message) Log_CREATE added in v0.2.3

func (m *Message) Log_CREATE(arg ...interface{}) *Message

func (*Message) Log_DELETE added in v0.2.3

func (m *Message) Log_DELETE(arg ...interface{}) *Message

func (*Message) Log_EXPORT added in v0.2.3

func (m *Message) Log_EXPORT(arg ...interface{}) *Message

func (*Message) Log_IMPORT added in v0.2.3

func (m *Message) Log_IMPORT(arg ...interface{}) *Message

func (*Message) Log_INSERT added in v0.2.3

func (m *Message) Log_INSERT(arg ...interface{}) *Message

func (*Message) Log_MODIFY added in v0.2.3

func (m *Message) Log_MODIFY(arg ...interface{}) *Message

func (*Message) Log_REMOVE added in v0.2.3

func (m *Message) Log_REMOVE(arg ...interface{}) *Message

func (*Message) Log_SELECT added in v0.2.3

func (m *Message) Log_SELECT(arg ...interface{}) *Message

func (*Message) Logs added in v0.1.21

func (m *Message) Logs(level string, arg ...interface{}) *Message

func (*Message) Option

func (m *Message) Option(key string, arg ...interface{}) string

func (*Message) Options

func (m *Message) Options(key string, arg ...interface{}) bool

func (*Message) Optionv

func (m *Message) Optionv(key string, arg ...interface{}) interface{}

func (*Message) Parse added in v0.0.18

func (m *Message) Parse(meta string, key string, arg ...string) *Message

func (*Message) Prefix added in v0.0.18

func (m *Message) Prefix(arg ...string) string

func (*Message) Push

func (m *Message) Push(key string, value interface{}, arg ...interface{}) *Message

func (*Message) PushAction added in v0.2.4

func (m *Message) PushAction(list ...interface{})

func (*Message) PushDetail added in v0.2.4

func (m *Message) PushDetail(value interface{}, arg ...interface{}) *Message

func (*Message) Render

func (m *Message) Render(cmd string, args ...interface{}) *Message

func (*Message) Result

func (m *Message) Result(arg ...interface{}) string

func (*Message) Resultv

func (m *Message) Resultv(arg ...interface{}) []string

func (*Message) Rich

func (m *Message) Rich(key string, chain interface{}, data interface{}) string

func (*Message) Richs

func (m *Message) Richs(key string, chain interface{}, raw interface{}, cb interface{}) (res map[string]interface{})

func (*Message) Right added in v0.0.4

func (m *Message) Right(arg ...interface{}) bool

func (*Message) Save added in v0.0.18

func (m *Message) Save(arg ...string) *Message

func (*Message) Search

func (m *Message) Search(key interface{}, cb interface{}) *Message

func (*Message) Set

func (m *Message) Set(key string, arg ...string) *Message

func (*Message) Sleep added in v0.0.18

func (m *Message) Sleep(arg string) *Message

func (*Message) Sort

func (m *Message) Sort(key string, arg ...string) *Message

func (*Message) Source added in v0.0.18

func (m *Message) Source() *Context

func (*Message) Space added in v0.0.4

func (m *Message) Space(arg interface{}) []string

func (*Message) Spawn

func (m *Message) Spawn(arg ...interface{}) *Message

func (*Message) Spawns

func (m *Message) Spawns(arg ...interface{}) *Message

func (*Message) Split

func (m *Message) Split(str string, field string, space string, enter string) *Message

func (*Message) Start

func (m *Message) Start(key string, arg ...string) *Message

func (*Message) Starts added in v0.0.18

func (m *Message) Starts(name string, help string, arg ...string) *Message

func (*Message) Table

func (m *Message) Table(cbs ...func(index int, value map[string]string, head []string)) *Message

func (*Message) Target

func (m *Message) Target() *Context

func (*Message) Time

func (m *Message) Time(args ...interface{}) string

func (*Message) Travel

func (m *Message) Travel(cb interface{}) *Message

func (*Message) TryCatch

func (m *Message) TryCatch(msg *Message, safe bool, hand ...func(msg *Message)) *Message

func (*Message) Warn

func (m *Message) Warn(err bool, arg ...interface{}) bool

func (*Message) Watch added in v0.0.4

func (m *Message) Watch(key string, arg ...string) *Message

type Server

type Server interface {
	Spawn(m *Message, c *Context, arg ...string) Server
	Begin(m *Message, arg ...string) Server
	Start(m *Message, arg ...string) bool
	Close(m *Message, arg ...string) bool
}

Directories

Path Synopsis
aaa
cli
ctx
gdb
lex
log
mdb
nfs
ssh
tcp
web
yac
git
idc
md
mp
pi
vim
wx
zsh

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL