agent

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2019 License: MIT Imports: 6 Imported by: 0

README

Readme

Go Report Card api documentation

Introduction

This project is based off emitter-actor.

Basic Usage

Requirements

Emitter is required for this project to work.

Keys must have read and write access. The target channel for the keys must end with /#/, ex: actor/#/, for this project to work.

Installation
go get broadcastle.co/code/emitter-agent
Server
package main

import (
    "fmt"

    agent "broadcastle.co/code/emitter-agent"
)

type data struct {
    URL string `json:"url"`
}

func main() {

    // Don't actually ignore errors.

    logs := logrus.New()

    config := agent.UseEmitter("127.0.0.1", "8090", "key-generate-from-keygen", "actor", logs, false)

    server, _ := agent.New(config)

    dt, _ := agent.PrepSender("server", "ping", data{"https://google.com"})

    server.Send(dt)

}
Client
package main

import (
    "fmt"
    "json"
    "net/http"

    agent "broadcastle.co/code/emitter-agent"
)

type data struct {
    URL string `json:"url"`
}

func main() {

    // Don't actually ignore errors.

    logs := logrus.New()

    config := agent.UseEmitter("127.0.0.1", "8090", "key-generate-from-keygen", "actor", logs, false)

    client, _ := agent.New(config)

    client.Do("ping", func(_ agent.Client, content string) {
    
        var d data
        
        json.Unmarshal([]byte(content), &d)

        res, _ := http.Get(d.URL)

        if res.StatusCode == 200 {
            fmt.Println("success")
        } else {
            fmt.Println("failure")
        }

    })

}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	Start() error
	Do(trigger string, action Perform)
	SendRaw(trigger string, data string)
	Send(Sender)
}

Client has the connection that receives instruction.

func New

func New(c Config) (Client, error)

New returns an actor.

type Config

type Config interface {
	Prepare() (Client, error)
}

Config gives options.

func UseEmitter

func UseEmitter(domain string, port int, key, link string, l Logger, debug bool) Config

UseEmitter returns emitter config struct.

type Logger

type Logger interface {
	Debugf(string, ...interface{})
	Errorf(string, ...interface{})
}

Logger allows for information to be given.

type Perform

type Perform = func(from Client, data string)

Perform is the function that occurs.

type Sender

type Sender interface {
	Source() string
	Trigger() string
	Data() string
}

Sender is used to send data to a remote agent.

func PrepSender

func PrepSender(sender, trigger string, data interface{}) (Sender, error)

PrepSender is used to prepare a Sender.

Jump to

Keyboard shortcuts

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