sendlinuxnotification

package module
v0.0.0-...-a189eda Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2026 License: MIT Imports: 3 Imported by: 0

README

a go lib use libnotify to send linux notification

sample usage

first setup

GOPRIVATE=gitee.com/EEPPEE_admin/send-linux-notification
go get gitee.com/EEPPEE_admin/send-linux-notification

go code to send notification

package main

import (
	"fmt"

	sendlinuxnotificationcgo "gitee.com/EEPPEE_admin/send-linux-notification"
)

func main() {
	// 1. 发送普通信息通知
	if err := sendlinuxnotificationcgo.SendInfo(
		"my-go-app", // 应用标识
		"操作成功",      // 标题
		"这是普通信息通知",  // 内容
	); err != nil {
		fmt.Printf("发送普通通知失败: %v\n", err)
	}

	// 2. 发送错误通知
	if err := sendlinuxnotificationcgo.SendError(
		"my-go-app", // 应用标识
		"操作失败",      // 标题
		"这是错误警告通知",  // 内容
	); err != nil {
		fmt.Printf("发送错误通知失败: %v\n", err)
	}

	// 3. 通用 Send 方法(自定义类型)
	if err := sendlinuxnotificationcgo.Send(
		"my-go-app",
		"自定义通知",
		"通过通用方法发送",
		sendlinuxnotificationcgo.NotificationInfo,
	); err != nil {
		fmt.Printf("发送自定义通知失败: %v\n", err)
	}

	fmt.Println("通知发送完成")
}

idea from xcat

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Send

func Send(appName, title, message string, nType NotificationType) error

Send 发送 Linux 系统通知(对外暴露的 Go API) 参数:

appName: 应用标识(如 "myapp")
title: 通知标题
message: 通知内容
nType: 通知类型(Info/Error)

返回:错误信息(nil 表示成功)

func SendError

func SendError(appName, title, message string) error

SendError 快捷发送错误通知(简化 API)

func SendInfo

func SendInfo(appName, title, message string) error

SendInfo 快捷发送普通信息通知(简化 API)

Types

type NotificationType

type NotificationType int

NotificationType 通知类型(区分普通/错误通知)

const (
	// NotificationInfo 普通信息通知
	NotificationInfo NotificationType = 0
	// NotificationError 错误警告通知
	NotificationError NotificationType = 1
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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