message

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2023 License: MIT Imports: 11 Imported by: 0

README

Go Report Card Go Version PkgGoDev

Send notification messages (bark, mail), and support real-time monitoring of configuration file changes

Install

go get github.com/zggsong/message

Usage

touch config.yml

write the following contents to the file

message:
  enabled: true #是否开启发送信息
  type: "bark"  #选择发送信息方式
  bark:
    url: ""
    key: ""
  mail:
    host: ""    #例:smtp.qq.com
    protocol:   #Optional
    port:       #例:587
    username: ""
    password: ""
    from_name: "" #"zgg <zgg@mail.com>"
    to: ""      #分号内空格分开

Bark is an iOS App which allows you to push custom notifications to your iPhone

func main() {
	/*配置初始化*/
	conf, err := message.InitConfig()
	if err != nil {
		log.Fatalf("failed to initialize config: %v", err)
	}
	message.GLO_CONF = conf

	/*测试发送*/
	var s = message.Service{Body: message.Body{
		Title:   "test title",
		Content: "this is content, time is " + time.Now().Format("2006-01-02 15:04:05"),
	}}
	if err = s.Run(); err != nil {
		log.Fatalf("failed to send message: %v", err)
	} else {
		log.Printf("send message successfully...")
	}

	/*监听配置*/
	for {
		_conf := <-message.GLO_CONF_CH
		log.Printf("config changed: %v", _conf)
		message.GLO_CONF = _conf
	}
}

License

Message © zggsong, Follow MIT certificate.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Enabled added in v0.2.0

func Enabled() bool

Types

type Bark added in v0.2.0

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

func (*Bark) Send added in v0.2.0

func (b *Bark) Send(body Body) error

type BarkRequest added in v0.2.0

type BarkRequest struct {
	Body      string `json:"body"`
	DeviceKey string `json:"device_key"`
	Title     string `json:"title"`
	Badge     int    `json:"badge"`
	Category  string `json:"category"`
	Sound     string `json:"sound"`
	Icon      string `json:"icon"`
	Group     string `json:"group"`
	Url       string `json:"url"`
}

BarkRequest @Description: Bark请求

type BarkResponse added in v0.2.0

type BarkResponse struct {
	Code      int    `json:"code"`
	Message   string `json:"message"`
	Timestamp int    `json:"timestamp"`
}

BarkResponse @Description: Bark回复

type Body added in v0.2.0

type Body struct {
	Title   string
	Content string
}

type Config added in v0.2.0

type Config struct {
	MsgEnabled   bool
	MsgType      string
	BarkUrl      string
	BarkKey      string
	MailHost     string
	MailProtocol string
	MailPort     int
	MailUser     string
	MailPwd      string
	MailFromName string
	MailTo       []string
}

Config @Description: 配置

var (
	GLO_CONF_CH chan Config
	GLO_CONF    Config
)

func InitConfig added in v0.2.0

func InitConfig() (Config, error)

InitConfig

@Description: 初始化配置
@return model.Config
@return error

type Mail added in v0.2.0

type Mail struct {
	Host     string
	Protocol string
	Port     int
	Username string
	Password string
	FromName string
	To       []string
}

func (*Mail) Send added in v0.2.0

func (m *Mail) Send(body Body) error

type Message added in v0.2.0

type Message interface {
	Send(body Body) error
}

func GetType added in v0.2.0

func GetType() (Message, error)

type Service

type Service struct {
	Body Body
}

func (Service) Run

func (s Service) Run() error

Jump to

Keyboard shortcuts

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