...

Source file src/github.com/google/go-containerregistry/pkg/v1/empty/index.go

Documentation: github.com/google/go-containerregistry/pkg/v1/empty

     1  // Copyright 2018 Google LLC All Rights Reserved.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //    http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package empty
    16  
    17  import (
    18  	"encoding/json"
    19  	"errors"
    20  
    21  	v1 "github.com/google/go-containerregistry/pkg/v1"
    22  	"github.com/google/go-containerregistry/pkg/v1/partial"
    23  	"github.com/google/go-containerregistry/pkg/v1/types"
    24  )
    25  
    26  // Index is a singleton empty index, think: FROM scratch.
    27  var Index = emptyIndex{}
    28  
    29  type emptyIndex struct{}
    30  
    31  func (i emptyIndex) MediaType() (types.MediaType, error) {
    32  	return types.OCIImageIndex, nil
    33  }
    34  
    35  func (i emptyIndex) Digest() (v1.Hash, error) {
    36  	return partial.Digest(i)
    37  }
    38  
    39  func (i emptyIndex) Size() (int64, error) {
    40  	return partial.Size(i)
    41  }
    42  
    43  func (i emptyIndex) IndexManifest() (*v1.IndexManifest, error) {
    44  	return base(), nil
    45  }
    46  
    47  func (i emptyIndex) RawManifest() ([]byte, error) {
    48  	return json.Marshal(base())
    49  }
    50  
    51  func (i emptyIndex) Image(v1.Hash) (v1.Image, error) {
    52  	return nil, errors.New("empty index")
    53  }
    54  
    55  func (i emptyIndex) ImageIndex(v1.Hash) (v1.ImageIndex, error) {
    56  	return nil, errors.New("empty index")
    57  }
    58  
    59  func base() *v1.IndexManifest {
    60  	return &v1.IndexManifest{
    61  		SchemaVersion: 2,
    62  		MediaType:     types.OCIImageIndex,
    63  		Manifests:     []v1.Descriptor{},
    64  	}
    65  }
    66  

View as plain text