Documentation ¶
Overview ¶
Package docs holds go code for inclusion into the prose documentation.
The documentation is available online at https://quay.github.io/claircore/
Example (Libindex) ¶
ctx := context.TODO() // ANCHOR: new opts := new(libindex.Options) // Populate with desired settings... lib, err := libindex.New(ctx, opts, http.DefaultClient) if err != nil { panic(err) } defer lib.Close(ctx) // Remember to cleanup when done. // ANCHOR_END: new // ANCHOR: index m := new(claircore.Manifest) // Populate somehow ... ir, err := lib.Index(ctx, m) if err != nil { panic(err) } // ANCHOR_END: index _ = ir // ANCHOR: indexreport ir, ok, err := lib.IndexReport(ctx, m.Hash) if err != nil { panic(err) } // ANCHOR_END: indexreport _ = ok var prevState string // ANCHOR: state state, err := lib.State(ctx) if err != nil { panic(err) } if state == prevState { // Nothing to do. return } // Otherwise, re-index manifest. // ANCHOR_END: state // ANCHOR: affectedmanifests var vulns []claircore.Vulnerability affected, err := lib.AffectedManifests(ctx, vulns) if err != nil { panic(err) } for manifest, vulns := range affected.VulnerableManifests { for _, vuln := range vulns { fmt.Printf("vuln affecting manifest %s: %+v", manifest, vuln) } } // ANCHOR_END: affectedmanifests
Output:
Example (Libvuln) ¶
ctx := context.TODO() // ANCHOR: new opts := new(libvuln.Options) // Populate with desired settings... lib, err := libvuln.New(ctx, opts) if err != nil { panic(err) } defer lib.Close(ctx) // ANCHOR_END: new liopts := new(libindex.Options) // Populate with desired settings... indexer, err := libindex.New(ctx, liopts, http.DefaultClient) if err != nil { panic(err) } defer indexer.Close(ctx) // ANCHOR: scan m := new(claircore.Manifest) // Populate somehow ... ir, err := indexer.Index(ctx, m) if err != nil { panic(err) } vr, err := lib.Scan(ctx, ir) if err != nil { panic(err) } // ANCHOR_END: scan _ = vr // ANCHOR: ops ops, err := lib.UpdateOperations(ctx, `updater`) if err != nil { panic(err) } // ANCHOR_END: ops // ANCHOR: ops_print for updater, ops := range ops { fmt.Printf("ops for updater %s, %+v", updater, ops) } // ANCHOR_END: ops_print // ANCHOR: ops_diff for upd, ops := range ops { fmt.Printf("updater: %v", upd) diff, err := lib.UpdateDiff(ctx, ops[1].Ref, ops[0].Ref) if err != nil { panic(err) } for _, vuln := range diff.Added { fmt.Printf("vuln %+v added in %v", vuln, diff.Cur.Ref) } } // ANCHOR_END: ops_diff
Output:
Example (Logger) ¶
Example_logger is an example annotated for inclusion in the prose documentation.
package main import ( "context" "time" "github.com/quay/zlog" ) func main() { ctx := context.Background() // ANCHOR: kvs ctx = zlog.ContextWithValues(ctx, "component", "Example.Logger") // ANCHOR_END: kvs // ANCHOR: bad_example zlog.Info(ctx).Msgf("done at: %v", time.Now()) // ANCHOR_END: bad_example // ANCHOR: good_example zlog.Info(ctx). Time("time", time.Now()). Msgf("done") // ANCHOR_END: good_example }
Output:
Example (Vulnerabilityreport) ¶
var report claircore.VulnerabilityReport // ANCHOR: example for pkgID, vulnIDS := range report.PackageVulnerabilities { // get package data structure pkg := report.Packages[pkgID] for _, vulnID := range vulnIDS { vuln := report.Vulnerabilities[vulnID] fmt.Printf("package %+v affected by vuln %+v", pkg, vuln) } } // ANCHOR_END: example
Output:
Click to show internal directories.
Click to hide internal directories.