Update dependencies and small code changes

This commit is contained in:
Jan-Lukas Else 2022-10-07 16:19:18 +02:00
parent b38e92bc57
commit 18c129d163
5 changed files with 44 additions and 28 deletions

6
go.mod
View File

@ -43,13 +43,13 @@ require (
github.com/paulmach/go.geojson v1.4.0
github.com/posener/wstest v1.2.0
github.com/pquerna/otp v1.3.0
github.com/samber/lo v1.29.0
github.com/samber/lo v1.31.0
github.com/schollz/sqlite3dump v1.3.1
github.com/snabb/sitemap v1.0.0
github.com/spf13/cast v1.5.0
github.com/spf13/viper v1.13.0
github.com/stretchr/testify v1.8.0
github.com/tdewolff/minify/v2 v2.12.3
github.com/tdewolff/minify/v2 v2.12.4
// master
github.com/tkrajina/gpxgo v1.2.2-0.20220217201249-321f19554eec
github.com/tomnomnom/linkheader v0.0.0-20180905144013-02ca5825eb80
@ -59,7 +59,7 @@ require (
// master
github.com/yuin/goldmark-emoji v1.0.2-0.20210607094911-0487583eca38
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa
golang.org/x/net v0.0.0-20221002022538-bcab6841153b
golang.org/x/net v0.0.0-20221004154528-8021a29435af
golang.org/x/sync v0.0.0-20220929204114-8fcdb60fdcc0
golang.org/x/text v0.3.7
gopkg.in/yaml.v3 v3.0.1

12
go.sum
View File

@ -429,8 +429,8 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/rogpeppe/go-internal v1.8.1-0.20211023094830-115ce09fd6b4 h1:Ha8xCaq6ln1a+R91Km45Oq6lPXj2Mla6CRJYcuV2h1w=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/samber/lo v1.29.0 h1:sh95NCc0FLh/RU596UfoO5+iOnlLHpsGclmx52P9KN8=
github.com/samber/lo v1.29.0/go.mod h1:it33p9UtPMS7z72fP4gw/EIfQB2eI8ke7GR2wc6+Rhg=
github.com/samber/lo v1.31.0 h1:Sfa+/064Tdo4SvlohQUQzBhgSer9v/coGvKQI/XLWAM=
github.com/samber/lo v1.31.0/go.mod h1:HLeWcJRRyLKp3+/XBJvOrerCQn9mhdKMHyd7IRlgeQ8=
github.com/schollz/sqlite3dump v1.3.1 h1:QXizJ7XEJ7hggjqjZ3YRtF3+javm8zKtzNByYtEkPRA=
github.com/schollz/sqlite3dump v1.3.1/go.mod h1:mzSTjZpJH4zAb1FN3iNlhWPbbdyeBpOaTW0hukyMHyI=
github.com/scylladb/termtables v0.0.0-20191203121021-c4c0b6d42ff4/go.mod h1:C1a7PQSMz9NShzorzCiG2fk9+xuCgLkPeCvMHYR2OWg=
@ -474,8 +474,8 @@ github.com/tailscale/netlink v1.1.1-0.20211101221916-cabfb018fe85 h1:zrsUcqrG2uQ
github.com/tailscale/netlink v1.1.1-0.20211101221916-cabfb018fe85/go.mod h1:NzVQi3Mleb+qzq8VmcWpSkcSYxXIg0DkI6XDzpVkhJ0=
github.com/tcnksm/go-httpstat v0.2.0 h1:rP7T5e5U2HfmOBmZzGgGZjBQ5/GluWUylujl0tJ04I0=
github.com/tcnksm/go-httpstat v0.2.0/go.mod h1:s3JVJFtQxtBEBC9dwcdTTXS9xFnM3SXAZwPG41aurT8=
github.com/tdewolff/minify/v2 v2.12.3 h1:YcwaWQ5Grdz6EMOSykHXnHY6hbkAu6mCdAJTBDV3c6A=
github.com/tdewolff/minify/v2 v2.12.3/go.mod h1:h+SRvSIX3kwgwTFOpSckvSxgax3uy8kZTSF1Ojrr3bk=
github.com/tdewolff/minify/v2 v2.12.4 h1:kejsHQMM17n6/gwdw53qsi6lg0TGddZADVyQOz1KMdE=
github.com/tdewolff/minify/v2 v2.12.4/go.mod h1:h+SRvSIX3kwgwTFOpSckvSxgax3uy8kZTSF1Ojrr3bk=
github.com/tdewolff/parse/v2 v2.6.4 h1:KCkDvNUMof10e3QExio9OPZJT8SbdKojLBumw8YZycQ=
github.com/tdewolff/parse/v2 v2.6.4/go.mod h1:woz0cgbLwFdtbjJu8PIKxhW05KplTFQkOdX78o+Jgrs=
github.com/tdewolff/test v1.0.7 h1:8Vs0142DmPFW/bQeHRP3MV19m1gvndjUb1sn8yy74LM=
@ -624,8 +624,8 @@ golang.org/x/net v0.0.0-20210916014120-12bc252f5db8/go.mod h1:9nx3DQGgdP8bBQD5qx
golang.org/x/net v0.0.0-20210928044308-7d9f5e0b762b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211020060615-d418f374d309/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.0.0-20221002022538-bcab6841153b h1:6e93nYa3hNqAvLr0pD4PN1fFS+gKzp2zAXqrnTCstqU=
golang.org/x/net v0.0.0-20221002022538-bcab6841153b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/net v0.0.0-20221004154528-8021a29435af h1:wv66FM3rLZGPdxpYL+ApnDe2HzHcTFta3z5nsc13wI4=
golang.org/x/net v0.0.0-20221004154528-8021a29435af/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=

View File

@ -9,19 +9,19 @@ import (
"tailscale.com/client/tailscale"
)
func (a *goBlog) getTCPListener(s *http.Server) (net.Listener, error) {
func (a *goBlog) getTCPListener(serverAddr string) (net.Listener, error) {
if a.tailscaleEnabled() {
// Tailscale listener
return a.getTailscaleListener(s.Addr)
} else if s.Addr == ":443" && a.cfg.Server.PublicHTTPS {
return a.getTailscaleListener(serverAddr)
} else if serverAddr == ":443" && a.cfg.Server.PublicHTTPS {
m := a.getAutocertManager()
if m == nil {
return nil, errors.New("autocert not initialized")
}
return a.getAutocertManager().Listener(), nil
} else if s.Addr == ":443" && a.cfg.Server.TailscaleHTTPS {
} else if serverAddr == ":443" && a.cfg.Server.TailscaleHTTPS {
// Listener with Tailscale TLS config
ln, err := net.Listen("tcp", s.Addr)
ln, err := net.Listen("tcp", serverAddr)
if err != nil {
return nil, err
}
@ -32,12 +32,12 @@ func (a *goBlog) getTCPListener(s *http.Server) (net.Listener, error) {
}), nil
} else {
// Default
return net.Listen("tcp", s.Addr)
return net.Listen("tcp", serverAddr)
}
}
func (a *goBlog) listenAndServe(s *http.Server) error {
listener, err := a.getTCPListener(s)
listener, err := a.getTCPListener(s.Addr)
if err != nil {
return err
}

View File

@ -126,18 +126,21 @@ type stringGroup struct {
}
func groupStrings(toGroup []string) []stringGroup {
stringMap := map[string][]string{}
for _, s := range toGroup {
first := strings.ToUpper(string([]rune(s)[0]))
stringMap[first] = append(stringMap[first], s)
}
stringGroups := []stringGroup{}
for key, sa := range stringMap {
stringGroups = append(stringGroups, stringGroup{
Identifier: key,
Strings: sortedStrings(sa),
})
}
// Group strings and map them to stringGroups
stringGroups := lo.MapToSlice(
// strings -> map
lo.GroupBy(toGroup, func(s string) string {
return strings.ToUpper(string([]rune(s)[0]))
}),
// map -> stringGroups
func(key string, strings []string) stringGroup {
return stringGroup{
Identifier: key,
Strings: sortedStrings(strings),
}
},
)
// Sort stringGroups
sort.Slice(stringGroups, func(i, j int) bool {
return strings.ToLower(stringGroups[i].Identifier) < strings.ToLower(stringGroups[j].Identifier)
})

View File

@ -154,3 +154,16 @@ func Fuzz_lowerUnescaptedPath(f *testing.F) {
}
})
}
func Test_groupStrings(t *testing.T) {
strings := []string{"Aaaaaa", "Dddedddee", "Bbbbb", "anjkdhfkjshf", "hjgsfkjdhkfhskjdfh", "🚴🏼‍♀️ jhfjshkfjh"}
groups := groupStrings(strings)
assert.Len(t, groups, 5)
assert.Equal(t, "A", groups[0].Identifier)
assert.Equal(t, "B", groups[1].Identifier)
assert.Equal(t, "D", groups[2].Identifier)
assert.Equal(t, "H", groups[3].Identifier)
assert.Equal(t, "🚴", groups[4].Identifier)
}