atmt

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2022 License: BSD-2-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultServeMux = NewServeMux()

Functions

func BadRequest added in v0.4.0

func BadRequest(resp *Message)

func Error added in v0.3.0

func Error(resp *Message, code StatusCode)

func InternalServerError added in v0.4.0

func InternalServerError(resp *Message)

func Push added in v0.3.0

func Push(url string, msg Message) (err error)

func PushCtx added in v0.3.0

func PushCtx(ctx context.Context, url string, msg Message) (err error)

func StartSrv added in v0.3.0

func StartSrv(srv *Server)

func StopSrv added in v0.3.0

func StopSrv(srv *Server)

Types

type Content added in v0.3.0

type Content []Paragraph

func FormatContent added in v0.3.0

func FormatContent(v ...any) (content Content)

func (*Content) Plaintext added in v0.3.0

func (c *Content) Plaintext() string

func (Content) String added in v0.3.0

func (c Content) String() string

type DataPush added in v0.3.0

type DataPush struct {
	MessageID MessageID `json:"message_id"`
	Sender    string    `json:"sender"`
}

type DataRequest added in v0.3.0

type DataRequest[Action ~uint8] struct {
	Action Action          `json:"action"`
	Args   json.RawMessage `json:"args"`
}

type DataRequestBuilder added in v0.3.0

type DataRequestBuilder[Action ~uint8, Args any] struct {
	Action Action `json:"action"`
	Args   Args   `json:"args"`
}

type DataResponse added in v0.3.0

type DataResponse struct {
	StatusCode StatusCode      `json:"status_code"`
	Values     json.RawMessage `json:"values"`
}

type DataResponseBuilder added in v0.3.0

type DataResponseBuilder[Values any] struct {
	StatusCode StatusCode `json:"status_code"`
	Values     Values     `json:"values"`
}

type Handler

type Handler interface {
	ServeMessage(resp *Message, post Message)
}

func MultiHandler added in v0.4.0

func MultiHandler(handlers []Handler) Handler

type HandlerFunc

type HandlerFunc func(*Message, Message)

func (HandlerFunc) ServeMessage added in v0.3.0

func (h HandlerFunc) ServeMessage(resp *Message, post Message)

type Matcher

type Matcher struct {
	Match     func(msg Message) bool
	Priority  int
	Temporary bool
}

type Message added in v0.3.0

type Message struct {
	Type    MessageType     `json:"type"`
	Data    json.RawMessage `json:"data"`
	Content Content         `json:"content"`
}

func SendMessage added in v0.3.0

func SendMessage(url string, msg Message) (resp Message, err error)

func SendMessageCtx added in v0.3.0

func SendMessageCtx(ctx context.Context, url string, msg Message) (resp Message, err error)

type MessageBuilder added in v0.3.0

type MessageBuilder[Data any] struct {
	Type    MessageType `json:"type"`
	Data    Data        `json:"data"`
	Content []Paragraph `json:"content"`
}

func (*MessageBuilder[Data]) Message added in v0.3.0

func (b *MessageBuilder[Data]) Message() (msg Message, err error)

func (*MessageBuilder[Data]) Write added in v0.3.0

func (b *MessageBuilder[Data]) Write(w *Message) (err error)

type MessageID added in v0.3.0

type MessageID = primitive.ObjectID

type MessageType added in v0.3.0

type MessageType uint8
const (
	MessagePush MessageType = iota + 1
	MessageRequest
	MessageResponse
)

func (MessageType) String added in v0.3.0

func (typ MessageType) String() (str string)

type Paragraph added in v0.3.0

type Paragraph struct {
	Type ParagraphType `json:"type" bson:"type,omitempty"`
	Text string        `json:"text" bson:"text,omitempty"`
	Name string        `json:"name" bson:"name,omitempty"`
	Ref  string        `json:"ref" bson:"ref,omitempty"`
}

func Image added in v0.3.0

func Image(name, ref string) Paragraph

func Record added in v0.3.0

func Record(name, ref string) Paragraph

func Text added in v0.3.0

func Text(txt string) Paragraph

func Video added in v0.3.0

func Video(name, ref string) Paragraph

type ParagraphType added in v0.3.0

type ParagraphType uint8
const (
	ParagraphText ParagraphType = iota + 1
	ParagraphImage
	ParagraphRecord
	ParagraphVideo
)

type PostError added in v0.3.0

type PostError interface {
	error
	StatusCode() StatusCode
}

type ServeMux

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

func NewServeMux

func NewServeMux() *ServeMux

func (*ServeMux) Handle

func (mux *ServeMux) Handle(m Matcher, h Handler)

func (*ServeMux) Handler

func (mux *ServeMux) Handler(msg Message) (m Matcher, h Handler)

func (*ServeMux) Matcher added in v0.3.0

func (mux *ServeMux) Matcher() Matcher

func (*ServeMux) ServeMessage added in v0.3.0

func (mux *ServeMux) ServeMessage(resp *Message, post Message)

type Server

type Server struct {
	Addr    string
	Handler Handler
	// contains filtered or unexported fields
}

func (*Server) ListenAndServe

func (srv *Server) ListenAndServe() (err error)

func (*Server) Shutdown

func (srv *Server) Shutdown(ctx context.Context) (err error)

type StatusCode added in v0.3.0

type StatusCode uint8
const (
	StatusOK StatusCode = iota + 1
	StatusBadRequest
	StatusUnauthorized
	StatusInternalServerError
)

func (StatusCode) String added in v0.3.0

func (c StatusCode) String() string

func (StatusCode) Text added in v0.3.0

func (c StatusCode) Text() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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