github.com/quay/claircore@v1.5.28/libindex/examples_test.go (about)

     1  package libindex_test
     2  
     3  import (
     4  	"context"
     5  	"net/http"
     6  	"os"
     7  
     8  	"github.com/quay/claircore"
     9  	"github.com/quay/claircore/datastore/postgres"
    10  	"github.com/quay/claircore/libindex"
    11  	"github.com/quay/claircore/pkg/ctxlock"
    12  )
    13  
    14  func ExampleLibindex() {
    15  	ctx := context.TODO()
    16  	pool, err := postgres.Connect(ctx, "connection string", "libindex-test")
    17  	if err != nil {
    18  		panic(err)
    19  	}
    20  
    21  	store, err := postgres.InitPostgresIndexerStore(ctx, pool, true)
    22  	if err != nil {
    23  		panic(err)
    24  	}
    25  
    26  	ctxLocker, err := ctxlock.New(ctx, pool)
    27  	if err != nil {
    28  		panic(err)
    29  	}
    30  
    31  	opts := &libindex.Options{
    32  		Store:      store,
    33  		Locker:     ctxLocker,
    34  		FetchArena: libindex.NewRemoteFetchArena(http.DefaultClient, os.TempDir()),
    35  		// see definition for more configuration options
    36  	}
    37  	lib, err := libindex.New(ctx, opts, http.DefaultClient)
    38  	if err != nil {
    39  		panic(err)
    40  	}
    41  	m := &claircore.Manifest{}
    42  
    43  	ir, err := lib.Index(ctx, m)
    44  	if err != nil {
    45  		panic(err)
    46  	}
    47  	if ir.State == "IndexError" {
    48  		panic(ir.Err)
    49  	}
    50  }