plugin

module
v0.0.0-...-17a5fe9 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2020 License: MIT

README

TeaWeb插件接口

如何实现一个自己的插件

  1. 新建一个项目,项目结构为:
    demo-plugin/
      src/
        github.com/
            TeaWeb/
                plugin/
                    [https://github.com/TeaWeb/plugin源码]
        main/
            demo.go - 你的插件源文件  
            build.sh - 构建脚本                              
    
  2. main/目录下建一个插件的Go文件,比如命名为demo.go
  3. demo.go中实现
    package main
    
    import (
        "github.com/TeaWeb/plugin/loader"
        "github.com/TeaWeb/plugin/plugins"
    )
    
    func main() {
        demoPlugin := plugins.NewPlugin()
        demoPlugin.Name = "Demo Plugin"
        demoPlugin.Code = "com.example.demo"
        demoPlugin.Developer = "Liu xiangchao"
        demoPlugin.Version = "1.0.0"
        demoPlugin.Date = "2018-10-15"
        demoPlugin.Site = "https://github.com/TeaWeb/build"
        demoPlugin.Description = "这是一个Demo插件"
    
        loader.Start(demoPlugin)
    }	
    
  4. 可以修改demoPlugin,以提供插件的名称、描述等信息,或者实现其他功能;
  5. 使用go build -o demo.tea demo.go编译插件;
  6. 将编译成功后的demo.tea放到TeaWebplugins/目录下,重启TeaWeb后生效。

构建脚本

build.sh

#!/usr/bin/env bash

export GOPATH=`pwd`/../../
export CGO_ENABLED=1

# msgpack
if [ ! -d "${GOPATH}/src/github.com/vmihailenco/msgpack" ]
then
    go get "github.com/vmihailenco/msgpack"
fi

# TeaWeb
if [ ! -d "${GOPATH}/src/github.com/TeaWeb/plugin" ]
then
    go get "github.com/TeaWeb/plugin"
fi

go build -o demo.tea demo.go

代码示例

请见 main/demo.go

安装插件

TeaWeb插件拷贝到plugins/目录下,即可完成安装:

bin/
plugins/
  demo.tea
  ...

安装后,请重启TeaWeb后插件生效,然后在Web界面中的"插件"菜单中可以看到加载成功的插件。

Directories

Path Synopsis
cmd
internal
pkg

Jump to

Keyboard shortcuts

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