Index: VERSION ================================================================== --- VERSION +++ VERSION @@ -1,1 +1,1 @@ -0.21.0 +0.22.0-dev Index: cmd/main.go ================================================================== --- cmd/main.go +++ cmd/main.go @@ -169,10 +169,12 @@ keyDefaultDirBoxType = "default-dir-box-type" keyInsecureCookie = "insecure-cookie" keyInsecureHTML = "insecure-html" keyListenAddr = "listen-addr" keyLogLevel = "log-level" + keyLoopbackIdent = "loopback-ident" + keyLoopbackZid = "loopback-zid" keyMaxRequestSize = "max-request-size" keyOwner = "owner" keyPersistentCookie = "persistent-cookie" keyReadOnly = "read-only-mode" keyRuntimeProfiling = "runtime-profiling" @@ -215,10 +217,12 @@ err = setConfigValue( err, kernel.ConfigService, kernel.ConfigInsecureHTML, cfg.GetDefault(keyInsecureHTML, kernel.ConfigSecureHTML)) err = setConfigValue( err, kernel.WebService, kernel.WebListenAddress, cfg.GetDefault(keyListenAddr, "127.0.0.1:23123")) + err = setConfigValue(err, kernel.WebService, kernel.WebLoopbackIdent, cfg.GetDefault(keyLoopbackIdent, "")) + err = setConfigValue(err, kernel.WebService, kernel.WebLoopbackZid, cfg.GetDefault(keyLoopbackZid, "")) if val, found := cfg.Get(keyBaseURL); found { err = setConfigValue(err, kernel.WebService, kernel.WebBaseURL, val) } if val, found := cfg.Get(keyURLPrefix); found { err = setConfigValue(err, kernel.WebService, kernel.WebURLPrefix, val) @@ -295,11 +299,14 @@ return nil }, ) if command.Simple { - kern.SetConfig(kernel.ConfigService, kernel.ConfigSimpleMode, "true") + if err := kern.SetConfig(kernel.ConfigService, kernel.ConfigSimpleMode, "true"); err != nil { + kern.GetKernelLogger().Error().Err(err).Msg("unable to set simple-mode") + return 1 + } } kern.Start(command.Header, command.LineServer, filename) exitCode, err := command.Func(fs) if err != nil { fmt.Fprintf(os.Stderr, "%s: %v\n", name, err) @@ -333,16 +340,25 @@ fullVersion += "-dirty" } kernel.Main.Setup(progName, fullVersion, info.time) flag.Parse() if *cpuprofile != "" || *memprofile != "" { + var err error if *cpuprofile != "" { - kernel.Main.StartProfiling(kernel.ProfileCPU, *cpuprofile) + err = kernel.Main.StartProfiling(kernel.ProfileCPU, *cpuprofile) } else { - kernel.Main.StartProfiling(kernel.ProfileHead, *memprofile) + err = kernel.Main.StartProfiling(kernel.ProfileHead, *memprofile) + } + if err != nil { + kernel.Main.GetKernelLogger().Error().Err(err).Msg("start profiling") + return 1 } - defer kernel.Main.StopProfiling() + defer func() { + if err = kernel.Main.StopProfiling(); err != nil { + kernel.Main.GetKernelLogger().Error().Err(err).Msg("stop profiling") + } + }() } args := flag.Args() if len(args) == 0 { return runSimple() } Index: docs/manual/00001004010000.zettel ================================================================== --- docs/manual/00001004010000.zettel +++ docs/manual/00001004010000.zettel @@ -2,11 +2,11 @@ title: Zettelstore startup configuration role: manual tags: #configuration #manual #zettelstore syntax: zmk created: 20210126175322 -modified: 20250102180346 +modified: 20250509182657 The configuration file, specified by the ''-c CONFIGFILE'' [[command line option|00001004051000]], allows you to specify some startup options. These cannot be stored in a [[configuration zettel|00001004020000]] because they are needed before Zettelstore can start or because of security reasons. For example, Zettelstore needs to know in advance on which network address it must listen or where zettel are stored. An attacker that is able to change the owner can do anything. @@ -93,10 +93,22 @@ Examples: ""error"" will produce just error messages (e.g. no ""info"" messages). ""error;web:debug"" will emit debugging messages for the web component of Zettelstore while still producing error messages for all other components. When you are familiar with operating the Zettelstore, you might set the level to ""error"" to receive fewer noisy messages from it. +; [!loopback-ident|''loopback-ident''], [!loopback-zid|''loopback-zid''] +: These keys are effective only if [[authentication is enabled|00001010000000]]. + They must specify the user ID and zettel ID of a [[user zettel|00001010040200]]. + When these keys are set and an HTTP request originates from the loopback device, no further authentication is required. + + The loopback device typically uses the IP address ''127.0.0.1'' (IPv4) or ''::1'' (IPv6). + + This configuration allows client software running on the same computer as the Zettelstore to access it through its API or web user interface. + + However, this setup is not recommended if the Zettelstore is running on a computer shared with untrusted or unknown users. + + Default: (empty string)/00000000000000 ; [!max-request-size|''max-request-size''] : It limits the maximum byte size of a web request body to prevent clients from accidentally or maliciously sending a large request and wasting server resources. The minimum value is 1024. Default: 16777216 (16 MiB). Index: docs/manual/00001010040100.zettel ================================================================== --- docs/manual/00001010040100.zettel +++ docs/manual/00001010040100.zettel @@ -2,11 +2,12 @@ title: Enable authentication role: manual tags: #authentication #configuration #manual #security #zettelstore syntax: zmk created: 20210126175322 -modified: 20220419192817 +modified: 20250509181249 +show-back-links: close To enable authentication, you must create a zettel that stores [[authentication data|00001010040200]] for the owner. Then you must reference this zettel within the [[startup configuration|00001004010000#owner]] under the key ''owner''. Once the startup configuration contains a valid [[zettel identifier|00001006050000]] under that key, authentication is enabled. Index: go.mod ================================================================== --- go.mod +++ go.mod @@ -2,18 +2,18 @@ go 1.24 require ( github.com/fsnotify/fsnotify v1.9.0 - github.com/yuin/goldmark v1.7.9 - golang.org/x/crypto v0.37.0 - golang.org/x/term v0.31.0 - golang.org/x/text v0.24.0 - t73f.de/r/sx v0.0.0-20250415161954-42ed9c4d6abc - t73f.de/r/sxwebs v0.0.0-20250415162443-110f49c5a1ae - t73f.de/r/webs v0.0.0-20250403120312-69ac186a05b5 - t73f.de/r/zero v0.0.0-20250403120114-7d464a82f2e5 - t73f.de/r/zsc v0.0.0-20250417145802-ef331b4f0cdd + github.com/yuin/goldmark v1.7.11 + golang.org/x/crypto v0.38.0 + golang.org/x/term v0.32.0 + golang.org/x/text v0.25.0 + t73f.de/r/sx v0.0.0-20250506141526-34e7a17d22f1 + t73f.de/r/sxwebs v0.0.0-20250505103220-54507dc1509d + t73f.de/r/webs v0.0.0-20250505155652-db844dadbf0a + t73f.de/r/zero v0.0.0-20250421161051-9472f592aeea + t73f.de/r/zsc v0.0.0-20250502143402-b5c74e61e1a7 t73f.de/r/zsx v0.0.0-20250415162540-fc13b286b6ce ) -require golang.org/x/sys v0.32.0 // indirect +require golang.org/x/sys v0.33.0 // indirect Index: go.sum ================================================================== --- go.sum +++ go.sum @@ -1,24 +1,24 @@ github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k= github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0= -github.com/yuin/goldmark v1.7.9 h1:rVSeT+f7/lAM+bJHVm5YHGwNrnd40i1Ch2DEocEjHQ0= -github.com/yuin/goldmark v1.7.9/go.mod h1:ip/1k0VRfGynBgxOz0yCqHrbZXhcjxyuS66Brc7iBKg= -golang.org/x/crypto v0.37.0 h1:kJNSjF/Xp7kU0iB2Z+9viTPMW4EqqsrywMXLJOOsXSE= -golang.org/x/crypto v0.37.0/go.mod h1:vg+k43peMZ0pUMhYmVAWysMK35e6ioLh3wB8ZCAfbVc= -golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20= -golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= -golang.org/x/term v0.31.0 h1:erwDkOK1Msy6offm1mOgvspSkslFnIGsFnxOKoufg3o= -golang.org/x/term v0.31.0/go.mod h1:R4BeIy7D95HzImkxGkTW1UQTtP54tio2RyHz7PwK0aw= -golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0= -golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU= -t73f.de/r/sx v0.0.0-20250415161954-42ed9c4d6abc h1:tlsP+47Rf8i9Zv1TqRnwfbQx3nN/F/92RkT6iCA6SVA= -t73f.de/r/sx v0.0.0-20250415161954-42ed9c4d6abc/go.mod h1:hzg05uSCMk3D/DWaL0pdlowfL2aWQeGIfD1S04vV+Xg= -t73f.de/r/sxwebs v0.0.0-20250415162443-110f49c5a1ae h1:K6nxN/bb0BCSiDffwNPGTF2uf5WcTdxcQXzByXNuJ7M= -t73f.de/r/sxwebs v0.0.0-20250415162443-110f49c5a1ae/go.mod h1:0LQ9T1svSg9ADY/6vQLKNUu6LqpPi8FGr7fd2qDT5H8= -t73f.de/r/webs v0.0.0-20250403120312-69ac186a05b5 h1:M2RMwkuBlMAKgNH70qLtEFqw7jtH+/rM0NTUPZObk6Y= -t73f.de/r/webs v0.0.0-20250403120312-69ac186a05b5/go.mod h1:zk92hSKB4iWyT290+163seNzu350TA9XLATC9kOldqo= -t73f.de/r/zero v0.0.0-20250403120114-7d464a82f2e5 h1:3FU6YUaqxJI20ZTXDc8xnPBzjajnWZ56XaPOfckEmJo= -t73f.de/r/zero v0.0.0-20250403120114-7d464a82f2e5/go.mod h1:T1vFcHoymUQcr7+vENBkS1yryZRZ3YB8uRtnMy8yRBA= -t73f.de/r/zsc v0.0.0-20250417145802-ef331b4f0cdd h1:InJjWI/Y2xAJBBs+SMXTS7rJaizk6/b/VW5CCno0vrg= -t73f.de/r/zsc v0.0.0-20250417145802-ef331b4f0cdd/go.mod h1:Mb3fLaOcSp5t6I7sRDKmOx4U1AnTb30F7Jh4e1L0mx8= +github.com/yuin/goldmark v1.7.11 h1:ZCxLyDMtz0nT2HFfsYG8WZ47Trip2+JyLysKcMYE5bo= +github.com/yuin/goldmark v1.7.11/go.mod h1:ip/1k0VRfGynBgxOz0yCqHrbZXhcjxyuS66Brc7iBKg= +golang.org/x/crypto v0.38.0 h1:jt+WWG8IZlBnVbomuhg2Mdq0+BBQaHbtqHEFEigjUV8= +golang.org/x/crypto v0.38.0/go.mod h1:MvrbAqul58NNYPKnOra203SB9vpuZW0e+RRZV+Ggqjw= +golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw= +golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/term v0.32.0 h1:DR4lr0TjUs3epypdhTOkMmuF5CDFJ/8pOnbzMZPQ7bg= +golang.org/x/term v0.32.0/go.mod h1:uZG1FhGx848Sqfsq4/DlJr3xGGsYMu/L5GW4abiaEPQ= +golang.org/x/text v0.25.0 h1:qVyWApTSYLk/drJRO5mDlNYskwQznZmkpV2c8q9zls4= +golang.org/x/text v0.25.0/go.mod h1:WEdwpYrmk1qmdHvhkSTNPm3app7v4rsT8F2UD6+VHIA= +t73f.de/r/sx v0.0.0-20250506141526-34e7a17d22f1 h1:XcJyCHhfdA8USdVPgSl2QB/xodif22t8U5Tnb1H9MWk= +t73f.de/r/sx v0.0.0-20250506141526-34e7a17d22f1/go.mod h1:1RlIqF7OJqEv7j5uhY+gNWkBYEYgVTpAUbGG20rK31Y= +t73f.de/r/sxwebs v0.0.0-20250505103220-54507dc1509d h1:Byow/3dJIeBONdF0XrdSmpzfWcGdCmIwQRU4D4DbKrQ= +t73f.de/r/sxwebs v0.0.0-20250505103220-54507dc1509d/go.mod h1:+uH4dTQ+I8eofO+rJX37yn1LSLf6V7/7lpRwUpwtCpE= +t73f.de/r/webs v0.0.0-20250505155652-db844dadbf0a h1:ohQthZH4IsyD0YuPurawY89pPUm2sFNrQwKUSRUr9So= +t73f.de/r/webs v0.0.0-20250505155652-db844dadbf0a/go.mod h1:zk92hSKB4iWyT290+163seNzu350TA9XLATC9kOldqo= +t73f.de/r/zero v0.0.0-20250421161051-9472f592aeea h1:7oOWX1J1YC9gadK/poa4g6upF9l8dQa9uNdqYFEmKm8= +t73f.de/r/zero v0.0.0-20250421161051-9472f592aeea/go.mod h1:T1vFcHoymUQcr7+vENBkS1yryZRZ3YB8uRtnMy8yRBA= +t73f.de/r/zsc v0.0.0-20250502143402-b5c74e61e1a7 h1:fn40OYrzWt8KUNpB6b77dej07H8sDA6WaqcFT4ifSW4= +t73f.de/r/zsc v0.0.0-20250502143402-b5c74e61e1a7/go.mod h1:Mb3fLaOcSp5t6I7sRDKmOx4U1AnTb30F7Jh4e1L0mx8= t73f.de/r/zsx v0.0.0-20250415162540-fc13b286b6ce h1:R9rtg4ecx4YYixsMmsh+wdcqLdY9GxoC5HZ9mMS33to= t73f.de/r/zsx v0.0.0-20250415162540-fc13b286b6ce/go.mod h1:tXOlmsQBoY4mY7Plu0LCCMZNSJZJbng98fFarZXAWvM= Index: internal/auth/impl/impl.go ================================================================== --- internal/auth/impl/impl.go +++ internal/auth/impl/impl.go @@ -57,14 +57,14 @@ } func calcSecret(extSecret string) []byte { h := fnv.New128() if extSecret != "" { - io.WriteString(h, extSecret) + _, _ = io.WriteString(h, extSecret) } for _, key := range configKeys { - io.WriteString(h, kernel.Main.GetConfig(kernel.CoreService, key).(string)) + _, _ = io.WriteString(h, kernel.Main.GetConfig(kernel.CoreService, key).(string)) } return h.Sum(nil) } // IsReadonly returns true, if the systems is configured to run in read-only-mode. Index: internal/box/constbox/constbox.go ================================================================== --- internal/box/constbox/constbox.go +++ internal/box/constbox/constbox.go @@ -258,24 +258,12 @@ meta.KeySyntax: meta.ValueSyntaxSxn, meta.KeyCreated: "20230619132800", meta.KeyModified: "20241118173500", meta.KeyReadOnly: meta.ValueTrue, meta.KeyVisibility: meta.ValueVisibilityExpert, - meta.KeyPrecursor: id.ZidSxnPrelude.String(), }, zettel.NewContent(contentBaseCodeSxn)}, - id.ZidSxnPrelude: { - constHeader{ - meta.KeyTitle: "Zettelstore Sxn Prelude", - meta.KeyRole: meta.ValueRoleConfiguration, - meta.KeySyntax: meta.ValueSyntaxSxn, - meta.KeyCreated: "20231006181700", - meta.KeyModified: "20240222121200", - meta.KeyReadOnly: meta.ValueTrue, - meta.KeyVisibility: meta.ValueVisibilityExpert, - }, - zettel.NewContent(contentPreludeSxn)}, id.ZidBaseCSS: { constHeader{ meta.KeyTitle: "Zettelstore Base CSS", meta.KeyRole: meta.ValueRoleConfiguration, meta.KeySyntax: meta.ValueSyntaxCSS, @@ -468,13 +456,10 @@ var contentStartCodeSxn []byte //go:embed wuicode.sxn var contentBaseCodeSxn []byte -//go:embed prelude.sxn -var contentPreludeSxn []byte - //go:embed base.css var contentBaseCSS []byte //go:embed emoji_spin.gif var contentEmoji []byte Index: internal/box/constbox/info.sxn ================================================================== --- internal/box/constbox/info.sxn +++ internal/box/constbox/info.sxn @@ -13,13 +13,12 @@ `(article (header (h1 "Information for Zettel " ,zid) (p (a (@ (href ,web-url)) "Web") - (@H " · ") (a (@ (href ,context-url)) "Context") - (@H " / ") (a (@ (href ,context-full-url)) "Full") ,@(if (bound? 'edit-url) `((@H " · ") (a (@ (href ,edit-url)) "Edit"))) + (@H " · ") (a (@ (href ,context-full-url)) "Full Context") ,@(ROLE-DEFAULT-actions (current-binding)) ,@(if (bound? 'reindex-url) `((@H " · ") (a (@ (href ,reindex-url)) "Reindex"))) ,@(if (bound? 'delete-url) `((@H " · ") (a (@ (href ,delete-url)) "Delete"))) ) ) DELETED internal/box/constbox/prelude.sxn Index: internal/box/constbox/prelude.sxn ================================================================== --- internal/box/constbox/prelude.sxn +++ /dev/null @@ -1,62 +0,0 @@ -;;;---------------------------------------------------------------------------- -;;; Copyright (c) 2023-present Detlef Stern -;;; -;;; This file is part of Zettelstore. -;;; -;;; Zettelstore is licensed under the latest version of the EUPL (European -;;; Union Public License). Please see file LICENSE.txt for your rights and -;;; obligations under this license. -;;; -;;; SPDX-License-Identifier: EUPL-1.2 -;;; SPDX-FileCopyrightText: 2023-present Detlef Stern -;;;---------------------------------------------------------------------------- - -;;; This zettel contains sxn definitions that are independent of specific -;;; subsystems, such as WebUI, API, or other. It just contains generic code to -;;; be used in all places. It asumes that the symbols NIL and T are defined. - -;; not macro -(defmacro not (x) `(if ,x NIL T)) - -;; not= macro, to negate an equivalence -(defmacro not= args `(not (= ,@args))) - -;; let* macro -;; -;; (let* (BINDING ...) EXPR ...), where SYMBOL may occur in later bindings. -(defmacro let* (bindings . body) - (if (null? bindings) - `(begin ,@body) - `(let ((,(caar bindings) ,(cadar bindings))) - (let* ,(cdr bindings) ,@body)))) - -;; cond macro -;; -;; (cond ((COND EXPR) ...)) -(defmacro cond clauses - (if (null? clauses) - () - (let* ((clause (car clauses)) - (the-cond (car clause))) - (if (= the-cond T) - `(begin ,@(cdr clause)) - `(if ,the-cond - (begin ,@(cdr clause)) - (cond ,@(cdr clauses))))))) - -;; and macro -;; -;; (and EXPR ...) -(defmacro and args - (cond ((null? args) T) - ((null? (cdr args)) (car args)) - (T `(if ,(car args) (and ,@(cdr args)))))) - - -;; or macro -;; -;; (or EXPR ...) -(defmacro or args - (cond ((null? args) NIL) - ((null? (cdr args)) (car args)) - (T `(if ,(car args) T (or ,@(cdr args)))))) Index: internal/box/constbox/zettel.sxn ================================================================== --- internal/box/constbox/zettel.sxn +++ internal/box/constbox/zettel.sxn @@ -21,10 +21,11 @@ "(" ,@(if (bound? 'role-url) `((a (@ (href ,role-url)) ,meta-role))) ,@(if (and (bound? 'folge-role-url) (bound? 'meta-folge-role)) `((@H " → ") (a (@ (href ,folge-role-url)) ,meta-folge-role))) ")" ,@(if tag-refs `((@H " · ") ,@tag-refs)) + (@H " · ") (a (@ (href ,context-url)) "Context") ,@(ROLE-DEFAULT-actions (current-binding)) ,@(if superior-refs `((br) "Superior: " ,superior-refs)) ,@(if predecessor-refs `((br) "Predecessor: " ,predecessor-refs)) ,@(if prequel-refs `((br) "Prequel: " ,prequel-refs)) ,@(if precursor-refs `((br) "Precursor: " ,precursor-refs)) Index: internal/box/dirbox/dirbox.go ================================================================== --- internal/box/dirbox/dirbox.go +++ internal/box/dirbox/dirbox.go @@ -312,12 +312,15 @@ if !entry.IsValid() { // Existing zettel, but new in this box. entry = ¬ify.DirEntry{Zid: zid} } dp.updateEntryFromMetaContent(entry, meta, zettel.Content) - dp.dirSrv.UpdateDirEntry(entry) - err := dp.srvSetZettel(ctx, entry, zettel) + err := dp.dirSrv.UpdateDirEntry(entry) + if err != nil { + return err + } + err = dp.srvSetZettel(ctx, entry, zettel) if err == nil { dp.notifyChanged(zid, box.OnZettel) } dp.log.Trace().Zid(zid).Err(err).Msg("UpdateZettel") return err Index: internal/box/filebox/zipbox.go ================================================================== --- internal/box/filebox/zipbox.go +++ internal/box/filebox/zipbox.go @@ -68,11 +68,13 @@ func (zb *zipBox) Start(context.Context) error { reader, err := zip.OpenReader(zb.name) if err != nil { return err } - reader.Close() + if err = reader.Close(); err != nil { + return err + } zipNotifier := notify.NewSimpleZipNotifier(zb.log, zb.name) zb.dirSrv = notify.NewDirService(zb, zb.log, zipNotifier, zb.notify) zb.dirSrv.Start() return nil } @@ -94,11 +96,11 @@ } reader, err := zip.OpenReader(zb.name) if err != nil { return zettel.Zettel{}, err } - defer reader.Close() + defer func() { _ = reader.Close() }() var m *meta.Meta var src []byte var inMeta bool @@ -154,11 +156,10 @@ func (zb *zipBox) ApplyMeta(ctx context.Context, handle box.MetaFunc, constraint query.RetrievePredicate) error { reader, err := zip.OpenReader(zb.name) if err != nil { return err } - defer reader.Close() entries := zb.dirSrv.GetDirEntries(constraint) zb.log.Trace().Int("entries", int64(len(entries))).Msg("ApplyMeta") for _, entry := range entries { if !constraint(entry.Zid) { continue @@ -168,11 +169,11 @@ continue } zb.enricher.Enrich(ctx, m, zb.number) handle(m) } - return nil + return reader.Close() } func (*zipBox) CanDeleteZettel(context.Context, id.Zid) bool { return false } func (zb *zipBox) DeleteZettel(_ context.Context, zid id.Zid) error { @@ -224,8 +225,12 @@ func readZipFileContent(reader *zip.ReadCloser, name string) ([]byte, error) { f, err := reader.Open(name) if err != nil { return nil, err } - defer f.Close() - return io.ReadAll(f) + data, err := io.ReadAll(f) + err2 := f.Close() + if err == nil { + err = err2 + } + return data, err } Index: internal/box/manager/mapstore/mapstore.go ================================================================== --- internal/box/manager/mapstore/mapstore.go +++ internal/box/manager/mapstore/mapstore.go @@ -581,11 +581,11 @@ func (ms *mapStore) Dump(w io.Writer) { ms.mx.RLock() defer ms.mx.RUnlock() - io.WriteString(w, "=== Dump\n") + _, _ = io.WriteString(w, "=== Dump\n") ms.dumpIndex(w) ms.dumpDead(w) dumpStringRefs(w, "Words", "", "", ms.words) dumpStringRefs(w, "URLs", "[[", "]]", ms.urls) } @@ -592,21 +592,21 @@ func (ms *mapStore) dumpIndex(w io.Writer) { if len(ms.idx) == 0 { return } - io.WriteString(w, "==== Zettel Index\n") + _, _ = io.WriteString(w, "==== Zettel Index\n") zids := make([]id.Zid, 0, len(ms.idx)) for id := range ms.idx { zids = append(zids, id) } slices.Sort(zids) for _, id := range zids { - fmt.Fprintln(w, "=====", id) + _, _ = fmt.Fprintln(w, "=====", id) zi := ms.idx[id] if !zi.dead.IsEmpty() { - fmt.Fprintln(w, "* Dead:", zi.dead) + _, _ = fmt.Fprintln(w, "* Dead:", zi.dead) } dumpSet(w, "* Forward:", zi.forward) dumpSet(w, "* Backward:", zi.backward) otherRefs := make([]string, 0, len(zi.otherRefs)) @@ -613,11 +613,11 @@ for k := range zi.otherRefs { otherRefs = append(otherRefs, k) } slices.Sort(otherRefs) for _, k := range otherRefs { - fmt.Fprintln(w, "* Meta", k) + _, _ = fmt.Fprintln(w, "* Meta", k) dumpSet(w, "** Forward:", zi.otherRefs[k].forward) dumpSet(w, "** Backward:", zi.otherRefs[k].backward) } dumpStrings(w, "* Words", "", "", zi.words) dumpStrings(w, "* URLs", "[[", "]]", zi.urls) @@ -626,49 +626,49 @@ func (ms *mapStore) dumpDead(w io.Writer) { if len(ms.dead) == 0 { return } - fmt.Fprintf(w, "==== Dead References\n") + _, _ = fmt.Fprintf(w, "==== Dead References\n") zids := make([]id.Zid, 0, len(ms.dead)) for id := range ms.dead { zids = append(zids, id) } slices.Sort(zids) for _, id := range zids { - fmt.Fprintln(w, ";", id) - fmt.Fprintln(w, ":", ms.dead[id]) + _, _ = fmt.Fprintln(w, ";", id) + _, _ = fmt.Fprintln(w, ":", ms.dead[id]) } } func dumpSet(w io.Writer, prefix string, s *idset.Set) { if !s.IsEmpty() { - io.WriteString(w, prefix) + _, _ = io.WriteString(w, prefix) s.ForEach(func(zid id.Zid) { - io.WriteString(w, " ") - w.Write(zid.Bytes()) + _, _ = io.WriteString(w, " ") + _, _ = w.Write(zid.Bytes()) }) - fmt.Fprintln(w) + _, _ = fmt.Fprintln(w) } } func dumpStrings(w io.Writer, title, preString, postString string, slice []string) { if len(slice) > 0 { sl := make([]string, len(slice)) copy(sl, slice) slices.Sort(sl) - fmt.Fprintln(w, title) + _, _ = fmt.Fprintln(w, title) for _, s := range sl { - fmt.Fprintf(w, "** %s%s%s\n", preString, s, postString) + _, _ = fmt.Fprintf(w, "** %s%s%s\n", preString, s, postString) } } } func dumpStringRefs(w io.Writer, title, preString, postString string, srefs stringRefs) { if len(srefs) == 0 { return } - fmt.Fprintln(w, "====", title) + _, _ = fmt.Fprintln(w, "====", title) for _, s := range slices.Sorted(maps.Keys(srefs)) { - fmt.Fprintf(w, "; %s%s%s\n", preString, s, postString) - fmt.Fprintln(w, ":", srefs[s]) + _, _ = fmt.Fprintf(w, "; %s%s%s\n", preString, s, postString) + _, _ = fmt.Fprintln(w, ":", srefs[s]) } } Index: internal/box/notify/fsdir.go ================================================================== --- internal/box/notify/fsdir.go +++ internal/box/notify/fsdir.go @@ -53,11 +53,11 @@ if err != nil { log.Error(). Str("parentDir", absParentDir).Err(errParent). Str("path", absPath).Err(err). Msg("Unable to access Zettel directory and its parent directory") - watcher.Close() + _ = watcher.Close() return nil, err } log.Info().Str("parentDir", absParentDir).Err(errParent). Msg("Parent of Zettel directory cannot be supervised") log.Info().Str("path", absPath). @@ -88,11 +88,11 @@ func (fsdn *fsdirNotifier) Refresh() { fsdn.refresh <- struct{}{} } func (fsdn *fsdirNotifier) eventLoop() { - defer fsdn.base.Close() + defer func() { _ = fsdn.base.Close() }() defer close(fsdn.events) defer close(fsdn.refresh) if !listDirElements(fsdn.log, fsdn.fetcher, fsdn.events, fsdn.done) { return } @@ -154,11 +154,11 @@ } func (fsdn *fsdirNotifier) processDirEvent(ev *fsnotify.Event) bool { if ev.Has(fsnotify.Remove) || ev.Has(fsnotify.Rename) { fsdn.log.Debug().Str("name", fsdn.path).Msg("Directory removed") - fsdn.base.Remove(fsdn.path) + _ = fsdn.base.Remove(fsdn.path) select { case fsdn.events <- Event{Op: Destroy}: case <-fsdn.done: fsdn.log.Trace().Int("i", 1).Msg("done dir event processing") return false Index: internal/box/notify/helper.go ================================================================== --- internal/box/notify/helper.go +++ internal/box/notify/helper.go @@ -55,16 +55,16 @@ func (zpf *zipPathFetcher) Fetch() ([]string, error) { reader, err := zip.OpenReader(zpf.zipPath) if err != nil { return nil, err } - defer reader.Close() result := make([]string, 0, len(reader.File)) for _, f := range reader.File { result = append(result, f.Name) } - return result, nil + err = reader.Close() + return result, err } // listDirElements write all files within the directory path as events. func listDirElements(log *logger.Logger, fetcher EntryFetcher, events chan<- Event, done <-chan struct{}) bool { select { Index: internal/encoder/htmlenc.go ================================================================== --- internal/encoder/htmlenc.go +++ internal/encoder/htmlenc.go @@ -68,11 +68,11 @@ sx.Nil().Cons(sx.Nil().Cons(sx.Cons(sx.MakeSymbol("charset"), sx.MakeString("utf-8"))).Cons(sxhtml.SymAttr)).Cons(shtml.SymMeta), ) head.ExtendBang(hm) var sb strings.Builder if hasTitle { - he.textEnc.WriteInlines(&sb, &isTitle) + _, _ = he.textEnc.WriteInlines(&sb, &isTitle) } else { sb.Write(zn.Meta.Zid.Bytes()) } head.Add(sx.MakeList(shtml.SymAttrTitle, sx.MakeString(sb.String()))) Index: internal/encoder/mdenc.go ================================================================== --- internal/encoder/mdenc.go +++ internal/encoder/mdenc.go @@ -35,11 +35,11 @@ v := newMDVisitor(w, me.lang) v.acceptMeta(zn.InhMeta) if zn.InhMeta.YamlSep { v.b.WriteString("---\n") } else { - v.b.WriteByte('\n') + v.b.WriteLn() } ast.Walk(&v, &zn.BlocksAST) length, err := v.b.Flush() return length, err } @@ -155,11 +155,11 @@ v.writeSpaces(4) lcm1 := lc - 1 for i := 0; i < lc; i++ { b := vn.Content[i] if b != '\n' && b != '\r' { - v.b.WriteByte(b) + _ = v.b.WriteByte(b) continue } j := i + 1 for ; j < lc; j++ { c := vn.Content[j] @@ -168,11 +168,11 @@ } } if j >= lcm1 { break } - v.b.WriteByte('\n') + v.b.WriteLn() v.writeSpaces(4) i = j - 1 } } @@ -223,17 +223,17 @@ v.listInfo = append(v.listInfo, len(enum)) regIndent := 4*len(v.listInfo) - 4 paraIndent := regIndent + len(enum) for i, item := range ln.Items { if i > 0 { - v.b.WriteByte('\n') + v.b.WriteLn() } v.writeSpaces(regIndent) v.b.WriteString(enum) for j, in := range item { if j > 0 { - v.b.WriteByte('\n') + v.b.WriteLn() if _, ok := in.(*ast.ParaNode); ok { v.writeSpaces(paraIndent) } } ast.Walk(v, in) @@ -250,16 +250,16 @@ prefix := v.listPrefix v.listPrefix = "> " for i, item := range ln.Items { if i > 0 { - v.b.WriteByte('\n') + v.b.WriteLn() } v.b.WriteString(v.listPrefix) for j, in := range item { if j > 0 { - v.b.WriteByte('\n') + v.b.WriteLn() if _, ok := in.(*ast.ParaNode); ok { v.b.WriteString(v.listPrefix) } } ast.Walk(v, in) @@ -271,11 +271,11 @@ func (v *mdVisitor) visitBreak(bn *ast.BreakNode) { if bn.Hard { v.b.WriteString("\\\n") } else { - v.b.WriteByte('\n') + v.b.WriteLn() } if l := len(v.listInfo); l > 0 { if v.listPrefix == "" { v.writeSpaces(4*l - 4 + v.listInfo[l-1]) } else { @@ -294,26 +294,26 @@ func (v *mdVisitor) visitEmbedRef(en *ast.EmbedRefNode) { v.pushAttributes(en.Attrs) defer v.popAttributes() - v.b.WriteByte('!') + _ = v.b.WriteByte('!') v.writeReference(en.Ref, en.Inlines) } func (v *mdVisitor) writeReference(ref *ast.Reference, is ast.InlineSlice) { if ref.State == ast.RefStateQuery { ast.Walk(v, &is) } else if len(is) > 0 { - v.b.WriteByte('[') + _ = v.b.WriteByte('[') ast.Walk(v, &is) v.b.WriteStrings("](", ref.String()) - v.b.WriteByte(')') + _ = v.b.WriteByte(')') } else if isAutoLinkable(ref) { - v.b.WriteByte('<') + _ = v.b.WriteByte('<') v.b.WriteString(ref.String()) - v.b.WriteByte('>') + _ = v.b.WriteByte('>') } else { s := ref.String() v.b.WriteStrings("[", s, "](", s, ")") } } @@ -329,13 +329,13 @@ v.pushAttributes(fn.Attrs) defer v.popAttributes() switch fn.Kind { case ast.FormatEmph: - v.b.WriteByte('*') + _ = v.b.WriteByte('*') ast.Walk(v, &fn.Inlines) - v.b.WriteByte('*') + _ = v.b.WriteByte('*') case ast.FormatStrong: v.b.WriteString("__") ast.Walk(v, &fn.Inlines) v.b.WriteString("__") case ast.FormatQuote: @@ -365,19 +365,19 @@ } func (v *mdVisitor) visitLiteral(ln *ast.LiteralNode) { switch ln.Kind { case ast.LiteralCode, ast.LiteralInput, ast.LiteralOutput: - v.b.WriteByte('`') - v.b.Write(ln.Content) - v.b.WriteByte('`') + _ = v.b.WriteByte('`') + _, _ = v.b.Write(ln.Content) + _ = v.b.WriteByte('`') case ast.LiteralComment: // ignore everything default: - v.b.Write(ln.Content) + _, _ = v.b.Write(ln.Content) } } func (v *mdVisitor) writeSpaces(n int) { for range n { - v.b.WriteByte(' ') + v.b.WriteSpace() } } Index: internal/encoder/textenc.go ================================================================== --- internal/encoder/textenc.go +++ internal/encoder/textenc.go @@ -29,11 +29,11 @@ type TextEncoder struct{} // WriteZettel writes metadata and content. func (te *TextEncoder) WriteZettel(w io.Writer, zn *ast.ZettelNode) (int, error) { v := newTextVisitor(w) - te.WriteMeta(&v.b, zn.InhMeta) + _, _ = te.WriteMeta(&v.b, zn.InhMeta) v.visitBlockSlice(&zn.BlocksAST) length, err := v.b.Flush() return length, err } @@ -44,21 +44,21 @@ if meta.Type(key) == meta.TypeTagSet { writeTagSet(&buf, val.Elems()) } else { buf.WriteString(string(val)) } - buf.WriteByte('\n') + buf.WriteLn() } length, err := buf.Flush() return length, err } func writeTagSet(buf *encWriter, tags iter.Seq[meta.Value]) { first := true for tag := range tags { if !first { - buf.WriteByte(' ') + buf.WriteSpace() } first = false buf.WriteString(string(tag.CleanTag())) } @@ -102,11 +102,11 @@ v.visitVerbatim(n) return nil case *ast.RegionNode: v.visitBlockSlice(&n.Blocks) if len(n.Inlines) > 0 { - v.b.WriteByte('\n') + v.b.WriteLn() ast.Walk(v, &n.Inlines) } return nil case *ast.NestedListNode: v.visitNestedList(n) @@ -124,13 +124,13 @@ case *ast.TextNode: v.visitText(n.Text) return nil case *ast.BreakNode: if n.Hard { - v.b.WriteByte('\n') + v.b.WriteLn() } else { - v.b.WriteByte(' ') + v.b.WriteSpace() } return nil case *ast.LinkNode: if len(n.Inlines) > 0 { ast.Walk(v, &n.Inlines) @@ -141,26 +141,25 @@ ast.Walk(v, &n.Inlines) } return nil case *ast.FootnoteNode: if v.inlinePos > 0 { - v.b.WriteByte(' ') + v.b.WriteSpace() } // No 'return nil' to write text case *ast.LiteralNode: if n.Kind != ast.LiteralComment { - v.b.Write(n.Content) + _, _ = v.b.Write(n.Content) } } return v } func (v *textVisitor) visitVerbatim(vn *ast.VerbatimNode) { - if vn.Kind == ast.VerbatimComment { - return + if vn.Kind != ast.VerbatimComment { + _, _ = v.b.Write(vn.Content) } - v.b.Write(vn.Content) } func (v *textVisitor) visitNestedList(ln *ast.NestedListNode) { for i, item := range ln.Items { v.writePosChar(i, '\n') @@ -174,11 +173,11 @@ func (v *textVisitor) visitDescriptionList(dl *ast.DescriptionListNode) { for i, descr := range dl.Descriptions { v.writePosChar(i, '\n') ast.Walk(v, &descr.Term) for _, b := range descr.Descriptions { - v.b.WriteByte('\n') + v.b.WriteLn() for k, d := range b { v.writePosChar(k, '\n') ast.Walk(v, d) } } @@ -186,11 +185,11 @@ } func (v *textVisitor) visitTable(tn *ast.TableNode) { if len(tn.Header) > 0 { v.writeRow(tn.Header) - v.b.WriteByte('\n') + v.b.WriteLn() } for i, row := range tn.Rows { v.writePosChar(i, '\n') v.writeRow(row) } @@ -221,11 +220,11 @@ func (v *textVisitor) visitText(s string) { spaceFound := false for _, ch := range s { if input.IsSpace(ch) { if !spaceFound { - v.b.WriteByte(' ') + v.b.WriteSpace() spaceFound = true } continue } spaceFound = false @@ -233,8 +232,8 @@ } } func (v *textVisitor) writePosChar(pos int, ch byte) { if pos > 0 { - v.b.WriteByte(ch) + _ = v.b.WriteByte(ch) } } Index: internal/encoder/write.go ================================================================== --- internal/encoder/write.go +++ internal/encoder/write.go @@ -24,13 +24,11 @@ err error // Collect error length int // Collected length } // newEncWriter creates a new encWriter -func newEncWriter(w io.Writer) encWriter { - return encWriter{w: w} -} +func newEncWriter(w io.Writer) encWriter { return encWriter{w: w} } // Write writes the content of p. func (w *encWriter) Write(p []byte) (l int, err error) { if w.err != nil { return 0, w.err @@ -64,13 +62,11 @@ w.length += l return w.err } // WriteBytes writes the content of bs. -func (w *encWriter) WriteBytes(bs ...byte) { - w.Write(bs) -} +func (w *encWriter) WriteBytes(bs ...byte) { _, _ = w.Write(bs) } // WriteBase64 writes the content of p, encoded with base64. func (w *encWriter) WriteBase64(p []byte) { if w.err == nil { encoder := base64.NewEncoder(base64.StdEncoding, w.w) @@ -81,8 +77,22 @@ if w.err == nil { w.err = err1 } } } + +// WriteLn writes a new line character. +func (w *encWriter) WriteLn() { + if w.err == nil { + w.err = w.WriteByte('\n') + } +} + +// WriteLn writes a space character. +func (w *encWriter) WriteSpace() { + if w.err == nil { + w.err = w.WriteByte(' ') + } +} // Flush returns the collected length and error. func (w *encWriter) Flush() (int, error) { return w.length, w.err } Index: internal/encoder/zmkenc.go ================================================================== --- internal/encoder/zmkenc.go +++ internal/encoder/zmkenc.go @@ -35,11 +35,11 @@ v := newZmkVisitor(w) v.acceptMeta(zn.InhMeta) if zn.InhMeta.YamlSep { v.b.WriteString("---\n") } else { - v.b.WriteByte('\n') + v.b.WriteLn() } ast.Walk(&v, &zn.BlocksAST) length, err := v.b.Flush() return length, err } @@ -120,11 +120,11 @@ case *ast.CiteNode: v.visitCite(n) case *ast.FootnoteNode: v.b.WriteString("[^") ast.Walk(v, &n.Inlines) - v.b.WriteByte(']') + _ = v.b.WriteByte(']') v.visitAttributes(n.Attrs) case *ast.MarkNode: v.visitMark(n) case *ast.FormatNode: v.visitFormat(n) @@ -138,14 +138,14 @@ func (v *zmkVisitor) visitBlockSlice(bs *ast.BlockSlice) { var lastWasParagraph bool for i, bn := range *bs { if i > 0 { - v.b.WriteByte('\n') + v.b.WriteLn() if lastWasParagraph && !v.inVerse { if _, ok := bn.(*ast.ParaNode); ok { - v.b.WriteByte('\n') + v.b.WriteLn() } } } ast.Walk(v, bn) _, lastWasParagraph = bn.(*ast.ParaNode) @@ -172,13 +172,13 @@ } // TODO: scan cn.Lines to find embedded kind[0]s at beginning v.b.WriteString(kind) v.visitAttributes(attrs) - v.b.WriteByte('\n') - v.b.Write(vn.Content) - v.b.WriteByte('\n') + v.b.WriteLn() + _, _ = v.b.Write(vn.Content) + v.b.WriteLn() v.b.WriteString(kind) } var mapRegionKind = map[ast.RegionKind]string{ ast.RegionSpan: ":::", @@ -192,19 +192,19 @@ if !ok { panic(fmt.Sprintf("Unknown region kind %d", rn.Kind)) } v.b.WriteString(kind) v.visitAttributes(rn.Attrs) - v.b.WriteByte('\n') + v.b.WriteLn() saveInVerse := v.inVerse v.inVerse = rn.Kind == ast.RegionVerse ast.Walk(v, &rn.Blocks) v.inVerse = saveInVerse - v.b.WriteByte('\n') + v.b.WriteLn() v.b.WriteString(kind) if len(rn.Inlines) > 0 { - v.b.WriteByte(' ') + v.b.WriteSpace() ast.Walk(v, &rn.Inlines) } } func (v *zmkVisitor) visitHeading(hn *ast.HeadingNode) { @@ -222,17 +222,17 @@ func (v *zmkVisitor) visitNestedList(ln *ast.NestedListNode) { v.prefix = append(v.prefix, mapNestedListKind[ln.Kind]) for i, item := range ln.Items { if i > 0 { - v.b.WriteByte('\n') + v.b.WriteLn() } - v.b.Write(v.prefix) - v.b.WriteByte(' ') + _, _ = v.b.Write(v.prefix) + v.b.WriteSpace() for j, in := range item { if j > 0 { - v.b.WriteByte('\n') + v.b.WriteLn() if _, ok := in.(*ast.ParaNode); ok { v.writePrefixSpaces() } } ast.Walk(v, in) @@ -242,19 +242,19 @@ } func (v *zmkVisitor) writePrefixSpaces() { if prefixLen := len(v.prefix); prefixLen > 0 { for i := 0; i <= prefixLen; i++ { - v.b.WriteByte(' ') + v.b.WriteSpace() } } } func (v *zmkVisitor) visitDescriptionList(dn *ast.DescriptionListNode) { for i, descr := range dn.Descriptions { if i > 0 { - v.b.WriteByte('\n') + v.b.WriteLn() } v.b.WriteString("; ") ast.Walk(v, &descr.Term) for _, b := range descr.Descriptions { @@ -277,15 +277,15 @@ } func (v *zmkVisitor) visitTable(tn *ast.TableNode) { if header := tn.Header; len(header) > 0 { v.writeTableHeader(header, tn.Align) - v.b.WriteByte('\n') + v.b.WriteLn() } for i, row := range tn.Rows { if i > 0 { - v.b.WriteByte('\n') + v.b.WriteLn() } v.writeTableRow(row, tn.Align) } } @@ -303,11 +303,11 @@ } } func (v *zmkVisitor) writeTableRow(row ast.TableRow, align []ast.Alignment) { for pos, cell := range row { - v.b.WriteByte('|') + _ = v.b.WriteByte('|') if cell.Align != align[pos] { v.b.WriteString(alignCode[cell.Align]) } ast.Walk(v, &cell.Inlines) } @@ -314,16 +314,16 @@ } func (v *zmkVisitor) visitBLOB(bn *ast.BLOBNode) { if bn.Syntax == meta.ValueSyntaxSVG { v.b.WriteStrings("@@@", bn.Syntax, "\n") - v.b.Write(bn.Blob) + _, _ = v.b.Write(bn.Blob) v.b.WriteString("\n@@@\n") return } var sb strings.Builder - v.textEnc.WriteInlines(&sb, &bn.Description) + _, _ = v.textEnc.WriteInlines(&sb, &bn.Description) v.b.WriteStrings("%% Unable to display BLOB with description '", sb.String(), "' and syntax '", bn.Syntax, "'.") } var escapeSeqs = set.New( "\\", "__", "**", "~~", "^^", ",,", ">>", `""`, "::", "''", "``", "++", "==", "##", @@ -356,63 +356,63 @@ func (v *zmkVisitor) visitBreak(bn *ast.BreakNode) { if bn.Hard { v.b.WriteString("\\\n") } else { - v.b.WriteByte('\n') + v.b.WriteLn() } v.writePrefixSpaces() } func (v *zmkVisitor) visitLink(ln *ast.LinkNode) { v.b.WriteString("[[") if len(ln.Inlines) > 0 { ast.Walk(v, &ln.Inlines) - v.b.WriteByte('|') + _ = v.b.WriteByte('|') } if ln.Ref.State == ast.RefStateBased { - v.b.WriteByte('/') + _ = v.b.WriteByte('/') } v.b.WriteStrings(ln.Ref.String(), "]]") } func (v *zmkVisitor) visitEmbedRef(en *ast.EmbedRefNode) { v.b.WriteString("{{") if len(en.Inlines) > 0 { ast.Walk(v, &en.Inlines) - v.b.WriteByte('|') + _ = v.b.WriteByte('|') } v.b.WriteStrings(en.Ref.String(), "}}") } func (v *zmkVisitor) visitEmbedBLOB(en *ast.EmbedBLOBNode) { if en.Syntax == meta.ValueSyntaxSVG { v.b.WriteString("@@") - v.b.Write(en.Blob) + _, _ = v.b.Write(en.Blob) v.b.WriteStrings("@@{=", en.Syntax, "}") return } v.b.WriteString("{{TODO: display inline BLOB}}") } func (v *zmkVisitor) visitCite(cn *ast.CiteNode) { v.b.WriteStrings("[@", cn.Key) if len(cn.Inlines) > 0 { - v.b.WriteByte(' ') + v.b.WriteSpace() ast.Walk(v, &cn.Inlines) } - v.b.WriteByte(']') + _ = v.b.WriteByte(']') v.visitAttributes(cn.Attrs) } func (v *zmkVisitor) visitMark(mn *ast.MarkNode) { v.b.WriteStrings("[!", mn.Mark) if len(mn.Inlines) > 0 { - v.b.WriteByte('|') + _ = v.b.WriteByte('|') ast.Walk(v, &mn.Inlines) } - v.b.WriteByte(']') + _ = v.b.WriteByte(']') } var mapFormatKind = map[ast.FormatKind][]byte{ ast.FormatEmph: []byte("__"), @@ -429,13 +429,13 @@ func (v *zmkVisitor) visitFormat(fn *ast.FormatNode) { kind, ok := mapFormatKind[fn.Kind] if !ok { panic(fmt.Sprintf("Unknown format kind %d", fn.Kind)) } - v.b.Write(kind) + _, _ = v.b.Write(kind) ast.Walk(v, &fn.Inlines) - v.b.Write(kind) + _, _ = v.b.Write(kind) v.visitAttributes(fn.Attrs) } func (v *zmkVisitor) visitLiteral(ln *ast.LiteralNode) { switch ln.Kind { @@ -449,12 +449,12 @@ case ast.LiteralOutput: v.writeLiteral('=', ln.Attrs, ln.Content) case ast.LiteralComment: v.b.WriteString("%%") v.visitAttributes(ln.Attrs) - v.b.WriteByte(' ') - v.b.Write(ln.Content) + v.b.WriteSpace() + _, _ = v.b.Write(ln.Content) default: panic(fmt.Sprintf("Unknown literal kind %v", ln.Kind)) } } @@ -468,26 +468,26 @@ // visitAttributes write HTML attributes func (v *zmkVisitor) visitAttributes(a zsx.Attributes) { if a.IsEmpty() { return } - v.b.WriteByte('{') + _ = v.b.WriteByte('{') for i, k := range a.Keys() { if i > 0 { - v.b.WriteByte(' ') + v.b.WriteSpace() } if k == "-" { - v.b.WriteByte('-') + _ = v.b.WriteByte('-') continue } v.b.WriteString(k) if vl := a[k]; len(vl) > 0 { v.b.WriteStrings("=\"", vl) - v.b.WriteByte('"') + _ = v.b.WriteByte('"') } } - v.b.WriteByte('}') + _ = v.b.WriteByte('}') } func (v *zmkVisitor) writeEscaped(s string, toEscape byte) { last := 0 for i := range len(s) { Index: internal/evaluator/evaluator.go ================================================================== --- internal/evaluator/evaluator.go +++ internal/evaluator/evaluator.go @@ -67,11 +67,11 @@ rd := sxreader.MakeReader(bytes.NewReader(vn.Content)) if objs, err := rd.ReadAll(); err == nil { result := make(ast.BlockSlice, len(objs)) for i, obj := range objs { var buf bytes.Buffer - sxbuiltins.Print(&buf, obj) + _, _ = sxbuiltins.Print(&buf, obj) result[i] = &ast.VerbatimNode{ Kind: ast.VerbatimCode, Attrs: zsx.Attributes{"": classAttr}, Content: buf.Bytes(), } Index: internal/kernel/cfg.go ================================================================== --- internal/kernel/cfg.go +++ internal/kernel/cfg.go @@ -172,32 +172,40 @@ return err } m := z.Meta cs.mxService.Lock() for key := range cs.orig.All() { + var setErr error if val, ok := m.Get(key); ok { - cs.SetConfig(key, string(val)) + setErr = cs.SetConfig(key, string(val)) } else if defVal, defFound := cs.orig.Get(key); defFound { - cs.SetConfig(key, string(defVal)) + setErr = cs.SetConfig(key, string(defVal)) + } + if err == nil && setErr != nil && setErr != errAlreadyFrozen { + err = fmt.Errorf("%w (key=%q)", setErr, key) } } cs.mxService.Unlock() cs.SwitchNextToCur() // Poor man's restart - return nil + return err } func (cs *configService) observe(ci box.UpdateInfo) { if (ci.Reason != box.OnZettel && ci.Reason != box.OnDelete) || ci.Zid == id.ZidConfiguration { cs.logger.Debug().Uint("reason", uint64(ci.Reason)).Zid(ci.Zid).Msg("observe") go func() { cs.mxService.RLock() mgr := cs.manager cs.mxService.RUnlock() + var err error if mgr != nil { - cs.doUpdate(mgr) + err = cs.doUpdate(mgr) } else { - cs.doUpdate(ci.Box) + err = cs.doUpdate(ci.Box) + } + if err != nil { + cs.logger.Error().Err(err).Msg("update config") } }() } } Index: internal/kernel/cmd.go ================================================================== --- internal/kernel/cmd.go +++ internal/kernel/cmd.go @@ -60,17 +60,17 @@ return true } func (sess *cmdSession) println(args ...string) { if len(args) > 0 { - io.WriteString(sess.w, args[0]) + _, _ = io.WriteString(sess.w, args[0]) for _, arg := range args[1:] { - io.WriteString(sess.w, " ") - io.WriteString(sess.w, arg) + _, _ = io.WriteString(sess.w, " ") + _, _ = io.WriteString(sess.w, arg) } } - sess.w.Write(sess.eol) + _, _ = sess.w.Write(sess.eol) } func (sess *cmdSession) usage(cmd, val string) { sess.println("Usage:", cmd, val) } @@ -108,15 +108,15 @@ return maxLen } func (sess *cmdSession) printRow(row []string, maxLen []int, prefix, delim string, pad rune) { for colno, column := range row { - io.WriteString(sess.w, prefix) + _, _ = io.WriteString(sess.w, prefix) prefix = delim - io.WriteString(sess.w, strfun.JustifyLeft(column, maxLen[colno], pad)) + _, _ = io.WriteString(sess.w, strfun.JustifyLeft(column, maxLen[colno], pad)) } - sess.w.Write(sess.eol) + _, _ = sess.w.Write(sess.eol) } func splitLine(line string) (string, []string) { s := strings.Fields(line) if len(s) == 0 { @@ -502,11 +502,13 @@ } func cmdRefresh(sess *cmdSession, _ string, _ []string) bool { kern := sess.kern kern.logger.Mandatory().Msg("Refresh") - kern.box.Refresh() + if err := kern.box.Refresh(); err != nil { + kern.logger.Error().Err(err).Msg("refresh") + } return true } func cmdDumpRecover(sess *cmdSession, cmd string, args []string) bool { if len(args) == 0 { Index: internal/kernel/config.go ================================================================== --- internal/kernel/config.go +++ internal/kernel/config.go @@ -59,11 +59,11 @@ result = append(result, serviceConfigDescription{Key: k, Descr: text}) } return result } -var errAlreadyFrozen = errors.New("value not allowed to be set") +var errAlreadyFrozen = errors.New("value frozen") func (cfg *srvConfig) noFrozen(parse parseFunc) parseFunc { return func(val string) (any, error) { if cfg.frozen { return nil, errAlreadyFrozen Index: internal/kernel/kernel.go ================================================================== --- internal/kernel/kernel.go +++ internal/kernel/kernel.go @@ -204,10 +204,12 @@ // Constants for web service keys. const ( WebAssetDir = "asset-dir" WebBaseURL = "base-url" WebListenAddress = "listen" + WebLoopbackIdent = "loopback-ident" + WebLoopbackZid = "loopback-zid" WebPersistentCookie = "persistent" WebProfiling = "profiling" WebMaxRequestSize = "max-request-size" WebSecureCookie = "secure" WebTokenLifetimeAPI = "api-lifetime" @@ -253,13 +255,13 @@ ) // Setup sets the most basic data of a software: its name, its version, // and when the version was created. func (kern *Kernel) Setup(progname, version string, versionTime time.Time) { - kern.SetConfig(CoreService, CoreProgname, progname) - kern.SetConfig(CoreService, CoreVersion, version) - kern.SetConfig(CoreService, CoreVTime, versionTime.Local().Format(id.TimestampLayout)) + _ = kern.SetConfig(CoreService, CoreProgname, progname) + _ = kern.SetConfig(CoreService, CoreVersion, version) + _ = kern.SetConfig(CoreService, CoreVTime, versionTime.Local().Format(id.TimestampLayout)) } // Start the service. func (kern *Kernel) Start(headline, lineServer bool, configFilename string) { for _, srvD := range kern.srvs { @@ -278,11 +280,11 @@ } kern.doShutdown() kern.wg.Done() }() - kern.StartService(KernelService) + _ = kern.StartService(KernelService) if headline { logger := kern.logger logger.Mandatory().Msg(fmt.Sprintf( "%v %v (%v@%v/%v)", kern.core.GetCurConfig(CoreProgname), @@ -308,11 +310,11 @@ } if lineServer { port := kern.core.GetNextConfig(CorePort).(int) if port > 0 { listenAddr := net.JoinHostPort("127.0.0.1", strconv.Itoa(port)) - startLineServer(kern, listenAddr) + _ = startLineServer(kern, listenAddr) } } } func (kern *Kernel) doShutdown() { @@ -320,11 +322,11 @@ } // WaitForShutdown blocks the call until Shutdown is called. func (kern *Kernel) WaitForShutdown() { kern.wg.Wait() - kern.doStopProfiling() + _ = kern.doStopProfiling() } // --- Shutdown operation ---------------------------------------------------- // Shutdown the service. Waits for all concurrent activities to stop. @@ -439,13 +441,12 @@ if profileName == ProfileCPU { f, err := os.Create(fileName) if err != nil { return err } - err = pprof.StartCPUProfile(f) - if err != nil { - f.Close() + if err = pprof.StartCPUProfile(f); err != nil { + _ = f.Close() return err } kern.profileName = profileName kern.fileName = fileName kern.profileFile = f @@ -462,12 +463,11 @@ kern.profileName = profileName kern.fileName = fileName kern.profile = profile kern.profileFile = f runtime.GC() // get up-to-date statistics - profile.WriteTo(f, 0) - return nil + return profile.WriteTo(f, 0) } // StopProfiling stops the current profiling and writes the result to // the file, which was named during StartProfiling(). // It will always be called before the software stops its operations. Index: internal/kernel/server.go ================================================================== --- internal/kernel/server.go +++ internal/kernel/server.go @@ -45,11 +45,11 @@ kern.logger.Error().Err(err).Msg("Unable to accept connection") break } go handleLineConnection(conn, kern) } - ln.Close() + _ = ln.Close() } func handleLineConnection(conn net.Conn, kern *Kernel) { // Something may panic. Ensure a running connection. defer func() { @@ -67,7 +67,7 @@ line := s.Text() if !cmds.executeLine(line) { break } } - conn.Close() + _ = conn.Close() } Index: internal/kernel/web.go ================================================================== --- internal/kernel/web.go +++ internal/kernel/web.go @@ -22,10 +22,12 @@ "path/filepath" "strconv" "strings" "sync" "time" + + "t73f.de/r/zsc/domain/id" "zettelstore.de/z/internal/logger" "zettelstore.de/z/internal/web/server" ) @@ -76,10 +78,12 @@ return "", err } return ap.String(), nil }, true}, + WebLoopbackIdent: {"Loopback user ident", ws.noFrozen(parseString), true}, + WebLoopbackZid: {"Loopback user zettel identifier", ws.noFrozen(parseInvalidZid), true}, WebMaxRequestSize: {"Max Request Size", parseInt64, true}, WebPersistentCookie: {"Persistent cookie", parseBool, true}, WebProfiling: {"Runtime profiling", parseBool, true}, WebSecureCookie: {"Secure cookie", parseBool, true}, WebTokenLifetimeAPI: { @@ -105,10 +109,12 @@ } ws.next = interfaceMap{ WebAssetDir: "", WebBaseURL: "http://127.0.0.1:23123/", WebListenAddress: "127.0.0.1:23123", + WebLoopbackIdent: "", + WebLoopbackZid: id.Invalid, WebMaxRequestSize: int64(16 * 1024 * 1024), WebPersistentCookie: false, WebSecureCookie: true, WebProfiling: false, WebTokenLifetimeAPI: 1 * time.Hour, @@ -138,10 +144,12 @@ func (ws *webService) GetLogger() *logger.Logger { return ws.logger } func (ws *webService) Start(kern *Kernel) error { baseURL := ws.GetNextConfig(WebBaseURL).(string) listenAddr := ws.GetNextConfig(WebListenAddress).(string) + loopbackIdent := ws.GetNextConfig(WebLoopbackIdent).(string) + loopbackZid := ws.GetNextConfig(WebLoopbackZid).(id.Zid) urlPrefix := ws.GetNextConfig(WebURLPrefix).(string) persistentCookie := ws.GetNextConfig(WebPersistentCookie).(bool) secureCookie := ws.GetNextConfig(WebSecureCookie).(bool) profile := ws.GetNextConfig(WebProfiling).(bool) maxRequestSize := max(ws.GetNextConfig(WebMaxRequestSize).(int64), 1024) @@ -161,10 +169,12 @@ ListenAddr: listenAddr, BaseURL: baseURL, URLPrefix: urlPrefix, MaxRequestSize: maxRequestSize, Auth: kern.auth.manager, + LoopbackIdent: loopbackIdent, + LoopbackZid: loopbackZid, PersistentCookie: persistentCookie, SecureCookie: secureCookie, Profiling: profile, } srvw := server.New(sd) Index: internal/logger/message.go ================================================================== --- internal/logger/message.go +++ internal/logger/message.go @@ -17,10 +17,11 @@ "context" "net/http" "strconv" "sync" + "t73f.de/r/webs/ip" "t73f.de/r/zsc/domain/id" "t73f.de/r/zsc/domain/meta" ) // Message presents a message to log. @@ -125,19 +126,17 @@ } } return m } -// HTTPIP adds the IP address of a HTTP request to the message. -func (m *Message) HTTPIP(r *http.Request) *Message { - if r == nil { +// RemoteAddr adds the remote address of an HTTP request to the message. +func (m *Message) RemoteAddr(r *http.Request) *Message { + addr := ip.GetRemoteAddr(r) + if addr == "" { return m } - if from := r.Header.Get("X-Forwarded-For"); from != "" { - return m.Str("ip", from) - } - return m.Str("IP", r.RemoteAddr) + return m.Str("remote", addr) } // Zid adds a zettel identifier to the full message func (m *Message) Zid(zid id.Zid) *Message { return m.Bytes("zid", zid.Bytes()) @@ -144,14 +143,14 @@ } // Msg add the given text to the message and writes it to the log. func (m *Message) Msg(text string) { if m.Enabled() { - m.logger.writeMessage(m.level, text, m.buf) + _ = m.logger.writeMessage(m.level, text, m.buf) recycleMessage(m) } } // Child creates a child logger with context of this message. func (m *Message) Child() *Logger { return newFromMessage(m) } Index: internal/parser/cleaner.go ================================================================== --- internal/parser/cleaner.go +++ internal/parser/cleaner.go @@ -161,46 +161,5 @@ } } cv.ids[id] = node return id } - -// CleanInlineLinks removes all links and footnote node from the given inline slice. -func CleanInlineLinks(is *ast.InlineSlice) { ast.Walk(&cleanLinks{}, is) } - -type cleanLinks struct{} - -func (cl *cleanLinks) Visit(node ast.Node) ast.Visitor { - ins, ok := node.(*ast.InlineSlice) - if !ok { - return cl - } - for _, in := range *ins { - ast.Walk(cl, in) - } - if hasNoLinks(*ins) { - return nil - } - - result := make(ast.InlineSlice, 0, len(*ins)) - for _, in := range *ins { - switch n := in.(type) { - case *ast.LinkNode: - result = append(result, n.Inlines...) - case *ast.FootnoteNode: // Do nothing - default: - result = append(result, n) - } - } - *ins = result - return nil -} - -func hasNoLinks(ins ast.InlineSlice) bool { - for _, in := range ins { - switch in.(type) { - case *ast.LinkNode, *ast.FootnoteNode: - return false - } - } - return true -} Index: internal/query/print.go ================================================================== --- internal/query/print.go +++ internal/query/print.go @@ -94,20 +94,20 @@ var bsSpace = []byte{' '} func (pe *PrintEnv) printSpace() { if pe.space { - pe.w.Write(bsSpace) + _, _ = pe.w.Write(bsSpace) return } pe.space = true } -func (pe *PrintEnv) write(ch byte) { pe.w.Write([]byte{ch}) } -func (pe *PrintEnv) writeString(s string) { io.WriteString(pe.w, s) } +func (pe *PrintEnv) write(ch byte) { _, _ = pe.w.Write([]byte{ch}) } +func (pe *PrintEnv) writeString(s string) { _, _ = io.WriteString(pe.w, s) } func (pe *PrintEnv) writeStrings(sSeq ...string) { for _, s := range sSeq { - io.WriteString(pe.w, s) + _, _ = io.WriteString(pe.w, s) } } func (pe *PrintEnv) printZids(zids []id.Zid) { for i, zid := range zids { Index: internal/usecase/authenticate.go ================================================================== --- internal/usecase/authenticate.go +++ internal/usecase/authenticate.go @@ -50,19 +50,19 @@ func (uc *Authenticate) Run(ctx context.Context, r *http.Request, ident, credential string, d time.Duration, k auth.TokenKind) ([]byte, error) { identMeta, err := uc.ucGetUser.Run(ctx, ident) defer addDelay(time.Now(), 500*time.Millisecond, 100*time.Millisecond) if identMeta == nil || err != nil { - uc.log.Info().Str("ident", ident).Err(err).HTTPIP(r).Msg("No user with given ident found") + uc.log.Info().Str("ident", ident).Err(err).RemoteAddr(r).Msg("No user with given ident found") compensateCompare() return nil, err } if hashCred, ok := identMeta.Get(meta.KeyCredential); ok { ok, err = cred.CompareHashAndCredential(string(hashCred), identMeta.Zid, ident, credential) if err != nil { - uc.log.Info().Str("ident", ident).Err(err).HTTPIP(r).Msg("Error while comparing credentials") + uc.log.Info().Str("ident", ident).Err(err).RemoteAddr(r).Msg("Error while comparing credentials") return nil, err } if ok { token, err2 := uc.token.GetToken(identMeta, d, k) if err2 != nil { @@ -70,21 +70,21 @@ return nil, err2 } uc.log.Info().Str("user", ident).Msg("Successful") return token, nil } - uc.log.Info().Str("ident", ident).HTTPIP(r).Msg("Credentials don't match") + uc.log.Info().Str("ident", ident).RemoteAddr(r).Msg("Credentials don't match") return nil, nil } uc.log.Info().Str("ident", ident).Msg("No credential stored") compensateCompare() return nil, nil } // compensateCompare if normal comapare is not possible, to avoid timing hints. func compensateCompare() { - cred.CompareHashAndCredential( + _, _ = cred.CompareHashAndCredential( "$2a$10$WHcSO3G9afJ3zlOYQR1suuf83bCXED2jmzjti/MH4YH4l2mivDuze", id.Invalid, "", "") } // addDelay after credential checking to allow some CPU time for other tasks. // durDelay is the normal delay, if time spend for checking is smaller than Index: internal/web/adapter/api/request.go ================================================================== --- internal/web/adapter/api/request.go +++ internal/web/adapter/api/request.go @@ -83,31 +83,12 @@ return part } return defPart } -func (p partType) String() string { - switch p { - case partMeta: - return "meta" - case partContent: - return "content" - case partZettel: - return "zettel" - } - return "" -} - -func (p partType) DefString(defPart partType) string { - if p == defPart { - return "" - } - return p.String() -} - func buildZettelFromPlainData(r *http.Request, zid id.Zid) (zettel.Zettel, error) { - defer r.Body.Close() + defer func() { _ = r.Body.Close() }() b, err := io.ReadAll(r.Body) if err != nil { return zettel.Zettel{}, err } inp := input.NewInput(b) @@ -117,11 +98,11 @@ Content: zettel.NewContent(inp.Src[inp.Pos:]), }, nil } func buildZettelFromData(r *http.Request, zid id.Zid) (zettel.Zettel, error) { - defer r.Body.Close() + defer func() { _ = r.Body.Close() }() rdr := sxreader.MakeReader(r.Body) obj, err := rdr.Read() if err != nil { return zettel.Zettel{}, err } Index: internal/web/adapter/webui/favicon.go ================================================================== --- internal/web/adapter/webui/favicon.go +++ internal/web/adapter/webui/favicon.go @@ -30,11 +30,11 @@ if err != nil { wui.log.Debug().Err(err).Msg("Favicon not found") http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) return } - defer f.Close() + defer func() { _ = f.Close() }() data, err := io.ReadAll(f) if err != nil { wui.log.Error().Err(err).Msg("Unable to read favicon data") http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) Index: internal/web/adapter/webui/forms.go ================================================================== --- internal/web/adapter/webui/forms.go +++ internal/web/adapter/webui/forms.go @@ -105,11 +105,11 @@ } func uploadedContent(r *http.Request, m *meta.Meta) ([]byte, *meta.Meta) { file, fh, err := r.FormFile("file") if file != nil { - defer file.Close() + defer func() { _ = file.Close() }() if err == nil { data, err2 := io.ReadAll(file) if err2 != nil { return nil, m } Index: internal/web/adapter/webui/htmlgen.go ================================================================== --- internal/web/adapter/webui/htmlgen.go +++ internal/web/adapter/webui/htmlgen.go @@ -273,18 +273,10 @@ return nil, nil, err } return sh, shtml.Endnotes(&env), nil } -// InlinesSxHTML returns an inline slice, encoded as a SxHTML object. -func (g *htmlGenerator) InlinesSxHTML(is *ast.InlineSlice) *sx.Pair { - if is == nil || len(*is) == 0 { - return nil - } - return g.nodeSxHTML(is) -} - func (g *htmlGenerator) nodeSxHTML(node ast.Node) *sx.Pair { sz := g.tx.GetSz(node) env := shtml.MakeEnvironment(g.lang) sh, err := g.th.Evaluate(sz, &env) if err != nil { Index: internal/web/adapter/webui/htmlmeta.go ================================================================== --- internal/web/adapter/webui/htmlmeta.go +++ internal/web/adapter/webui/htmlmeta.go @@ -112,13 +112,14 @@ return nil } func (wui *WebUI) transformTagSet(key string, tags []string) *sx.Pair { var lb sx.ListBuilder - lb.Add(shtml.SymSPAN) for i, tag := range tags { - if i > 0 { + if i == 0 { + lb.Add(shtml.SymSPAN) + } else if i > 0 { lb.Add(space) } lb.Add(wui.transformKeyValueText(key, meta.Value(tag), tag)) } if len(tags) > 1 { Index: internal/web/adapter/webui/sxn_code.go ================================================================== --- internal/web/adapter/webui/sxn_code.go +++ internal/web/adapter/webui/sxn_code.go @@ -38,11 +38,10 @@ dg := buildSxnCodeDigraph(ctx, id.ZidSxnStart, getMeta) if dg == nil { return nil, wui.rootBinding, nil } dg = dg.AddVertex(id.ZidSxnBase).AddEdge(id.ZidSxnStart, id.ZidSxnBase) - dg = dg.AddVertex(id.ZidSxnPrelude).AddEdge(id.ZidSxnBase, id.ZidSxnPrelude) dg = dg.TransitiveClosure(id.ZidSxnStart) if zid, isDAG := dg.IsDAG(); !isDAG { return nil, nil, fmt.Errorf("zettel %v is part of a dependency cycle", zid) } Index: internal/web/adapter/webui/template.go ================================================================== --- internal/web/adapter/webui/template.go +++ internal/web/adapter/webui/template.go @@ -39,15 +39,14 @@ "zettelstore.de/z/internal/web/server" "zettelstore.de/z/internal/zettel" ) func (wui *WebUI) createRenderBinding() *sxeval.Binding { - root := sxeval.MakeRootBinding(len(specials) + len(builtins) + 3) + root := sxeval.MakeRootBinding(len(specials) + len(builtins) + 32) + _ = sxbuiltins.LoadPrelude(root) _ = sxeval.BindSpecials(root, specials...) _ = sxeval.BindBuiltins(root, builtins...) - _ = root.Bind(sx.MakeSymbol("NIL"), sx.Nil()) - _ = root.Bind(sx.MakeSymbol("T"), sx.MakeSymbol("T")) _ = sxeval.BindBuiltins(root, &sxeval.Builtin{ Name: "url-to-html", MinArity: 1, MaxArity: 1, @@ -100,15 +99,16 @@ specials = []*sxeval.Special{ &sxbuiltins.QuoteS, &sxbuiltins.QuasiquoteS, // quote, quasiquote &sxbuiltins.UnquoteS, &sxbuiltins.UnquoteSplicingS, // unquote, unquote-splicing &sxbuiltins.DefVarS, // defvar &sxbuiltins.DefunS, &sxbuiltins.LambdaS, // defun, lambda - &sxbuiltins.SetXS, // set! - &sxbuiltins.IfS, // if - &sxbuiltins.BeginS, // begin - &sxbuiltins.DefMacroS, // defmacro - &sxbuiltins.LetS, // let + &sxbuiltins.SetXS, // set! + &sxbuiltins.IfS, // if + &sxbuiltins.BeginS, // begin + &sxbuiltins.DefMacroS, // defmacro + &sxbuiltins.LetS, &sxbuiltins.LetStarS, // let, let* + &sxbuiltins.AndS, &sxbuiltins.OrS, // and, or } builtins = []*sxeval.Builtin{ &sxbuiltins.Equal, // = &sxbuiltins.NumGreater, // > &sxbuiltins.NullP, // null? @@ -407,11 +407,13 @@ func (wui *WebUI) renderSxnTemplateStatus(ctx context.Context, w http.ResponseWriter, code int, templateID id.Zid, bind *sxeval.Binding) error { detailObj, err := wui.evalSxnTemplate(ctx, templateID, bind) if err != nil { return err } - bind.Bind(symDetail, detailObj) + if err = bind.Bind(symDetail, detailObj); err != nil { + return err + } pageObj, err := wui.evalSxnTemplate(ctx, id.ZidBaseTemplate, bind) if err != nil { return err } @@ -454,11 +456,11 @@ } wui.log.Error().Err(errSx).Msg("while rendering error message") // if errBind != nil, the HTTP header was not written wui.prepareAndWriteHeader(w, http.StatusInternalServerError) - fmt.Fprintf( + _, _ = fmt.Fprintf( w, `