-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up http-server tree structure. Fixes CSS in banner. (#147)
* Clean up http-server tree structure. Fixes CSS in banner. * Cleanup go.mod and Readme. * Remove random string generator. * Add documentation for functions. * Prevent using casting and use "errors.As()" instead. * Work through golangci-lint messages. * Viper does not support a check for config file not found.
- Loading branch information
1 parent
bfebd36
commit 2c2591c
Showing
33 changed files
with
590 additions
and
369 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
run: | ||
tests: false | ||
concurrency: 5 | ||
timeout: 3m | ||
|
||
linters: | ||
disable-all: true | ||
enable: | ||
- gosimple | ||
- govet | ||
- ineffassign | ||
- staticcheck | ||
- unused | ||
- asasalint | ||
- asciicheck | ||
- bidichk | ||
- bodyclose | ||
- contextcheck | ||
- decorder | ||
- dogsled | ||
- dupl | ||
- dupword | ||
- durationcheck | ||
- errchkjson | ||
- errname | ||
- errorlint | ||
- exhaustive | ||
- copyloopvar | ||
- ginkgolinter | ||
- gocheckcompilerdirectives | ||
- gochecksumtype | ||
- gocritic | ||
- gocyclo | ||
- gofmt | ||
- gofumpt | ||
- goheader | ||
- goimports | ||
- gomodguard | ||
- goprintffuncname | ||
- gosec | ||
- gosmopolitan | ||
- grouper | ||
- importas | ||
- inamedparam | ||
- ireturn | ||
- loggercheck | ||
- makezero | ||
- mirror | ||
- misspell | ||
- musttag | ||
- nakedret | ||
- nilerr | ||
- nilnil | ||
- noctx | ||
- nolintlint | ||
- nonamedreturns | ||
- nosprintfhostport | ||
- paralleltest | ||
- perfsprint | ||
- prealloc | ||
- predeclared | ||
- promlinter | ||
- protogetter | ||
- reassign | ||
- revive | ||
- rowserrcheck | ||
- sloglint | ||
- spancheck | ||
- sqlclosecheck | ||
- stylecheck | ||
- tenv | ||
- testableexamples | ||
- testifylint | ||
- testpackage | ||
- thelper | ||
- tparallel | ||
- unconvert | ||
- unparam | ||
- usestdlibvars | ||
- wastedassign | ||
- whitespace | ||
- wrapcheck | ||
- zerologlint | ||
|
||
linters-settings: | ||
perfsprint: | ||
int-conversion: false | ||
err-error: false | ||
errorf: true | ||
sprintf1: true | ||
strconcat: false | ||
|
||
ireturn: | ||
allow: | ||
- error | ||
- http.Handler | ||
|
||
gosec: | ||
confidence: medium | ||
excludes: | ||
- G401 # Use of weak cryptographic primitive: we're using sha1 for etag generation | ||
- G505 # Blocklisted import crypto/sha1: we're using sha1 for etag generation | ||
|
||
stylecheck: | ||
checks: | ||
- "all" | ||
- "-ST1003" # this is covered by a different linter | ||
|
||
gocyclo: | ||
min-complexity: 60 | ||
|
||
staticcheck: | ||
checks: | ||
- "all" | ||
- "-SA1019" # keeping some deprecated code for compatibility | ||
|
||
gocritic: | ||
enable-all: true | ||
disabled-checks: | ||
- appendAssign | ||
- unnamedResult | ||
- badRegexp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package mdrendering | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
|
||
"github.com/yuin/goldmark/ast" | ||
"github.com/yuin/goldmark/renderer" | ||
"github.com/yuin/goldmark/renderer/html" | ||
"github.com/yuin/goldmark/util" | ||
) | ||
|
||
type HTTPServerRendering struct { | ||
html.Config | ||
} | ||
|
||
// RegisterFuncs implements goldmark.Renderer. | ||
func (r *HTTPServerRendering) RegisterFuncs(reg renderer.NodeRendererFuncRegisterer) { | ||
reg.Register(ast.KindHeading, r.renderHeading) | ||
reg.Register(ast.KindImage, r.renderImageAlign) | ||
} | ||
|
||
func (r *HTTPServerRendering) renderImageAlign(w util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) { | ||
if !entering { | ||
return ast.WalkContinue, nil | ||
} | ||
n := node.(*ast.Image) | ||
w.WriteString("<img src=\"") | ||
|
||
if r.Unsafe || !html.IsDangerousURL(n.Destination) { | ||
u := util.URLEscape(n.Destination, true) | ||
|
||
switch { | ||
case bytes.HasSuffix(n.Destination, []byte(`#align-right`)): | ||
w.Write(util.EscapeHTML(bytes.TrimSuffix(u, []byte(`#align-right`)))) | ||
w.WriteString(`" align="right`) | ||
case bytes.HasSuffix(n.Destination, []byte(`#align-center`)): | ||
w.Write(util.EscapeHTML(bytes.TrimSuffix(u, []byte(`#align-center`)))) | ||
w.WriteString(`" align="center`) | ||
case bytes.HasSuffix(n.Destination, []byte(`#align-left`)): | ||
w.Write(util.EscapeHTML(bytes.TrimSuffix(u, []byte(`#align-left`)))) | ||
w.WriteString(`" align="left`) | ||
default: | ||
w.Write(util.EscapeHTML(u)) | ||
} | ||
} | ||
|
||
w.WriteString(`" alt="`) | ||
w.Write(util.EscapeHTML(n.Text(source))) | ||
w.WriteString(`"`) | ||
if n.Title != nil { | ||
w.WriteString(` title="`) | ||
r.Writer.Write(w, n.Title) | ||
w.WriteString(`"`) | ||
} | ||
if r.XHTML { | ||
w.WriteString(" />") | ||
} else { | ||
w.WriteString(">") | ||
} | ||
return ast.WalkSkipChildren, nil | ||
} | ||
|
||
func (r *HTTPServerRendering) renderHeading(w util.BufWriter, _ []byte, node ast.Node, entering bool) (ast.WalkStatus, error) { | ||
hn := node.(*ast.Heading) | ||
|
||
slug, _ := node.AttributeString("id") | ||
|
||
if entering { | ||
node.SetAttribute([]byte("id"), slug) | ||
fmt.Fprintf(w, `<h%d class="content-header" id="%s">`, hn.Level, slug) | ||
return ast.WalkContinue, nil | ||
} | ||
|
||
fmt.Fprintf(w, `<a href="#%s" tabindex="-1"><i class="fas fa-link"></i></a></h%d>`, slug, hn.Level) | ||
return ast.WalkContinue, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
internal/mw/disable_config_access.go → ...rnal/middlewares/disable_config_access.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package mw | ||
package middlewares | ||
|
||
import ( | ||
"fmt" | ||
|
Oops, something went wrong.