82 lines
1.6 KiB
Go
82 lines
1.6 KiB
Go
package mt
|
|
|
|
import (
|
|
"q5"
|
|
"main/constant"
|
|
"fmt"
|
|
)
|
|
|
|
type Mail struct {
|
|
title string
|
|
content string
|
|
}
|
|
|
|
func (this *Mail) GetTitle() string {
|
|
return this.title
|
|
}
|
|
|
|
func (this *Mail) GetContent() string {
|
|
return this.content
|
|
}
|
|
|
|
type MailTable struct {
|
|
nameHash *q5.ConcurrentMap[string, *Mail]
|
|
}
|
|
|
|
func (this *MailTable) IsNoLoad() bool {
|
|
return false
|
|
}
|
|
|
|
func (this *MailTable) Load() {
|
|
this.nameHash = new(q5.ConcurrentMap[string, *Mail])
|
|
this.loadMail(constant.MAIL_HERO_MINT)
|
|
this.loadMail(constant.MAIL_HERO_LOCK)
|
|
this.loadMail(constant.MAIL_HERO_UNLOCK)
|
|
|
|
this.loadMail(constant.MAIL_HERO_MINT)
|
|
this.loadMail(constant.MAIL_HERO_LOCK)
|
|
this.loadMail(constant.MAIL_HERO_UNLOCK)
|
|
}
|
|
|
|
func (this *MailTable) PreInit1() {
|
|
|
|
}
|
|
|
|
func (this *MailTable) ElementsInit(int) {
|
|
|
|
}
|
|
|
|
func (this *MailTable) PostInit1() {
|
|
|
|
}
|
|
|
|
func (this *MailTable) loadMail(mailName string) {
|
|
p := new(Mail)
|
|
tmpStrings := q5.StrSplit(mailName, ".")
|
|
{
|
|
fileName := fmt.Sprintf("../config/mail/%s/%s.title.txt", tmpStrings[0], tmpStrings[1])
|
|
if data, err := q5.LoadFileAsString(fileName); err == nil {
|
|
p.title = data
|
|
} else {
|
|
panic(fmt.Sprintf("load mail title %s error %s", mailName, err))
|
|
}
|
|
}
|
|
{
|
|
fileName := fmt.Sprintf("../config/mail/%s/%s.content.txt", tmpStrings[0], tmpStrings[1])
|
|
if data, err := q5.LoadFileAsString(fileName); err == nil {
|
|
p.content = data
|
|
} else {
|
|
panic(fmt.Sprintf("load mail content %s error %s", mailName, err))
|
|
}
|
|
}
|
|
this.nameHash.Store(mailName, p)
|
|
}
|
|
|
|
func (this *MailTable) GetMailByName(mailName string) *Mail {
|
|
if v, ok := this.nameHash.Load(mailName); ok {
|
|
return *v
|
|
} else {
|
|
return nil
|
|
}
|
|
}
|