From a2f04e4d6ebf69e71260c01fca8f4e9c421a53c8 Mon Sep 17 00:00:00 2001 From: Peter Stuifzand Date: Sat, 16 Apr 2022 15:12:58 +0200 Subject: [PATCH] Problem: strings.Title is deprecated Solution: use golang.org/x/text/cases instead --- go.mod | 1 + go.sum | 1 + pkg/rss/rss_1.0.go | 8 ++++++-- pkg/rss/rss_2.0.go | 7 +++++-- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 3aa331e..9ae83be 100644 --- a/go.mod +++ b/go.mod @@ -13,5 +13,6 @@ require ( github.com/pkg/errors v0.9.1 github.com/stretchr/testify v1.7.0 golang.org/x/net v0.0.0-20211013171255-e13a2654a71e + golang.org/x/text v0.3.7 willnorris.com/go/microformats v1.1.0 ) diff --git a/go.sum b/go.sum index 07b746f..ed77444 100644 --- a/go.sum +++ b/go.sum @@ -1234,6 +1234,7 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= diff --git a/pkg/rss/rss_1.0.go b/pkg/rss/rss_1.0.go index 278988c..ab22330 100644 --- a/pkg/rss/rss_1.0.go +++ b/pkg/rss/rss_1.0.go @@ -5,8 +5,10 @@ import ( "encoding/xml" "fmt" "sort" - "strings" "time" + + "golang.org/x/text/cases" + "golang.org/x/text/language" ) func parseRSS1(data []byte) (*Feed, error) { @@ -29,6 +31,8 @@ func parseRSS1(data []byte) (*Feed, error) { out.Description = channel.Description out.Link = channel.Link out.Image = channel.Image.Image() + + titleCaser := cases.Title(language.English) if channel.MinsToLive != 0 { sort.Ints(channel.SkipHours) next := time.Now().Add(time.Duration(channel.MinsToLive) * time.Minute) @@ -41,7 +45,7 @@ func parseRSS1(data []byte) (*Feed, error) { for trying { trying = false for _, day := range channel.SkipDays { - if strings.Title(day) == next.Weekday().String() { + if titleCaser.String(day) == next.Weekday().String() { next.Add(time.Duration(24-next.Hour()) * time.Hour) trying = true break diff --git a/pkg/rss/rss_2.0.go b/pkg/rss/rss_2.0.go index 137f099..c70d7b7 100644 --- a/pkg/rss/rss_2.0.go +++ b/pkg/rss/rss_2.0.go @@ -5,8 +5,10 @@ import ( "encoding/xml" "fmt" "sort" - "strings" "time" + + "golang.org/x/text/cases" + "golang.org/x/text/language" ) func parseRSS2(data []byte) (*Feed, error) { @@ -38,6 +40,7 @@ func parseRSS2(data []byte) (*Feed, error) { out.Image = channel.Image.Image() if channel.MinsToLive != 0 { + titleCaser := cases.Title(language.English) sort.Ints(channel.SkipHours) next := time.Now().Add(time.Duration(channel.MinsToLive) * time.Minute) for _, hour := range channel.SkipHours { @@ -49,7 +52,7 @@ func parseRSS2(data []byte) (*Feed, error) { for trying { trying = false for _, day := range channel.SkipDays { - if strings.Title(day) == next.Weekday().String() { + if titleCaser.String(day) == next.Weekday().String() { next.Add(time.Duration(24-next.Hour()) * time.Hour) trying = true break