mirror of
https://github.com/knadh/listmonk.git
synced 2025-09-12 01:14:50 +08:00
Apply minor Go code fixes (#2219)
- replace deprecated 'strings.Title' with 'cases.Title' - remove unreachable return and fix syntax issue
This commit is contained in:
parent
98934e601e
commit
2abc0a8651
5 changed files with 13 additions and 7 deletions
|
@ -48,5 +48,4 @@ func handleEventStream(c echo.Context) error {
|
|||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -9,6 +9,9 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
"unicode"
|
||||
|
||||
"golang.org/x/text/cases"
|
||||
"golang.org/x/text/language"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -116,7 +119,7 @@ func trimNullBytes(b []byte) string {
|
|||
func titleCase(input string) string {
|
||||
parts := strings.Fields(input)
|
||||
for n, p := range parts {
|
||||
parts[n] = strings.Title(p)
|
||||
parts[n] = cases.Title(language.Und).String(p)
|
||||
}
|
||||
|
||||
return strings.Join(parts, " ")
|
||||
|
|
|
@ -64,11 +64,11 @@ func (c *Captcha) Verify(token string) (error, bool) {
|
|||
}
|
||||
|
||||
var r captchaResp
|
||||
if json.Unmarshal(body, &r); err != nil {
|
||||
if err := json.Unmarshal(body, &r); err != nil {
|
||||
return err, true
|
||||
}
|
||||
|
||||
if r.Success != true {
|
||||
if !r.Success {
|
||||
return fmt.Errorf("captcha failed: %s", strings.Join(r.ErrorCodes, ",")), false
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,8 @@ import (
|
|||
"github.com/Masterminds/sprig/v3"
|
||||
"github.com/knadh/listmonk/internal/i18n"
|
||||
"github.com/knadh/listmonk/models"
|
||||
"golang.org/x/text/cases"
|
||||
"golang.org/x/text/language"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -594,7 +596,7 @@ func (m *Manager) trackLink(url, campUUID, subUUID string) string {
|
|||
// sendNotif sends a notification to registered admin e-mails.
|
||||
func (m *Manager) sendNotif(c *models.Campaign, status, reason string) error {
|
||||
var (
|
||||
subject = fmt.Sprintf("%s: %s", strings.Title(status), c.Name)
|
||||
subject = fmt.Sprintf("%s: %s", cases.Title(language.Und).String(status), c.Name)
|
||||
data = map[string]interface{}{
|
||||
"ID": c.ID,
|
||||
"Name": c.Name,
|
||||
|
|
|
@ -26,6 +26,8 @@ import (
|
|||
"github.com/knadh/listmonk/internal/i18n"
|
||||
"github.com/knadh/listmonk/models"
|
||||
"github.com/lib/pq"
|
||||
"golang.org/x/text/cases"
|
||||
"golang.org/x/text/language"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -246,7 +248,7 @@ func (im *Importer) sendNotif(status string) error {
|
|||
Total: s.Total,
|
||||
}
|
||||
subject = fmt.Sprintf("%s: %s import",
|
||||
strings.Title(status),
|
||||
cases.Title(language.Und).String(status),
|
||||
s.Name)
|
||||
)
|
||||
return im.opt.NotifCB(subject, out)
|
||||
|
@ -648,7 +650,7 @@ func (im *Importer) ValidateFields(s SubReq) (SubReq, error) {
|
|||
|
||||
parts := strings.Fields(strings.ReplaceAll(name, ".", " "))
|
||||
for n, p := range parts {
|
||||
parts[n] = strings.Title(p)
|
||||
parts[n] = cases.Title(language.Und).String(p)
|
||||
}
|
||||
|
||||
s.Name = strings.Join(parts, " ")
|
||||
|
|
Loading…
Add table
Reference in a new issue