webhook

package
v0.0.0-...-45ae43d Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2018 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyURL     = errors.New("URL must not empty")
	ErrEmptyChannel = errors.New("Channel must not empty")
)

Functions

This section is empty.

Types

type Attachment

type Attachment struct {
	// Required text summary of the attachment that is shown by clients that understand attachments
	// but choose not to show them.
	Fallback string `json:"fallback"`
	// Optional text that should appear within the attachment.
	Text string `json:"text"`
	// Optional text that should appear above the formatted data.
	Pretext string `json:"pretext"`
	// Can either be one of 'good', 'warning', 'danger', or any hex color code.
	Color  string   `json:"color"`
	Fields []*Field `json:"fields"`
}

Attachment contains message formatting info.

type Client

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

Client keeps config and underlying http client. store config value not pointer for immutability.

func New

func New(c Config) (*Client, error)

New return Client by provided configuration. if it is not given, use default one

func (*Client) Send

func (c *Client) Send(msg string) error

func (*Client) SendPayload

func (c *Client) SendPayload(p *Payload) (err error)

type Config

type Config struct {
	// WebhookURL
	URL string
	// Channel to which post messages
	Channel string
	// Username by whom message is posted
	Username string
	// Emoji representing user
	IconEmoji string
	// Timeout used by http.Client
	Timeout time.Duration
	// flag whether dump response
	Dump bool
}

func (*Config) SetDefualts

func (cfg *Config) SetDefualts()

type Field

type Field struct {
	// Required Field Title.
	Title string `json:"title"`
	// Text value of the field.
	Value string `json:"value"`
	// Optional flag indicating whether the `value` is short enough to be displayed
	// side-by-side with other values.
	Short bool `json:"short"`
}

Field which is used in Attachment is displayed in message table.

type Payload

type Payload struct {
	Text        string        `json:"text"`
	Channel     string        `json:"channel"`
	Username    string        `json:"username,omitempty"`
	IconEmoji   string        `json:"icon_emoji,omitempty"`
	Attachments []*Attachment `json:"attachments,omitempty"`
}

Payload represent POST request body. it is intended to encode json.

Jump to

Keyboard shortcuts

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