Skip to content

codec在yomo plugin中消费数据的调用方式 #14

@fanweixiao

Description

@fanweixiao

yomo-plugin的对codec数据的消费方式如下:https://github.com/yomorun/yomo-echo-plugin#echogo

package main

import (
  "github.com/yomorun/yomo/pkg/env"
  "github.com/yomorun/yomo/pkg/yomo"
)

func main() {
  endpoint := env.GetString("YOMO_PLUGIN_ENDPOINT", "localhost:4241")
  yomo.RunDev(&EchoPlugin{}, endpoint)
}

// EchoPlugin is a demo for echo
type EchoPlugin struct{}

// Handle data-------->(3) 在这里,value就是payload内容
func (p *EchoPlugin) Handle(value interface{}) (interface{}, error) {
  return value.(string) + "-new", nil
}

// Observed key -------->(1) 在这里,Observed返回该plugin要关注的Key(即Tag,比如0x23这样的SeqID)
func (p EchoPlugin) Observed() string {
  return "name"
}

// Mold describe the struct of `Observed` value-------->(2) 在这里,是使用codec的decode的过程
func (p EchoPlugin) Mold() interface{} {
	return ""
}

// Name this plugin
func (p *EchoPlugin) Name() string {
  return "EchoPlugin"
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions