1
0
Fork 0
mirror of https://github.com/gocsaf/csaf.git synced 2025-12-22 18:15:42 +01:00

Demand Go 1.19 in go.mod. Replaced interface{} with any

This commit is contained in:
Sascha L. Teichmann 2023-01-17 10:55:06 +01:00
parent 1189d538b3
commit c4b70d20cd
15 changed files with 74 additions and 74 deletions

View file

@ -78,7 +78,7 @@ func (w *worker) checkInterims(
data.Reset()
hasher := io.MultiWriter(s256, &data)
var doc interface{}
var doc any
if err := func() error {
defer res.Body.Close()
tee := io.TeeReader(res.Body, hasher)

View file

@ -430,7 +430,7 @@ func (w *worker) sign(data []byte) (string, error) {
sig.Data, constants.PGPSignatureHeader, "", "")
}
func (w *worker) extractCategories(label string, advisory interface{}) error {
func (w *worker) extractCategories(label string, advisory any) error {
// use provider or global categories
var categories []string
@ -499,7 +499,7 @@ func (w *worker) mirrorFiles(tlpLabel csaf.TLPLabel, files []csaf.AdvisoryFile)
continue
}
var advisory interface{}
var advisory any
s256 := sha256.New()
s512 := sha512.New()

View file

@ -42,7 +42,7 @@ type worker struct {
client util.Client // client per provider
provider *provider // current provider
metadataProvider interface{} // current metadata provider
metadataProvider any // current metadata provider
loc string // URL of current provider-metadata.json
dir string // Directory to store data to.
summaries map[string][]summary // the summaries of the advisories.
@ -80,7 +80,7 @@ func (w *worker) createDir() (string, error) {
func (w *worker) locateProviderMetadata(domain string) error {
lpmd := csaf.LoadProviderMetadataForDomain(
w.client, domain, func(format string, args ...interface{}) {
w.client, domain, func(format string, args ...any) {
log.Printf(
"Looking for provider-metadata.json of '"+domain+"': "+format+"\n", args...)
})

View file

@ -49,7 +49,7 @@ type processor struct {
alreadyChecked map[string]whereType
pmdURL string
pmd256 []byte
pmd interface{}
pmd any
keys []*crypto.KeyRing
badIntegrities topicMessages
@ -112,22 +112,22 @@ func (wt whereType) String() string {
}
// add adds a message to this topic.
func (m *topicMessages) add(typ MessageType, format string, args ...interface{}) {
func (m *topicMessages) add(typ MessageType, format string, args ...any) {
*m = append(*m, Message{Type: typ, Text: fmt.Sprintf(format, args...)})
}
// error adds an error message to this topic.
func (m *topicMessages) error(format string, args ...interface{}) {
func (m *topicMessages) error(format string, args ...any) {
m.add(ErrorType, format, args...)
}
// warn adds a warning message to this topic.
func (m *topicMessages) warn(format string, args ...interface{}) {
func (m *topicMessages) warn(format string, args ...any) {
m.add(WarnType, format, args...)
}
// info adds an info message to this topic.
func (m *topicMessages) info(format string, args ...interface{}) {
func (m *topicMessages) info(format string, args ...any) {
m.add(InfoType, format, args...)
}
@ -378,7 +378,7 @@ func (p *processor) integrity(
files []csaf.AdvisoryFile,
base string,
mask whereType,
lg func(MessageType, string, ...interface{}),
lg func(MessageType, string, ...any),
) error {
b, err := url.Parse(base)
if err != nil {
@ -440,7 +440,7 @@ func (p *processor) integrity(
data.Reset()
hasher := io.MultiWriter(s256, s512, &data)
var doc interface{}
var doc any
if err := func() error {
defer res.Body.Close()
@ -592,7 +592,7 @@ func (p *processor) processROLIEFeed(feed string) error {
return errContinue
}
rfeed, rolieDoc, err := func() (*csaf.ROLIEFeed, interface{}, error) {
rfeed, rolieDoc, err := func() (*csaf.ROLIEFeed, any, error) {
defer res.Body.Close()
all, err := io.ReadAll(res.Body)
if err != nil {
@ -602,7 +602,7 @@ func (p *processor) processROLIEFeed(feed string) error {
if err != nil {
return nil, nil, fmt.Errorf("%s: %v", feed, err)
}
var rolieDoc interface{}
var rolieDoc any
err = json.NewDecoder(bytes.NewReader(all)).Decode(&rolieDoc)
return rfeed, rolieDoc, err
@ -899,7 +899,7 @@ func (p *processor) checkCSAFs(domain string) error {
return err
}
fs, hasRolie := rolie.([]interface{})
fs, hasRolie := rolie.([]any)
hasRolie = hasRolie && len(fs) > 0
if hasRolie {

View file

@ -88,7 +88,7 @@ func (d *downloader) httpClient() util.Client {
func (d *downloader) download(domain string) error {
lpmd := csaf.LoadProviderMetadataForDomain(
d.httpClient(), domain, func(format string, args ...interface{}) {
d.httpClient(), domain, func(format string, args ...any) {
log.Printf(
"Looking for provider-metadata.json of '"+domain+"': "+format+"\n", args...)
})
@ -122,7 +122,7 @@ func (d *downloader) download(domain string) error {
func (d *downloader) loadOpenPGPKeys(
client util.Client,
doc interface{},
doc any,
base *url.URL,
) error {
@ -284,7 +284,7 @@ func (d *downloader) downloadFiles(label csaf.TLPLabel, files []csaf.AdvisoryFil
// Download the advisory and hash it.
hasher := io.MultiWriter(writers...)
var doc interface{}
var doc any
if err := func() error {
defer resp.Body.Close()

View file

@ -132,7 +132,7 @@ func (c *controller) tlpParam(r *http.Request) (tlp, error) {
// create calls the "ensureFolders" functions to create the directories and files.
// It returns a struct by success, otherwise an error.
func (c *controller) create(*http.Request) (interface{}, error) {
func (c *controller) create(*http.Request) (any, error) {
if err := ensureFolders(c.cfg); err != nil {
return nil, err
}
@ -144,14 +144,14 @@ func (c *controller) create(*http.Request) (interface{}, error) {
}, nil
}
func (c *controller) upload(r *http.Request) (interface{}, error) {
func (c *controller) upload(r *http.Request) (any, error) {
newCSAF, data, err := c.loadCSAF(r)
if err != nil {
return nil, err
}
var content interface{}
var content any
if err := json.Unmarshal(data, &content); err != nil {
return nil, err
}

View file

@ -131,7 +131,7 @@ func (c *controller) auth(
// render sets the headers for the response. It applies the given template "tmpl" to
// the given object "arg" and writes the output to http.ResponseWriter.
// It logs a warning in case of error.
func (c *controller) render(rw http.ResponseWriter, tmpl string, arg interface{}) {
func (c *controller) render(rw http.ResponseWriter, tmpl string, arg any) {
rw.Header().Set("Content-type", "text/html; charset=utf-8")
rw.Header().Set("X-Content-Type-Options", "nosniff")
if err := c.tmpl.ExecuteTemplate(rw, tmpl, arg); err != nil {
@ -142,13 +142,13 @@ func (c *controller) render(rw http.ResponseWriter, tmpl string, arg interface{}
// failed constructs the error messages by calling "asMultiError" and calls "render"
// function to render the passed template and error object.
func (c *controller) failed(rw http.ResponseWriter, tmpl string, err error) {
result := map[string]interface{}{"Error": asMultiError(err)}
result := map[string]any{"Error": asMultiError(err)}
c.render(rw, tmpl, result)
}
// index calls the "render" function and passes the "index.html" and c.cfg to it.
func (c *controller) index(rw http.ResponseWriter, r *http.Request) {
c.render(rw, "index.html", map[string]interface{}{
c.render(rw, "index.html", map[string]any{
"Config": c.cfg,
})
}
@ -158,7 +158,7 @@ func (c *controller) index(rw http.ResponseWriter, r *http.Request) {
// in case of no error occurred, otherwise calls the "failed" function and passes the given
// template and the error from "fn".
func (c *controller) web(
fn func(*http.Request) (interface{}, error),
fn func(*http.Request) (any, error),
tmpl string,
) func(http.ResponseWriter, *http.Request) {
@ -173,7 +173,7 @@ func (c *controller) web(
// writeJSON sets the header for the response and writes the JSON encoding of the given "content".
// It logs out an error message in case of an error.
func writeJSON(rw http.ResponseWriter, content interface{}, code int) {
func writeJSON(rw http.ResponseWriter, content any, code int) {
rw.Header().Set("Content-type", "application/json; charset=utf-8")
rw.Header().Set("X-Content-Type-Options", "nosniff")
rw.WriteHeader(code)
@ -182,7 +182,7 @@ func writeJSON(rw http.ResponseWriter, content interface{}, code int) {
}
}
func errorToContent(err error) interface{} {
func errorToContent(err error) any {
return &struct {
Errors multiError `json:"errors"`
}{
@ -191,7 +191,7 @@ func errorToContent(err error) interface{} {
}
func api(
fn func(*http.Request) (interface{}, error),
fn func(*http.Request) (any, error),
) func(http.ResponseWriter, *http.Request) {
return func(rw http.ResponseWriter, r *http.Request) {

View file

@ -216,7 +216,7 @@ func (p *processor) uploadRequest(filename string) (*http.Request, error) {
}
if !p.opts.NoSchemaCheck {
var doc interface{}
var doc any
if err := json.NewDecoder(bytes.NewReader(data)).Decode(&doc); err != nil {
return nil, err
}