-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathferag_message.go
36 lines (30 loc) · 939 Bytes
/
ferag_message.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
package feragstring
import (
"fmt"
"strings"
)
// FeragMessage is the struct for the "abstract" message.
// It is meant to be embedded into the real message structs.
type FeragMessage struct {
messageStart string
messageEnd string
}
func (fm *FeragMessage) getMessageStart() string {
return fmt.Sprintf("%%%s", fm.messageStart)
}
func (fm *FeragMessage) getMessageEnd() string {
return fmt.Sprintf("%s", fm.messageEnd)
}
// MessageTemplateFunc is a func type for the generating the
// FERAG-formatted message.
type MessageTemplateFunc func(*FeragMessage, string) string
// MessageTemplate returns a MessageTemplateFunc - to be called
// from within the "real" message structs.
func (fm *FeragMessage) MessageTemplate() MessageTemplateFunc {
return func(fm *FeragMessage, s string) string {
message := fm.getMessageStart()
message += s
message += fm.getMessageEnd()
return strings.TrimSpace(message) + linebreak
}
}