feragstring/ferag_message.go

37 lines
939 B
Go
Raw Permalink Normal View History

2020-05-27 21:23:36 +02:00
package feragstring
import (
"fmt"
"strings"
)
2020-05-27 21:23:36 +02:00
// FeragMessage is the struct for the "abstract" message.
// It is meant to be embedded into the real message structs.
2020-05-27 21:23:36 +02:00
type FeragMessage struct {
messageStart string
2020-05-29 14:39:59 +02:00
messageEnd string
2020-05-27 21:23:36 +02:00
}
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.
2020-05-27 21:23:36 +02:00
type MessageTemplateFunc func(*FeragMessage, string) string
// MessageTemplate returns a MessageTemplateFunc - to be called
// from within the "real" message structs.
2020-05-27 21:23:36 +02:00
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
2020-05-27 21:23:36 +02:00
}
}