Fix lint issues

Signed-off-by: Émile Ré <emile@probo.com>
This commit is contained in:
Émile Ré
2026-07-21 18:42:05 +02:00
parent 418bb5a8f8
commit e47091e5b5
3 changed files with 16 additions and 8 deletions

View File

@@ -117,6 +117,7 @@ func (r *mutationResolver) UpdateLocale(ctx context.Context, input types.UpdateL
}
r.logger.ErrorCtx(ctx, "cannot update identity locale", log.Error(err))
return nil, gqlutils.Internal(ctx)
}

View File

@@ -23,6 +23,7 @@ package complianceportal_v1
import (
"net/http"
"net/url"
"slices"
"strings"
"go.probo.inc/probo/pkg/iam"
@@ -39,12 +40,14 @@ func SEOFromRequest(r *http.Request, pageBaseURL string) (htmlLang, canonical st
if pathname == "" {
pathname = "/"
}
locale, rest := splitLocaleFromAppPath(pathname)
htmlLang = locale
canonical = localizedPageURL(pageBaseURL, locale, rest)
locales := iam.SupportedIdentityLocales
hreflang = make([]HreflangLink, 0, len(locales)+1)
for _, loc := range locales {
hreflang = append(hreflang, HreflangLink{
@@ -52,6 +55,7 @@ func SEOFromRequest(r *http.Request, pageBaseURL string) (htmlLang, canonical st
Href: localizedPageURL(pageBaseURL, loc, rest),
})
}
hreflang = append(hreflang, HreflangLink{
Lang: "x-default",
Href: localizedPageURL(pageBaseURL, defaultCompliancePortalLocale, rest),
@@ -71,6 +75,7 @@ func splitLocaleFromAppPath(appPath string) (locale, rest string) {
if len(segments) == 1 {
return locale, "/"
}
return locale, "/" + strings.Join(segments[1:], "/")
}
@@ -79,17 +84,13 @@ func splitLocaleFromAppPath(appPath string) (locale, rest string) {
}
func isCompliancePortalLocale(value string) bool {
for _, locale := range iam.SupportedIdentityLocales {
if locale == value {
return true
}
}
return false
return slices.Contains(iam.SupportedIdentityLocales, value)
}
func localizedPageURL(pageBaseURL, locale, rest string) string {
base := strings.TrimRight(pageBaseURL, "/")
segments := []string{locale}
if rest != "/" && rest != "" {
trimmed := strings.Trim(rest, "/")
if trimmed != "" {
@@ -106,5 +107,6 @@ func localizedPageURL(pageBaseURL, locale, rest string) string {
if err != nil {
return base + "/" + strings.Join(escaped, "/")
}
return joined
}

View File

@@ -47,16 +47,21 @@ func TestSEOFromRequest(t *testing.T) {
assert.Equal(t, "https://acme.probopage.localhost/fr/documents", canonical)
require.NotEmpty(t, hreflang)
var xDefault string
var enHref string
var (
xDefault string
enHref string
)
for _, link := range hreflang {
if link.Lang == "x-default" {
xDefault = link.Href
}
if link.Lang == "en" {
enHref = link.Href
}
}
assert.Equal(t, "https://acme.probopage.localhost/en/documents", enHref)
assert.Equal(t, enHref, xDefault)
}