Upgrade to Go 1.18

This commit is contained in:
Peter 2022-03-15 20:22:04 +01:00
parent c358848ed5
commit f7548a2816
Signed by: prskr
GPG key ID: C1DB5D2E8DB512F9
8 changed files with 22 additions and 25 deletions

View file

@ -19,10 +19,10 @@ jobs:
name: Build name: Build
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Set up Go 1.17 - name: Set up Go 1.18
uses: actions/setup-go@v3 uses: actions/setup-go@v3
with: with:
go-version: '^1.17' go-version: '^1.18'
id: go id: go
- name: Login to GitHub Container Registry - name: Login to GitHub Container Registry

View file

@ -25,7 +25,7 @@ func init() {
if t, err := template. if t, err := template.
New("index"). New("index").
Funcs(sprig.FuncMap()). Funcs(sprig.FuncMap()).
Funcs(map[string]interface{}{ Funcs(map[string]any{
"fileId": func(fileName string) string { "fileId": func(fileName string) string {
h := fnv.New32a() h := fnv.New32a()
return hex.EncodeToString(h.Sum([]byte(path.Base(fileName)))) return hex.EncodeToString(h.Sum([]byte(path.Base(fileName))))
@ -60,7 +60,7 @@ func RegisterViews(router *httprouter.Router, logger *log.Logger, wdfs fs.FS, md
func (p *Views) IndexPage(writer http.ResponseWriter, _ *http.Request, _ httprouter.Params) { func (p *Views) IndexPage(writer http.ResponseWriter, _ *http.Request, _ httprouter.Params) {
writer.Header().Set("Content-Type", "text/html") writer.Header().Set("Content-Type", "text/html")
if err := indexTmpl.ExecuteTemplate(writer, "index.gohtml", map[string]interface{}{ if err := indexTmpl.ExecuteTemplate(writer, "index.gohtml", map[string]any{
"Reveal": p.cfg.Reveal, "Reveal": p.cfg.Reveal,
"Rendering": p.cfg.Rendering, "Rendering": p.cfg.Rendering,
}); err != nil { }); err != nil {

View file

@ -5,7 +5,7 @@ const (
defaultHeight uint = 700 defaultHeight uint = 700
) )
var defaults = map[string]interface{}{ var defaults = map[string]any{
"mermaid.theme": "forest", "mermaid.theme": "forest",
"theme": "beige", "theme": "beige",
"width": defaultWidth, "width": defaultWidth,

3
go.mod
View file

@ -1,6 +1,6 @@
module github.com/baez90/goveal module github.com/baez90/goveal
go 1.17 go 1.18
require ( require (
github.com/Masterminds/sprig/v3 v3.2.2 github.com/Masterminds/sprig/v3 v3.2.2
@ -12,6 +12,7 @@ require (
github.com/sirupsen/logrus v1.8.1 github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v1.4.0 github.com/spf13/cobra v1.4.0
github.com/spf13/viper v1.10.1 github.com/spf13/viper v1.10.1
github.com/valyala/bytebufferpool v1.0.0
go.uber.org/multierr v1.8.0 go.uber.org/multierr v1.8.0
) )

2
go.sum
View file

@ -201,6 +201,8 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=

View file

@ -1,12 +1,12 @@
package rendering package rendering
import ( import (
"bytes"
"fmt" "fmt"
"html/template" "html/template"
"regexp" "regexp"
"github.com/gomarkdown/markdown/parser" "github.com/gomarkdown/markdown/parser"
"github.com/valyala/bytebufferpool"
"github.com/baez90/goveal/config" "github.com/baez90/goveal/config"
) )
@ -24,17 +24,17 @@ func ToHTML(markdown string, renderCfg config.Rendering) (rendered []byte, err e
return nil, err return nil, err
} }
buf := templateRenderBufferPool.Get().(*bytes.Buffer) buf := bytebufferpool.Get()
defer func() { defer func() {
buf.Reset() buf.Reset()
templateRenderBufferPool.Put(buf) bytebufferpool.Put(buf)
}() }()
for idx := range slides { for idx := range slides {
if rendered, err := slides[idx].ToHTML(); err != nil { if rendered, err := slides[idx].ToHTML(); err != nil {
return nil, err return nil, err
} else { } else {
buf.WriteString(string(rendered)) _, _ = buf.WriteString(string(rendered))
} }
} }

View file

@ -78,7 +78,7 @@ func (r *RevealRenderer) handleListItem(w io.Writer, listItem *ast.ListItem) (as
return ast.GoToNext, false return ast.GoToNext, false
} }
data := map[string]interface{}{ data := map[string]any{
"Attributes": getAttributesFromChildSpan(p), "Attributes": getAttributesFromChildSpan(p),
} }
@ -102,7 +102,7 @@ func (r *RevealRenderer) handleImage(w io.Writer, img *ast.Image) (ast.WalkStatu
} }
} }
data := map[string]interface{}{ data := map[string]any{
"ID": hex.EncodeToString(r.Hash.Sum([]byte(path.Base(string(img.Destination))))), "ID": hex.EncodeToString(r.Hash.Sum([]byte(path.Base(string(img.Destination))))),
"Attributes": getAttributesFromChildSpan(img.GetParent()), "Attributes": getAttributesFromChildSpan(img.GetParent()),
"ImageSource": string(img.Destination), "ImageSource": string(img.Destination),
@ -154,7 +154,7 @@ func extractElementAttributes(htmlSpan *ast.HTMLSpan) (attrs []template.HTMLAttr
} }
func renderCodeTemplate(templateName string, codeBlock *ast.CodeBlock) (output []byte, err error) { func renderCodeTemplate(templateName string, codeBlock *ast.CodeBlock) (output []byte, err error) {
data := map[string]interface{}{ data := map[string]any{
//nolint:gosec // need to embed the code in original format without escaping //nolint:gosec // need to embed the code in original format without escaping
"Code": template.HTML(codeBlock.Literal), "Code": template.HTML(codeBlock.Literal),
"LineNumbers": lineNumbers(codeBlock.Attribute), "LineNumbers": lineNumbers(codeBlock.Attribute),

View file

@ -1,29 +1,23 @@
package rendering package rendering
import ( import (
"bytes"
"embed" "embed"
"hash/fnv" "hash/fnv"
"html/template" "html/template"
"sync"
"github.com/Masterminds/sprig/v3" "github.com/Masterminds/sprig/v3"
"github.com/gomarkdown/markdown" "github.com/gomarkdown/markdown"
mdhtml "github.com/gomarkdown/markdown/html" mdhtml "github.com/gomarkdown/markdown/html"
"github.com/gomarkdown/markdown/parser" "github.com/gomarkdown/markdown/parser"
"github.com/valyala/bytebufferpool"
"github.com/baez90/goveal/rendering/emoji" "github.com/baez90/goveal/rendering/emoji"
) )
var ( var (
//go:embed templates/*.gohtml //go:embed templates/*.gohtml
templatesFS embed.FS templatesFS embed.FS
templates *template.Template templates *template.Template
templateRenderBufferPool = &sync.Pool{
New: func() interface{} {
return new(bytes.Buffer)
},
}
) )
func init() { func init() {
@ -54,11 +48,11 @@ func init() {
} }
} }
func renderTemplate(templateName string, data interface{}) (output []byte, err error) { func renderTemplate(templateName string, data any) (output []byte, err error) {
buffer := templateRenderBufferPool.Get().(*bytes.Buffer) buffer := bytebufferpool.Get()
defer func() { defer func() {
buffer.Reset() buffer.Reset()
templateRenderBufferPool.Put(buffer) bytebufferpool.Put(buffer)
}() }()
err = templates.ExecuteTemplate(buffer, templateName, data) err = templates.ExecuteTemplate(buffer, templateName, data)