bark

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2025 License: MIT Imports: 11 Imported by: 0

README

go-bark

bark 推送 golang sdk,支持加密传输

Example

go get github.com/gaoyaxuan/go-bark@latest

package main

import "github.com/gaoyaxuan/go-bark"

func main() {
	err := bark.Push(&bark.Options{
		Msg:   "test",
		Token: "xxxxxxxxxxxxxxxxxxxxxx",
	})
	if err != nil {
		panic(err)
	}

	err = bark.Push(&bark.Options{
		Client: bark.Client{ServerURL: "https://aaa.bbbbb.ccc"},
		Msg:    "test",
		Token:  "xxxxxxxxxxxxxxxxxxxxxx",
		Enc: &bark.EncOpt{
			Mode: bark.CBC,
			Key:  "1234567890abcdef",
			Iv:   "1111111111111111",
		},
	})
	if err != nil {
		panic(err)
	}

	// Client
	c := bark.New("https://aaa.bbbbb.ccc")
	err = c.Push(&bark.Options{
		Msg:   "test",
		Token: "xxxxxxxxxxxxxxxxxxxxxx",
	})
	if err != nil {
		panic(err)
	}
}

Options

type Client struct {
	// 服务器URL
	Domain string
}   

type Options struct {
    Client `json:"-"`
    
    // token (必填)
    Token string `json:"-"`
    // 推送标题
    Title string `json:"title"`
    // 推送内容 (必填)
    Msg string `json:"body,omitempty"`
    // 消息分组
    Group string `json:"group,omitempty"`
    // 点击推送时,跳转的URL,支持URL Scheme 和 Universal Link
    URL string `json:"url,omitempty"`
    // 推送中断级别
    Level string `json:"level,omitempty"`
    // 指定复制的内容
    Copy *string `json:"copy,omitempty"`
    // 自动复制
    AutoCopy *bool `json:"autoCopy,omitempty"`
    // 推送铃声
    Sound string `json:"sound,omitempty"`
    // 自定义图标,传入URL
    Icon string `json:"icon,omitempty"`
    // 推送角标
    Badge *int `json:"badge,omitempty"`
    // 传 1 保存推送,传其他的不保存推送,不传按APP内设置来决定是否保存。
    IsArchive int `json:"isArchive,omitempty,string"`
    //持续响铃 1 持续响铃30秒
    Call int `json:"call,omitempty,string"`
    //level 为 critical时设置声音大小,取值0-10,不传默认为5
    Volume *int `json:"volume,omitempty,string"`
    // 加密传输
    Enc *EncOpt `json:"-"`
}

type EncOpt struct {
	Mode EncMode
	Key  string
	Iv   string
}

Documentation

Index

Constants

View Source
const DefaultDomain = "api.day.app"
View Source
const DefaultURL = "https://" + DefaultDomain

Variables

View Source
var DefaultClient = New(DefaultURL)

Functions

This section is empty.

Types

type Client

type Client struct {
	ServerURL  string
	HTTPClient *http.Client
}

func New

func New(serverURL string) *Client

func (*Client) Push

func (c *Client) Push(o *Options) error

type EncMode

type EncMode string

EncMode 加密模式 (新增 GCM)

const (
	EncModeCBC EncMode = "CBC"
	EncModeECB EncMode = "ECB"
	EncModeGCM EncMode = "GCM"
)

type EncOpt

type EncOpt struct {
	Mode EncMode
	Key  string
	// CBC 模式为 IV (初始化向量),GCM 模式为 Nonce (随机数)
	Iv string
}

EncOpt 加密选项

type Options

type Options struct {
	DeviceKey  string   `json:"device_key,omitempty"`
	DeviceKeys []string `json:"device_keys,omitempty"`
	Title      string   `json:"title,omitempty"`
	Body       string   `json:"body,omitempty"`
	Markdown   string   `json:"markdown,omitempty"`
	Subtitle   string   `json:"subtitle,omitempty"`
	Group      string   `json:"group,omitempty"`
	URL        string   `json:"url,omitempty"`
	Icon       string   `json:"icon,omitempty"`
	Sound      string   `json:"sound,omitempty"`
	Badge      *int     `json:"badge,omitempty"`
	Level      string   `json:"level,omitempty"`
	Copy       string   `json:"copy,omitempty"`
	AutoCopy   string   `json:"autoCopy,omitempty"`
	IsArchive  *int     `json:"isArchive,omitempty"`
	Call       string   `json:"call,omitempty"`
	Volume     *int     `json:"volume,omitempty"`
	Action     string   `json:"action,omitempty"`
	ID         string   `json:"id,omitempty"`
	Delete     string   `json:"delete,omitempty"`

	// --- 加密设置 (不参与 JSON 序列化) ---
	Enc *EncOpt `json:"-"`
}

Options 推送参数结构体 (保持不变)

func (*Options) Validate added in v1.1.0

func (o *Options) Validate() error

Validate 检查核心参数和加密参数的合法性

Jump to

Keyboard shortcuts

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