Giter Site home page Giter Site logo

plugin's Introduction

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界面中的"插件"菜单中可以看到加载成功的插件。

plugin's People

Contributors

iwind avatar teaweb avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.