Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Comment: | Add revive tool to tools; add some missing comments |
---|---|
Timelines: | family | ancestors | trunk |
Files: | files | file ages | folders |
SHA3-256: |
a64decfa473befc6cfa470a816e310ce |
User & Date: | stern 2024-09-27 16:35:04 |
2024-09-27
| ||
16:35 | Add revive tool to tools; add some missing comments ... (Leaf check-in: a64decfa47 user: stern tags: trunk) | |
16:05 | Refactor to make revive tool happy (and me) ... (check-in: 6f8452996b user: stern tags: trunk) | |
Changes to box/manager/manager.go.
︙ | ︙ | |||
123 124 125 126 127 128 129 130 131 132 133 134 135 136 | func (mgr *Manager) setState(newState box.StartState) { mgr.stateMx.Lock() mgr.state = newState mgr.stateMx.Unlock() } func (mgr *Manager) State() box.StartState { mgr.stateMx.RLock() state := mgr.state mgr.stateMx.RUnlock() return state } | > | 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | func (mgr *Manager) setState(newState box.StartState) { mgr.stateMx.Lock() mgr.state = newState mgr.stateMx.Unlock() } // State returns the box.StartState of the manager. func (mgr *Manager) State() box.StartState { mgr.stateMx.RLock() state := mgr.state mgr.stateMx.RUnlock() return state } |
︙ | ︙ | |||
151 152 153 154 155 156 157 | propertyKeys: propertyKeys, idxLog: boxLog.Clone().Str("box", "index").Child(), idxStore: createIdxStore(rtConfig), idxAr: newAnteroomQueue(1000), idxReady: make(chan struct{}, 1), } | | | 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | propertyKeys: propertyKeys, idxLog: boxLog.Clone().Str("box", "index").Child(), idxStore: createIdxStore(rtConfig), idxAr: newAnteroomQueue(1000), idxReady: make(chan struct{}, 1), } mgr.zidMapper = newZidMapper(mgr) cdata := ConnectData{Number: 1, Config: rtConfig, Enricher: mgr, Notify: mgr.notifyChanged, Mapper: mgr.zidMapper} boxes := make([]box.ManagedBox, 0, len(boxURIs)+2) for _, uri := range boxURIs { p, err := Connect(uri, authManager, &cdata) if err != nil { return nil, err |
︙ | ︙ |
Changes to box/manager/zidmapper.go.
︙ | ︙ | |||
42 43 44 45 46 47 48 | nextZidN id.ZidN // next zid for normal zettel } type zidfetcher interface { fetchZids(context.Context) (*id.Set, error) } | | | | 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | nextZidN id.ZidN // next zid for normal zettel } type zidfetcher interface { fetchZids(context.Context) (*id.Set, error) } // newZidMapper creates a new ZipMapper. func newZidMapper(fetcher zidfetcher) *zidMapper { defined := map[id.Zid]id.ZidN{ id.Invalid: id.InvalidN, 1: id.MustParseN("0001"), // ZidVersion 2: id.MustParseN("0002"), // ZidHost 3: id.MustParseN("0003"), // ZidOperatingSystem 4: id.MustParseN("0004"), // ZidLicense 5: id.MustParseN("0005"), // ZidAuthors |
︙ | ︙ |
Changes to docs/development/20210916193200.zettel.
︙ | ︙ | |||
21 22 23 24 25 26 27 28 | It can be installed / updated via the build tool itself: ``go run tools/devtools/devtools.go``. Otherwise you can install the software by hand: * [[shadow|https://pkg.go.dev/golang.org/x/tools/go/analysis/passes/shadow]] via ``go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow@latest``, * [[staticcheck|https://staticcheck.io/]] via ``go install honnef.co/go/tools/cmd/staticcheck@latest``, * [[unparam|https://mvdan.cc/unparam]][^[[GitHub|https://github.com/mvdan/unparam]]] via ``go install mvdan.cc/unparam@latest``, * [[govulncheck|https://golang.org/x/vuln/cmd/govulncheck]] via ``go install golang.org/x/vuln/cmd/govulncheck@latest``, | > | 21 22 23 24 25 26 27 28 29 | It can be installed / updated via the build tool itself: ``go run tools/devtools/devtools.go``. Otherwise you can install the software by hand: * [[shadow|https://pkg.go.dev/golang.org/x/tools/go/analysis/passes/shadow]] via ``go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow@latest``, * [[staticcheck|https://staticcheck.io/]] via ``go install honnef.co/go/tools/cmd/staticcheck@latest``, * [[unparam|https://mvdan.cc/unparam]][^[[GitHub|https://github.com/mvdan/unparam]]] via ``go install mvdan.cc/unparam@latest``, * [[revive|https://revive.run]] via ``go install github.com/mgechev/revive@vlatest``, * [[govulncheck|https://golang.org/x/vuln/cmd/govulncheck]] via ``go install golang.org/x/vuln/cmd/govulncheck@latest``, |
Changes to encoder/htmlenc/htmlenc.go.
︙ | ︙ | |||
45 46 47 48 49 50 51 52 53 54 55 56 57 58 | tx: szenc.NewTransformer(), th: shtml.NewEvaluator(1), lang: params.Lang, textEnc: textenc.Create(), } } type Encoder struct { tx *szenc.Transformer th *shtml.Evaluator lang string textEnc *textenc.Encoder } | > | 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | tx: szenc.NewTransformer(), th: shtml.NewEvaluator(1), lang: params.Lang, textEnc: textenc.Create(), } } // Encoder contains all data needed for encoding. type Encoder struct { tx *szenc.Transformer th *shtml.Evaluator lang string textEnc *textenc.Encoder } |
︙ | ︙ | |||
122 123 124 125 126 127 128 129 130 131 132 133 134 135 | if err != nil { return 0, err } gen := sxhtml.NewGenerator().SetNewline() return gen.WriteListHTML(w, hm) } func (he *Encoder) WriteContent(w io.Writer, zn *ast.ZettelNode) (int, error) { return he.WriteBlocks(w, &zn.Ast) } // WriteBlocks encodes a block slice. func (he *Encoder) WriteBlocks(w io.Writer, bs *ast.BlockSlice) (int, error) { env := shtml.MakeEnvironment(he.lang) | > | 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | if err != nil { return 0, err } gen := sxhtml.NewGenerator().SetNewline() return gen.WriteListHTML(w, hm) } // WriteContent encodes the zettel content. func (he *Encoder) WriteContent(w io.Writer, zn *ast.ZettelNode) (int, error) { return he.WriteBlocks(w, &zn.Ast) } // WriteBlocks encodes a block slice. func (he *Encoder) WriteBlocks(w io.Writer, bs *ast.BlockSlice) (int, error) { env := shtml.MakeEnvironment(he.lang) |
︙ | ︙ |
Changes to encoder/mdenc/mdenc.go.
︙ | ︙ | |||
33 34 35 36 37 38 39 40 41 42 43 44 45 46 | } // Create an encoder. func Create(params *encoder.CreateParameter) *Encoder { return &Encoder{lang: params.Lang} } type Encoder struct { lang string } // WriteZettel writes the encoded zettel to the writer. func (me *Encoder) WriteZettel(w io.Writer, zn *ast.ZettelNode, evalMeta encoder.EvalMetaFunc) (int, error) { v := newVisitor(w, me.lang) | > | 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | } // Create an encoder. func Create(params *encoder.CreateParameter) *Encoder { return &Encoder{lang: params.Lang} } // Encoder contains all data needed for encoding. type Encoder struct { lang string } // WriteZettel writes the encoded zettel to the writer. func (me *Encoder) WriteZettel(w io.Writer, zn *ast.ZettelNode, evalMeta encoder.EvalMetaFunc) (int, error) { v := newVisitor(w, me.lang) |
︙ | ︙ | |||
73 74 75 76 77 78 79 80 81 82 83 84 85 86 | } else { v.b.WriteString(p.Value) } v.b.WriteByte('\n') } } func (me *Encoder) WriteContent(w io.Writer, zn *ast.ZettelNode) (int, error) { return me.WriteBlocks(w, &zn.Ast) } // WriteBlocks writes the content of a block slice to the writer. func (me *Encoder) WriteBlocks(w io.Writer, bs *ast.BlockSlice) (int, error) { v := newVisitor(w, me.lang) | > | 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | } else { v.b.WriteString(p.Value) } v.b.WriteByte('\n') } } // WriteContent encodes the zettel content. func (me *Encoder) WriteContent(w io.Writer, zn *ast.ZettelNode) (int, error) { return me.WriteBlocks(w, &zn.Ast) } // WriteBlocks writes the content of a block slice to the writer. func (me *Encoder) WriteBlocks(w io.Writer, bs *ast.BlockSlice) (int, error) { v := newVisitor(w, me.lang) |
︙ | ︙ |
Changes to encoder/shtmlenc/shtmlenc.go.
︙ | ︙ | |||
37 38 39 40 41 42 43 44 45 46 47 48 49 50 | return &Encoder{ tx: szenc.NewTransformer(), th: shtml.NewEvaluator(1), lang: params.Lang, } } type Encoder struct { tx *szenc.Transformer th *shtml.Evaluator lang string } // WriteZettel writes the encoded zettel to the writer. | > | 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | return &Encoder{ tx: szenc.NewTransformer(), th: shtml.NewEvaluator(1), lang: params.Lang, } } // Encoder contains all data needed for encoding. type Encoder struct { tx *szenc.Transformer th *shtml.Evaluator lang string } // WriteZettel writes the encoded zettel to the writer. |
︙ | ︙ | |||
68 69 70 71 72 73 74 75 76 77 78 79 80 81 | metaSHTML, err := enc.th.Evaluate(enc.tx.GetMeta(m, evalMeta), &env) if err != nil { return 0, err } return sx.Print(w, metaSHTML) } func (enc *Encoder) WriteContent(w io.Writer, zn *ast.ZettelNode) (int, error) { return enc.WriteBlocks(w, &zn.Ast) } // WriteBlocks writes a block slice to the writer func (enc *Encoder) WriteBlocks(w io.Writer, bs *ast.BlockSlice) (int, error) { env := shtml.MakeEnvironment(enc.lang) | > | 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | metaSHTML, err := enc.th.Evaluate(enc.tx.GetMeta(m, evalMeta), &env) if err != nil { return 0, err } return sx.Print(w, metaSHTML) } // WriteContent encodes the zettel content. func (enc *Encoder) WriteContent(w io.Writer, zn *ast.ZettelNode) (int, error) { return enc.WriteBlocks(w, &zn.Ast) } // WriteBlocks writes a block slice to the writer func (enc *Encoder) WriteBlocks(w io.Writer, bs *ast.BlockSlice) (int, error) { env := shtml.MakeEnvironment(enc.lang) |
︙ | ︙ |
Changes to encoder/szenc/szenc.go.
︙ | ︙ | |||
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | // Create a S-expr encoder func Create() *Encoder { // We need a new transformer every time, because trans.inVerse must be unique. // If we can refactor it out, the transformer can be created only once. return &Encoder{trans: NewTransformer()} } type Encoder struct { trans *Transformer } // WriteZettel writes the encoded zettel to the writer. func (enc *Encoder) WriteZettel(w io.Writer, zn *ast.ZettelNode, evalMeta encoder.EvalMetaFunc) (int, error) { content := enc.trans.GetSz(&zn.Ast) meta := enc.trans.GetMeta(zn.InhMeta, evalMeta) return sx.MakeList(meta, content).Print(w) } // WriteMeta encodes meta data as s-expression. func (enc *Encoder) WriteMeta(w io.Writer, m *meta.Meta, evalMeta encoder.EvalMetaFunc) (int, error) { return enc.trans.GetMeta(m, evalMeta).Print(w) } func (enc *Encoder) WriteContent(w io.Writer, zn *ast.ZettelNode) (int, error) { return enc.WriteBlocks(w, &zn.Ast) } // WriteBlocks writes a block slice to the writer func (enc *Encoder) WriteBlocks(w io.Writer, bs *ast.BlockSlice) (int, error) { return enc.trans.GetSz(bs).Print(w) } // WriteInlines writes an inline slice to the writer func (enc *Encoder) WriteInlines(w io.Writer, is *ast.InlineSlice) (int, error) { return enc.trans.GetSz(is).Print(w) } | > > | 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | // Create a S-expr encoder func Create() *Encoder { // We need a new transformer every time, because trans.inVerse must be unique. // If we can refactor it out, the transformer can be created only once. return &Encoder{trans: NewTransformer()} } // Encoder contains all data needed for encoding. type Encoder struct { trans *Transformer } // WriteZettel writes the encoded zettel to the writer. func (enc *Encoder) WriteZettel(w io.Writer, zn *ast.ZettelNode, evalMeta encoder.EvalMetaFunc) (int, error) { content := enc.trans.GetSz(&zn.Ast) meta := enc.trans.GetMeta(zn.InhMeta, evalMeta) return sx.MakeList(meta, content).Print(w) } // WriteMeta encodes meta data as s-expression. func (enc *Encoder) WriteMeta(w io.Writer, m *meta.Meta, evalMeta encoder.EvalMetaFunc) (int, error) { return enc.trans.GetMeta(m, evalMeta).Print(w) } // WriteContent encodes the zettel content. func (enc *Encoder) WriteContent(w io.Writer, zn *ast.ZettelNode) (int, error) { return enc.WriteBlocks(w, &zn.Ast) } // WriteBlocks writes a block slice to the writer func (enc *Encoder) WriteBlocks(w io.Writer, bs *ast.BlockSlice) (int, error) { return enc.trans.GetSz(bs).Print(w) } // WriteInlines writes an inline slice to the writer func (enc *Encoder) WriteInlines(w io.Writer, is *ast.InlineSlice) (int, error) { return enc.trans.GetSz(is).Print(w) } |
Changes to encoder/szenc/transform.go.
︙ | ︙ | |||
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | // NewTransformer returns a new transformer to create s-expressions from AST nodes. func NewTransformer() *Transformer { t := Transformer{} return &t } type Transformer struct { inVerse bool } func (t *Transformer) GetSz(node ast.Node) *sx.Pair { switch n := node.(type) { case *ast.BlockSlice: return t.getBlockList(n).Cons(sz.SymBlock) case *ast.InlineSlice: return t.getInlineList(*n).Cons(sz.SymInline) case *ast.ParaNode: | > > | 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | // NewTransformer returns a new transformer to create s-expressions from AST nodes. func NewTransformer() *Transformer { t := Transformer{} return &t } // Transformer contains all data needed to transform into a s-expression. type Transformer struct { inVerse bool } // GetSz transforms the given node into a sx list. func (t *Transformer) GetSz(node ast.Node) *sx.Pair { switch n := node.(type) { case *ast.BlockSlice: return t.getBlockList(n).Cons(sz.SymBlock) case *ast.InlineSlice: return t.getInlineList(*n).Cons(sz.SymInline) case *ast.ParaNode: |
︙ | ︙ | |||
357 358 359 360 361 362 363 364 365 366 367 368 369 370 | meta.TypeTagSet: sz.SymTypeTagSet, meta.TypeTimestamp: sz.SymTypeTimestamp, meta.TypeURL: sz.SymTypeURL, meta.TypeWord: sz.SymTypeWord, meta.TypeZettelmarkup: sz.SymTypeZettelmarkup, } func (t *Transformer) GetMeta(m *meta.Meta, evalMeta encoder.EvalMetaFunc) *sx.Pair { pairs := m.ComputedPairs() objs := make(sx.Vector, 0, len(pairs)) for _, p := range pairs { key := p.Key ty := m.Type(key) symType := mapGetS(mapMetaTypeS, ty) | > | 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 | meta.TypeTagSet: sz.SymTypeTagSet, meta.TypeTimestamp: sz.SymTypeTimestamp, meta.TypeURL: sz.SymTypeURL, meta.TypeWord: sz.SymTypeWord, meta.TypeZettelmarkup: sz.SymTypeZettelmarkup, } // GetMeta transforms the given metadata into a sx list. func (t *Transformer) GetMeta(m *meta.Meta, evalMeta encoder.EvalMetaFunc) *sx.Pair { pairs := m.ComputedPairs() objs := make(sx.Vector, 0, len(pairs)) for _, p := range pairs { key := p.Key ty := m.Type(key) symType := mapGetS(mapMetaTypeS, ty) |
︙ | ︙ |
Changes to encoder/textenc/textenc.go.
︙ | ︙ | |||
27 28 29 30 31 32 33 34 35 36 37 38 39 40 | func init() { encoder.Register(api.EncoderText, func(*encoder.CreateParameter) encoder.Encoder { return Create() }) } // Create an encoder. func Create() *Encoder { return &myTE } type Encoder struct{} var myTE Encoder // Only a singleton is required. // WriteZettel writes metadata and content. func (te *Encoder) WriteZettel(w io.Writer, zn *ast.ZettelNode, evalMeta encoder.EvalMetaFunc) (int, error) { v := newVisitor(w) | > | 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | func init() { encoder.Register(api.EncoderText, func(*encoder.CreateParameter) encoder.Encoder { return Create() }) } // Create an encoder. func Create() *Encoder { return &myTE } // Encoder contains all data needed for encoding. type Encoder struct{} var myTE Encoder // Only a singleton is required. // WriteZettel writes metadata and content. func (te *Encoder) WriteZettel(w io.Writer, zn *ast.ZettelNode, evalMeta encoder.EvalMetaFunc) (int, error) { v := newVisitor(w) |
︙ | ︙ | |||
69 70 71 72 73 74 75 76 77 78 79 80 81 82 | buf.WriteByte(' ') } buf.WriteString(meta.CleanTag(tag)) } } func (te *Encoder) WriteContent(w io.Writer, zn *ast.ZettelNode) (int, error) { return te.WriteBlocks(w, &zn.Ast) } // WriteBlocks writes the content of a block slice to the writer. func (*Encoder) WriteBlocks(w io.Writer, bs *ast.BlockSlice) (int, error) { v := newVisitor(w) | > | 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | buf.WriteByte(' ') } buf.WriteString(meta.CleanTag(tag)) } } // WriteContent encodes the zettel content. func (te *Encoder) WriteContent(w io.Writer, zn *ast.ZettelNode) (int, error) { return te.WriteBlocks(w, &zn.Ast) } // WriteBlocks writes the content of a block slice to the writer. func (*Encoder) WriteBlocks(w io.Writer, bs *ast.BlockSlice) (int, error) { v := newVisitor(w) |
︙ | ︙ |
Changes to encoder/zmkenc/zmkenc.go.
︙ | ︙ | |||
31 32 33 34 35 36 37 38 39 40 41 42 43 44 | func init() { encoder.Register(api.EncoderZmk, func(*encoder.CreateParameter) encoder.Encoder { return Create() }) } // Create an encoder. func Create() *Encoder { return &myZE } type Encoder struct{} var myZE Encoder // WriteZettel writes the encoded zettel to the writer. func (*Encoder) WriteZettel(w io.Writer, zn *ast.ZettelNode, evalMeta encoder.EvalMetaFunc) (int, error) { v := newVisitor(w) | > | 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | func init() { encoder.Register(api.EncoderZmk, func(*encoder.CreateParameter) encoder.Encoder { return Create() }) } // Create an encoder. func Create() *Encoder { return &myZE } // Encoder contains all data needed for encoding. type Encoder struct{} var myZE Encoder // WriteZettel writes the encoded zettel to the writer. func (*Encoder) WriteZettel(w io.Writer, zn *ast.ZettelNode, evalMeta encoder.EvalMetaFunc) (int, error) { v := newVisitor(w) |
︙ | ︙ | |||
71 72 73 74 75 76 77 78 79 80 81 82 83 84 | } else { v.b.WriteString(p.Value) } v.b.WriteByte('\n') } } func (ze *Encoder) WriteContent(w io.Writer, zn *ast.ZettelNode) (int, error) { return ze.WriteBlocks(w, &zn.Ast) } // WriteBlocks writes the content of a block slice to the writer. func (*Encoder) WriteBlocks(w io.Writer, bs *ast.BlockSlice) (int, error) { v := newVisitor(w) | > | 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | } else { v.b.WriteString(p.Value) } v.b.WriteByte('\n') } } // WriteContent encodes the zettel content. func (ze *Encoder) WriteContent(w io.Writer, zn *ast.ZettelNode) (int, error) { return ze.WriteBlocks(w, &zn.Ast) } // WriteBlocks writes the content of a block slice to the writer. func (*Encoder) WriteBlocks(w io.Writer, bs *ast.BlockSlice) (int, error) { v := newVisitor(w) |
︙ | ︙ |
Changes to encoding/atom/atom.go.
︙ | ︙ | |||
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | "zettelstore.de/z/kernel" "zettelstore.de/z/query" "zettelstore.de/z/strfun" "zettelstore.de/z/zettel/id" "zettelstore.de/z/zettel/meta" ) const ContentType = "application/atom+xml" type Configuration struct { Title string Generator string NewURLBuilderAbs func() *api.URLBuilder } func (c *Configuration) Setup(cfg config.Config) { baseURL := kernel.Main.GetConfig(kernel.WebService, kernel.WebBaseURL).(string) c.Title = cfg.GetSiteName() c.Generator = (kernel.Main.GetConfig(kernel.CoreService, kernel.CoreProgname).(string) + " " + kernel.Main.GetConfig(kernel.CoreService, kernel.CoreVersion).(string)) c.NewURLBuilderAbs = func() *api.URLBuilder { return api.NewURLBuilder(baseURL, 'h') } } func (c *Configuration) Marshal(q *query.Query, ml []*meta.Meta) []byte { atomUpdated := encoding.LastUpdated(ml, time.RFC3339) feedLink := c.NewURLBuilderAbs().String() var buf bytes.Buffer buf.WriteString(`<feed xmlns="http://www.w3.org/2005/Atom">` + "\n") xml.WriteTag(&buf, " ", "title", c.Title) | > > > > | 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | "zettelstore.de/z/kernel" "zettelstore.de/z/query" "zettelstore.de/z/strfun" "zettelstore.de/z/zettel/id" "zettelstore.de/z/zettel/meta" ) // ContentType specifies the HTTP content type for Atom. const ContentType = "application/atom+xml" // Configuration contains data to configure the Atom encoding. type Configuration struct { Title string Generator string NewURLBuilderAbs func() *api.URLBuilder } // Setup initializes the Configuration. func (c *Configuration) Setup(cfg config.Config) { baseURL := kernel.Main.GetConfig(kernel.WebService, kernel.WebBaseURL).(string) c.Title = cfg.GetSiteName() c.Generator = (kernel.Main.GetConfig(kernel.CoreService, kernel.CoreProgname).(string) + " " + kernel.Main.GetConfig(kernel.CoreService, kernel.CoreVersion).(string)) c.NewURLBuilderAbs = func() *api.URLBuilder { return api.NewURLBuilder(baseURL, 'h') } } // Marshal encodes the result of a query as Atom. func (c *Configuration) Marshal(q *query.Query, ml []*meta.Meta) []byte { atomUpdated := encoding.LastUpdated(ml, time.RFC3339) feedLink := c.NewURLBuilderAbs().String() var buf bytes.Buffer buf.WriteString(`<feed xmlns="http://www.w3.org/2005/Atom">` + "\n") xml.WriteTag(&buf, " ", "title", c.Title) |
︙ | ︙ |
Changes to encoding/rss/rss.go.
︙ | ︙ | |||
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | "zettelstore.de/z/kernel" "zettelstore.de/z/query" "zettelstore.de/z/strfun" "zettelstore.de/z/zettel/id" "zettelstore.de/z/zettel/meta" ) const ContentType = "application/rss+xml" type Configuration struct { Title string Language string Copyright string Generator string NewURLBuilderAbs func() *api.URLBuilder } func (c *Configuration) Setup(ctx context.Context, cfg config.Config) { baseURL := kernel.Main.GetConfig(kernel.WebService, kernel.WebBaseURL).(string) defVals := cfg.AddDefaultValues(ctx, &meta.Meta{}) c.Title = cfg.GetSiteName() c.Language = defVals.GetDefault(api.KeyLang, "") c.Copyright = defVals.GetDefault(api.KeyCopyright, "") c.Generator = (kernel.Main.GetConfig(kernel.CoreService, kernel.CoreProgname).(string) + " " + kernel.Main.GetConfig(kernel.CoreService, kernel.CoreVersion).(string)) c.NewURLBuilderAbs = func() *api.URLBuilder { return api.NewURLBuilder(baseURL, 'h') } } func (c *Configuration) Marshal(q *query.Query, ml []*meta.Meta) []byte { rssPublished := encoding.LastUpdated(ml, time.RFC1123Z) atomLink := "" if s := q.String(); s != "" { atomLink = c.NewURLBuilderAbs().AppendQuery(s).String() } | > > > > | 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | "zettelstore.de/z/kernel" "zettelstore.de/z/query" "zettelstore.de/z/strfun" "zettelstore.de/z/zettel/id" "zettelstore.de/z/zettel/meta" ) // ContentType specifies the HTTP content type for RSS. const ContentType = "application/rss+xml" // Configuration contains data to configure the RSS encoding. type Configuration struct { Title string Language string Copyright string Generator string NewURLBuilderAbs func() *api.URLBuilder } // Setup initializes the Configuration. func (c *Configuration) Setup(ctx context.Context, cfg config.Config) { baseURL := kernel.Main.GetConfig(kernel.WebService, kernel.WebBaseURL).(string) defVals := cfg.AddDefaultValues(ctx, &meta.Meta{}) c.Title = cfg.GetSiteName() c.Language = defVals.GetDefault(api.KeyLang, "") c.Copyright = defVals.GetDefault(api.KeyCopyright, "") c.Generator = (kernel.Main.GetConfig(kernel.CoreService, kernel.CoreProgname).(string) + " " + kernel.Main.GetConfig(kernel.CoreService, kernel.CoreVersion).(string)) c.NewURLBuilderAbs = func() *api.URLBuilder { return api.NewURLBuilder(baseURL, 'h') } } // Marshal encodes the result of a query as Atom. func (c *Configuration) Marshal(q *query.Query, ml []*meta.Meta) []byte { rssPublished := encoding.LastUpdated(ml, time.RFC1123Z) atomLink := "" if s := q.String(); s != "" { atomLink = c.NewURLBuilderAbs().AppendQuery(s).String() } |
︙ | ︙ |
Changes to query/context.go.
︙ | ︙ | |||
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | MaxCount int Full bool } // ContextDirection specifies the direction a context should be calculated. type ContextDirection uint8 const ( ContextDirBoth ContextDirection = iota ContextDirForward ContextDirBackward ) // ContextPort is the collection of box methods needed by this directive. type ContextPort interface { GetMeta(ctx context.Context, zid id.Zid) (*meta.Meta, error) SelectMeta(ctx context.Context, metaSeq []*meta.Meta, q *Query) ([]*meta.Meta, error) } func (spec *ContextSpec) Print(pe *PrintEnv) { pe.printSpace() pe.writeString(api.ContextDirective) if spec.Full { pe.printSpace() pe.writeString(api.FullDirective) } switch spec.Direction { case ContextDirBackward: pe.printSpace() pe.writeString(api.BackwardDirective) case ContextDirForward: pe.printSpace() pe.writeString(api.ForwardDirective) } pe.printPosInt(api.CostDirective, spec.MaxCost) pe.printPosInt(api.MaxDirective, spec.MaxCount) } func (spec *ContextSpec) Execute(ctx context.Context, startSeq []*meta.Meta, port ContextPort) []*meta.Meta { maxCost := float64(spec.MaxCost) if maxCost <= 0 { maxCost = 17 } maxCount := spec.MaxCount if maxCount <= 0 { | > > > | 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | MaxCount int Full bool } // ContextDirection specifies the direction a context should be calculated. type ContextDirection uint8 // Constants for ContextDirection. const ( ContextDirBoth ContextDirection = iota ContextDirForward ContextDirBackward ) // ContextPort is the collection of box methods needed by this directive. type ContextPort interface { GetMeta(ctx context.Context, zid id.Zid) (*meta.Meta, error) SelectMeta(ctx context.Context, metaSeq []*meta.Meta, q *Query) ([]*meta.Meta, error) } // Print the spec on the given print environment. func (spec *ContextSpec) Print(pe *PrintEnv) { pe.printSpace() pe.writeString(api.ContextDirective) if spec.Full { pe.printSpace() pe.writeString(api.FullDirective) } switch spec.Direction { case ContextDirBackward: pe.printSpace() pe.writeString(api.BackwardDirective) case ContextDirForward: pe.printSpace() pe.writeString(api.ForwardDirective) } pe.printPosInt(api.CostDirective, spec.MaxCost) pe.printPosInt(api.MaxDirective, spec.MaxCount) } // Execute the specification. func (spec *ContextSpec) Execute(ctx context.Context, startSeq []*meta.Meta, port ContextPort) []*meta.Meta { maxCost := float64(spec.MaxCost) if maxCost <= 0 { maxCost = 17 } maxCount := spec.MaxCount if maxCount <= 0 { |
︙ | ︙ |
Changes to query/print.go.
︙ | ︙ | |||
145 146 147 148 149 150 151 152 153 154 155 156 157 158 | } if s := val.value; s != "" { pe.writeString(s) } } } func (q *Query) Human() string { var sb strings.Builder q.PrintHuman(&sb) return sb.String() } // PrintHuman the query to a writer in a human readable form. | > | 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | } if s := val.value; s != "" { pe.writeString(s) } } } // Human returns the query as a human readable string. func (q *Query) Human() string { var sb strings.Builder q.PrintHuman(&sb) return sb.String() } // PrintHuman the query to a writer in a human readable form. |
︙ | ︙ |
Changes to query/specs.go.
︙ | ︙ | |||
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | package query import "t73f.de/r/zsc/api" // IdentSpec contains all specification values to calculate the ident directive. type IdentSpec struct{} func (spec *IdentSpec) Print(pe *PrintEnv) { pe.printSpace() pe.writeString(api.IdentDirective) } // ItemsSpec contains all specification values to calculate items. type ItemsSpec struct{} func (spec *ItemsSpec) Print(pe *PrintEnv) { pe.printSpace() pe.writeString(api.ItemsDirective) } | > > | 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | package query import "t73f.de/r/zsc/api" // IdentSpec contains all specification values to calculate the ident directive. type IdentSpec struct{} // Print the spec on the given print environment. func (spec *IdentSpec) Print(pe *PrintEnv) { pe.printSpace() pe.writeString(api.IdentDirective) } // ItemsSpec contains all specification values to calculate items. type ItemsSpec struct{} // Print the spec on the given print environment. func (spec *ItemsSpec) Print(pe *PrintEnv) { pe.printSpace() pe.writeString(api.ItemsDirective) } |
Changes to query/unlinked.go.
︙ | ︙ | |||
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | ) // UnlinkedSpec contains all specification values to calculate unlinked references. type UnlinkedSpec struct { words []string } func (spec *UnlinkedSpec) Print(pe *PrintEnv) { pe.printSpace() pe.writeString(api.UnlinkedDirective) for _, word := range spec.words { pe.writeStrings(" ", api.PhraseDirective, " ", word) } } func (spec *UnlinkedSpec) GetWords(metaSeq []*meta.Meta) []string { if words := spec.words; len(words) > 0 { result := make([]string, len(words)) copy(result, words) return result } result := make([]string, 0, len(metaSeq)*4) // Assumption: four words per title | > > | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | ) // UnlinkedSpec contains all specification values to calculate unlinked references. type UnlinkedSpec struct { words []string } // Print the spec on the given print environment. func (spec *UnlinkedSpec) Print(pe *PrintEnv) { pe.printSpace() pe.writeString(api.UnlinkedDirective) for _, word := range spec.words { pe.writeStrings(" ", api.PhraseDirective, " ", word) } } // GetWords returns all title words of a given query result. func (spec *UnlinkedSpec) GetWords(metaSeq []*meta.Meta) []string { if words := spec.words; len(words) > 0 { result := make([]string, len(words)) copy(result, words) return result } result := make([]string, 0, len(metaSeq)*4) // Assumption: four words per title |
︙ | ︙ |
Changes to tools/devtools/devtools.go.
︙ | ︙ | |||
35 36 37 38 39 40 41 42 43 44 45 46 47 48 | tools := []struct{ name, pack string }{ {"shadow", "golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow@latest"}, {"unparam", "mvdan.cc/unparam@latest"}, {"staticcheck", "honnef.co/go/tools/cmd/staticcheck@latest"}, {"govulncheck", "golang.org/x/vuln/cmd/govulncheck@latest"}, {"deadcode", "golang.org/x/tools/cmd/deadcode@latest"}, {"errcheck", "github.com/kisielk/errcheck@latest"}, } for _, tool := range tools { err := doGoInstall(tool.pack) if err != nil { return err } } | > | 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | tools := []struct{ name, pack string }{ {"shadow", "golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow@latest"}, {"unparam", "mvdan.cc/unparam@latest"}, {"staticcheck", "honnef.co/go/tools/cmd/staticcheck@latest"}, {"govulncheck", "golang.org/x/vuln/cmd/govulncheck@latest"}, {"deadcode", "golang.org/x/tools/cmd/deadcode@latest"}, {"errcheck", "github.com/kisielk/errcheck@latest"}, {"revive", "https://github.com/mgechev/revive@latest"}, } for _, tool := range tools { err := doGoInstall(tool.pack) if err != nil { return err } } |
︙ | ︙ |
Changes to tools/tools.go.
︙ | ︙ | |||
22 23 24 25 26 27 28 | "os" "os/exec" "strings" "zettelstore.de/z/strfun" ) | > > | | > > > > > > > > > > > > > | 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | "os" "os/exec" "strings" "zettelstore.de/z/strfun" ) // Some constants to make Go work with fossil. var ( EnvDirectProxy = []string{"GOPROXY=direct"} EnvGoVCS = []string{"GOVCS=zettelstore.de:fossil,t73f.de:fossil"} ) // Verbose signals a verbose tool execution. var Verbose bool // ExecuteCommand executes a specific command. func ExecuteCommand(env []string, name string, arg ...string) (string, error) { LogCommand("EXEC", env, name, arg) var out strings.Builder cmd := PrepareCommand(env, name, arg, nil, &out, os.Stderr) err := cmd.Run() return out.String(), err } // ExecuteFilter executes an external program to be used as a filter. func ExecuteFilter(data []byte, env []string, name string, arg ...string) (string, string, error) { LogCommand("EXEC", env, name, arg) var stdout, stderr strings.Builder cmd := PrepareCommand(env, name, arg, bytes.NewReader(data), &stdout, &stderr) err := cmd.Run() return stdout.String(), stderr.String(), err } // PrepareCommand creates a commands to be executed. func PrepareCommand(env []string, name string, arg []string, in io.Reader, stdout, stderr io.Writer) *exec.Cmd { if len(env) > 0 { env = append(env, os.Environ()...) } cmd := exec.Command(name, arg...) cmd.Env = env cmd.Stdin = in cmd.Stdout = stdout cmd.Stderr = stderr return cmd } // LogCommand logs the execution of a command. func LogCommand(exec string, env []string, name string, arg []string) { if Verbose { if len(env) > 0 { for i, e := range env { fmt.Fprintf(os.Stderr, "ENV%d %v\n", i+1, e) } } fmt.Fprintln(os.Stderr, exec, name, arg) } } // Check the source with some linters. func Check(forRelease bool) error { if err := CheckGoTest("./..."); err != nil { return err } if err := checkGoVet(); err != nil { return err } if err := checkShadow(forRelease); err != nil { return err } if err := checkStaticcheck(); err != nil { return err } if err := checkUnparam(forRelease); err != nil { return err } if err := checkRevive(); err != nil { return err } if forRelease { if err := checkGoVulncheck(); err != nil { return err } } return checkFossilExtra() } // CheckGoTest runs all internal unti tests. func CheckGoTest(pkg string, testParams ...string) error { var env []string env = append(env, EnvDirectProxy...) env = append(env, EnvGoVCS...) args := []string{"test", pkg} args = append(args, testParams...) out, err := ExecuteCommand(env, "go", args...) |
︙ | ︙ | |||
138 139 140 141 142 143 144 145 146 147 148 149 150 151 | func checkStaticcheck() error { out, err := ExecuteCommand(EnvGoVCS, "staticcheck", "./...") if err != nil { fmt.Fprintln(os.Stderr, "Some staticcheck problems found") if len(out) > 0 { fmt.Fprintln(os.Stderr, out) } } return err } func checkUnparam(forRelease bool) error { path, err := findExecStrict("unparam", forRelease) if path == "" { | > > > > > > > > > > > | 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | func checkStaticcheck() error { out, err := ExecuteCommand(EnvGoVCS, "staticcheck", "./...") if err != nil { fmt.Fprintln(os.Stderr, "Some staticcheck problems found") if len(out) > 0 { fmt.Fprintln(os.Stderr, out) } } return err } func checkRevive() error { out, err := ExecuteCommand(EnvGoVCS, "revive", "./...") if err != nil { fmt.Fprintln(os.Stderr, "Some revive problems found") if len(out) > 0 { fmt.Fprintln(os.Stderr, out) } } return err } func checkUnparam(forRelease bool) error { path, err := findExecStrict("unparam", forRelease) if path == "" { |
︙ | ︙ |
Changes to web/content/content.go.
︙ | ︙ | |||
20 21 22 23 24 25 26 27 28 29 30 31 32 33 | "net/http" "t73f.de/r/zsc/api" "zettelstore.de/z/zettel" "zettelstore.de/z/zettel/meta" ) const ( UnknownMIME = "application/octet-stream" mimeGIF = "image/gif" mimeHTML = "text/html; charset=utf-8" mimeJPEG = "image/jpeg" mimeMarkdown = "text/markdown; charset=utf-8" PlainText = "text/plain; charset=utf-8" | > | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | "net/http" "t73f.de/r/zsc/api" "zettelstore.de/z/zettel" "zettelstore.de/z/zettel/meta" ) // Some MIME encoding values. const ( UnknownMIME = "application/octet-stream" mimeGIF = "image/gif" mimeHTML = "text/html; charset=utf-8" mimeJPEG = "image/jpeg" mimeMarkdown = "text/markdown; charset=utf-8" PlainText = "text/plain; charset=utf-8" |
︙ | ︙ | |||
96 97 98 99 100 101 102 103 104 105 106 107 108 109 | "text/plain": meta.SyntaxText, // Additional syntaxes "application/pdf": "pdf", "text/javascript": "js", } func SyntaxFromMIME(m string, data []byte) string { mt, _, _ := mime.ParseMediaType(m) if syntax, found := mime2syntax[mt]; found { return syntax } if len(data) > 0 { ct := http.DetectContentType(data) | > > | 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | "text/plain": meta.SyntaxText, // Additional syntaxes "application/pdf": "pdf", "text/javascript": "js", } // SyntaxFromMIME returns the syntax for a zettel based on MIME encoding value // and the actual data. func SyntaxFromMIME(m string, data []byte) string { mt, _, _ := mime.ParseMediaType(m) if syntax, found := mime2syntax[mt]; found { return syntax } if len(data) > 0 { ct := http.DetectContentType(data) |
︙ | ︙ |
Changes to web/server/impl/impl.go.
︙ | ︙ | |||
31 32 33 34 35 36 37 38 39 40 41 42 43 44 | baseURL string server httpServer router httpRouter persistentCookie bool secureCookie bool } type ServerData struct { Log *logger.Logger ListenAddr string BaseURL string URLPrefix string MaxRequestSize int64 Auth auth.TokenManager | > | 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | baseURL string server httpServer router httpRouter persistentCookie bool secureCookie bool } // ServerData contains the data needed to configure a server. type ServerData struct { Log *logger.Logger ListenAddr string BaseURL string URLPrefix string MaxRequestSize int64 Auth auth.TokenManager |
︙ | ︙ |