-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotification.go
46 lines (40 loc) · 1.08 KB
/
notification.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package notigo
import (
"os"
)
// A Notification is a simple struct that group a title and content.
// Depending on the OS your are using, the length of the authorized content may vary.
// Sending more 1000 characters per Notification may be problematic.
type Notification struct {
Title string `json:"value1"`
Message string `json:"value2"`
}
// Create a Notification.
// title and message are self-explanatory.
// If the title of the Notification is empty, NewMessage is called.
func NewNotification(title, message string) Notification {
if title == "" {
return NewMessage(message)
} else {
return Notification{
Title: title,
Message: message,
}
}
}
// Create a new Notification with a specified content.
// message is the content of the Notification.
// This method use the hostname as title or "notigo" if the hostname could not be determined.
func NewMessage(message string) Notification {
var title string
hostname, err := os.Hostname()
if err != nil {
title = "Notigo"
} else {
title = hostname
}
return Notification{
Title: title,
Message: message,
}
}