mirror of
https://github.com/securego/gosec.git
synced 2025-04-13 11:40:37 +02:00
Use go embed for templates (#725)
This commit is contained in:
parent
3eba7b8a3e
commit
ff17c30a97
@ -1,20 +1,3 @@
|
|||||||
// (c) Copyright 2016 Hewlett Packard Enterprise Development LP
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package html
|
|
||||||
|
|
||||||
const templateContent = `
|
|
||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
@ -454,4 +437,4 @@ const templateContent = `
|
|||||||
);
|
);
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>`
|
</html>
|
@ -1,12 +1,18 @@
|
|||||||
package html
|
package html
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
||||||
|
// use go embed to import template
|
||||||
|
_ "embed"
|
||||||
"html/template"
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/securego/gosec/v2"
|
"github.com/securego/gosec/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//go:embed template.html
|
||||||
|
var templateContent string
|
||||||
|
|
||||||
// WriteReport write a report in html format to the output writer
|
// WriteReport write a report in html format to the output writer
|
||||||
func WriteReport(w io.Writer, data *gosec.ReportInfo) error {
|
func WriteReport(w io.Writer, data *gosec.ReportInfo) error {
|
||||||
t, e := template.New("gosec").Parse(templateContent)
|
t, e := template.New("gosec").Parse(templateContent)
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
package text
|
Results:
|
||||||
|
|
||||||
const templateContent = `Results:
|
|
||||||
{{range $filePath,$fileErrors := .Errors}}
|
{{range $filePath,$fileErrors := .Errors}}
|
||||||
Golang errors in file: [{{ $filePath }}]:
|
Golang errors in file: [{{ $filePath }}]:
|
||||||
{{range $index, $error := $fileErrors}}
|
{{range $index, $error := $fileErrors}}
|
||||||
@ -23,4 +21,3 @@ Golang errors in file: [{{ $filePath }}]:
|
|||||||
{{- danger .Stats.NumFound }}
|
{{- danger .Stats.NumFound }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
|
||||||
`
|
|
@ -3,6 +3,9 @@ package text
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
|
|
||||||
|
// use go embed to import template
|
||||||
|
_ "embed"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -17,6 +20,9 @@ var (
|
|||||||
errorTheme = color.New(color.FgLightWhite, color.BgRed)
|
errorTheme = color.New(color.FgLightWhite, color.BgRed)
|
||||||
warningTheme = color.New(color.FgBlack, color.BgYellow)
|
warningTheme = color.New(color.FgBlack, color.BgYellow)
|
||||||
defaultTheme = color.New(color.FgWhite, color.BgBlack)
|
defaultTheme = color.New(color.FgWhite, color.BgBlack)
|
||||||
|
|
||||||
|
//go:embed template.txt
|
||||||
|
templateContent string
|
||||||
)
|
)
|
||||||
|
|
||||||
// WriteReport write a (colorized) report in text format
|
// WriteReport write a (colorized) report in text format
|
||||||
|
Loading…
x
Reference in New Issue
Block a user