ami

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadMessage

func ReadMessage(m *Message, rd io.Reader) (err error)

func WriteMessage

func WriteMessage(m *Message, w io.Writer) (err error)

Types

type Conn

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

func Connect

func Connect(addr string, opts ...ConnectOption) (conn *Conn, err error)
Example
package main

import (
	"context"
	"fmt"
	"github.com/ezdev128/astgo/ami"
)

func main() {
	boot := make(chan *ami.Message, 1)

	conn, err := ami.Connect(
		"192.168.1.1:5038",
		ami.WithAuth("admin", "admin"), // AMI auth
		// add predefined subscriber
		ami.WithSubscribe(ami.SubscribeFullyBootedChanOnce(boot)),
		ami.WithSubscribe(func(ctx context.Context, msg *ami.Message) bool {
			fmt.Println(msg.Format()) // log everything
			return true               // keep subscribe
		}, ami.SubscribeSend(), // subscribe send message - default recv only
		))
	if err != nil {
		panic(err)
	}
	<-boot
	// AMI now FullyBooted
	_ = conn
}
Output:

func (*Conn) Close

func (c *Conn) Close() error

func (*Conn) Request

func (c *Conn) Request(r interface{}, opts ...RequestOption) (resp *Message, err error)

func (*Conn) Subscribe

func (c *Conn) Subscribe(cb SubscribeFunc, opts ...SubscribeOption) (func(), error)

type ConnErrHandler

type ConnErrHandler func(*Conn, error)

type ConnHandler

type ConnHandler func(*Conn)

type ConnectOption

type ConnectOption func(c *ConnectOptions) error

func WithAuth

func WithAuth(username string, secret string) ConnectOption

func WithSubscribe

func WithSubscribe(cb SubscribeFunc, opts ...SubscribeOption) ConnectOption

type ConnectOptions

type ConnectOptions struct {
	Context        context.Context
	Timeout        time.Duration
	AllowReconnect bool
	Username       string // login username
	Secret         string // login secret
	Events         string // subscribe to events
	Logger         *zap.Logger
	Dialer         CustomDialer
	OnConnectErr   ConnErrHandler
	OnConnected    ConnHandler
	// contains filtered or unexported fields
}

type CustomDialer

type CustomDialer interface {
	Dial(network, address string) (net.Conn, error)
}

CustomDialer can be used to specify any dialer, not necessarily a *net.Dialer.

type Message

type Message struct {
	Type       MessageType // type of message
	Name       string      // name of message
	Attributes map[string]any
}

func ConvertToMessage

func ConvertToMessage(in interface{}) (msg *Message, err error)

func MustConvertToMessage

func MustConvertToMessage(in interface{}) (msg *Message)

func (*Message) AttrString

func (m *Message) AttrString(name string) string

func (*Message) Error

func (m *Message) Error() error

func (*Message) Format

func (m *Message) Format() string

func (*Message) Message

func (m *Message) Message() string

func (*Message) Read

func (m *Message) Read(r *bufio.Reader) (err error)

func (*Message) SetAttr

func (m *Message) SetAttr(name string, val interface{})

func (*Message) Success

func (m *Message) Success() bool

func (*Message) Write

func (m *Message) Write(w io.Writer) (err error)

type MessageType

type MessageType string
const (
	MessageTypeAction   MessageType = "Action"
	MessageTypeEvent    MessageType = "Event"
	MessageTypeResponse MessageType = "Response"
)

type RequestOption

type RequestOption func(o *requestOptions) error

func RequestResponseCallback

func RequestResponseCallback(cb func(ctx context.Context, msg *Message, err error)) RequestOption

RequestResponseCallback will case Conn.Request run async, will not time out

func RequestTimeout

func RequestTimeout(d time.Duration) RequestOption

type SubscribeFunc

type SubscribeFunc func(ctx context.Context, message *Message) bool

func SubscribeChan

func SubscribeChan(c chan *Message, names ...string) SubscribeFunc

func SubscribeFullyBootedChanOnce

func SubscribeFullyBootedChanOnce(c chan *Message) SubscribeFunc

type SubscribeOption

type SubscribeOption func(o *subscribe) error

func SubscribeSend

func SubscribeSend() SubscribeOption

func SubscribeSetContext

func SubscribeSetContext(ctx context.Context) SubscribeOption

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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