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)) r.logger.ErrorCtx(ctx, "cannot update identity locale", log.Error(err))
return nil, gqlutils.Internal(ctx) return nil, gqlutils.Internal(ctx)
} }

View File

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

View File

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