diff --git a/output/formatter.go b/output/formatter.go index fb5ece6..f10a973 100644 --- a/output/formatter.go +++ b/output/formatter.go @@ -17,9 +17,10 @@ package output import ( "encoding/csv" "encoding/json" + htmlTemplate "html/template" "io" "strconv" - "text/template" + plainTemplate "text/template" gas "github.com/GoASTScanner/gas/core" ) @@ -54,10 +55,12 @@ func CreateReport(w io.Writer, format string, data *gas.Analyzer) error { err = reportJSON(w, data) case "csv": err = reportCSV(w, data) + case "html": + err = reportFromHTMLTemplate(w, html, data) case "text": - err = reportFromTemplate(w, text, data) + err = reportFromPlaintextTemplate(w, text, data) default: - err = reportFromTemplate(w, text, data) + err = reportFromPlaintextTemplate(w, text, data) } return err } @@ -94,8 +97,17 @@ func reportCSV(w io.Writer, data *gas.Analyzer) error { return nil } -func reportFromTemplate(w io.Writer, reportTemplate string, data *gas.Analyzer) error { - t, e := template.New("gas").Parse(reportTemplate) +func reportFromPlaintextTemplate(w io.Writer, reportTemplate string, data *gas.Analyzer) error { + t, e := plainTemplate.New("gas").Parse(reportTemplate) + if e != nil { + return e + } + + return t.Execute(w, data) +} + +func reportFromHTMLTemplate(w io.Writer, reportTemplate string, data *gas.Analyzer) error { + t, e := htmlTemplate.New("gas").Parse(reportTemplate) if e != nil { return e } diff --git a/output/template.go b/output/template.go new file mode 100644 index 0000000..f7dd236 --- /dev/null +++ b/output/template.go @@ -0,0 +1,401 @@ +// (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 output + +const html = ` + + + + + Go AST Scanner + + + + + + + +
+
+
+
+
+ + + +`