Documentation
¶
Index ¶
- func ReadMessage(m *Message, rd io.Reader) (err error)
- func WriteMessage(m *Message, w io.Writer) (err error)
- type Conn
- type ConnErrHandler
- type ConnHandler
- type ConnectOption
- type ConnectOptions
- type CustomDialer
- type Message
- func (m *Message) AttrString(name string) string
- func (m *Message) Error() error
- func (m *Message) Format() string
- func (m *Message) Message() string
- func (m *Message) Read(r *bufio.Reader) (err error)
- func (m *Message) SetAttr(name string, val interface{})
- func (m *Message) Success() bool
- func (m *Message) Write(w io.Writer) (err error)
- type MessageType
- type RequestOption
- type SubscribeFunc
- type SubscribeOption
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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
}
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 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 ¶
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 MustConvertToMessage ¶
func MustConvertToMessage(in interface{}) (msg *Message)
func (*Message) AttrString ¶
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 ¶
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
Source Files
¶
Click to show internal directories.
Click to hide internal directories.