types

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2021 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package types defines common types used in package notify, model and drivers

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	// Creates a new Client using current settings and different context. The
	// context is used with http.NewRequestWithContext to create *http.Request.
	With(ctx context.Context) (ret Client)

	// maps api endpoints to function
	Send(id string, driver string, ep string, payload interface{}) (err error)
	SendOnce(id string, driver string, ep string, payload interface{}) (err error)
	Resend(id string) (err error)
	Result(id string) (ret []byte, err error)
	Status(id string) (ret Status, err error)
	Detail(id string) (ret Detail, err error)
	Delete(id string) (err error)
	Clear(before time.Time) (err error)
	ForceClear(before time.Time) (err error)
}

Client defines golang client to call notify.APIServer

func NewClient

func NewClient(server string, hc *http.Client) (ret Client)

NewClient creates a Client

server is address of the server in "http(s)://example.com:1234" format (no path)

type Detail

type Detail struct {
	Driver   string `json:"type"`
	Endpoint string `json:"endpoint"`
	Content  []byte `json:"content"`
	Response []byte `json:"response"`
	Status
}

Detail defines response type of /detail

type Driver

type Driver interface {
	// driver type, 3rd party drivers *SHOULD* use go import path format like
	// github.com/some_org/some_proj/DRIVER_NAME
	Type() string
	// send the notification
	Send(ep string, content []byte) (resp []byte, err error)
	// check the payload format. content is in json format
	Verify(content []byte) (err error)
	// check endpoint format.
	CheckEP(ep string) (err error)
}

Driver defines the interface a driver must implement

type Params

type Params struct {
	// notification ID. It has to be unique as used as primary key in DB.
	ID string `json:"id"`
	// driver type
	Driver string `json:"type"`
	// endpoint to recieve notification. see docs of the driver for detail
	Endpoint string `json:"endpoint"`
	// driver specific parameters. see docs of the driver for detail
	Payload json.RawMessage `json:"payload"`
}

Params defines required parameters of API endpoint /send and /sendOnce

type Scheduler

type Scheduler func(driver, notifyID string, lastExec time.Time, tried uint32) (next time.Time, stop bool)

Scheduler is an user-defined function to determine when to resend notification

type State

type State int

State denotes the processing state of a notification

const (
	PENDING State = iota // notification is waiting to (re)send
	SUCCESS              // notification is sent to the endpoint
	FAILED               // notification is failed to send after all
)

type Status

type Status struct {
	CreateAt int64  `json:"create_at"`
	NextAt   int64  `json:"next_at"`
	Tried    uint32 `json:"tried"`
	State    State  `json:"state"`
}

Status defines response type of /status

Jump to

Keyboard shortcuts

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