github.com/containerd/Containerd@v1.4.13/services/content/service.go (about)

     1  /*
     2     Copyright The containerd Authors.
     3  
     4     Licensed under the Apache License, Version 2.0 (the "License");
     5     you may not use this file except in compliance with the License.
     6     You may obtain a copy of the License at
     7  
     8         http://www.apache.org/licenses/LICENSE-2.0
     9  
    10     Unless required by applicable law or agreed to in writing, software
    11     distributed under the License is distributed on an "AS IS" BASIS,
    12     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13     See the License for the specific language governing permissions and
    14     limitations under the License.
    15  */
    16  
    17  package content
    18  
    19  import (
    20  	"github.com/containerd/containerd/content"
    21  	"github.com/containerd/containerd/plugin"
    22  	"github.com/containerd/containerd/services"
    23  	"github.com/containerd/containerd/services/content/contentserver"
    24  	"github.com/pkg/errors"
    25  )
    26  
    27  func init() {
    28  	plugin.Register(&plugin.Registration{
    29  		Type: plugin.GRPCPlugin,
    30  		ID:   "content",
    31  		Requires: []plugin.Type{
    32  			plugin.ServicePlugin,
    33  		},
    34  		InitFn: func(ic *plugin.InitContext) (interface{}, error) {
    35  			plugins, err := ic.GetByType(plugin.ServicePlugin)
    36  			if err != nil {
    37  				return nil, err
    38  			}
    39  			p, ok := plugins[services.ContentService]
    40  			if !ok {
    41  				return nil, errors.New("content store service not found")
    42  			}
    43  			cs, err := p.Instance()
    44  			if err != nil {
    45  				return nil, err
    46  			}
    47  			return contentserver.New(cs.(content.Store)), nil
    48  		},
    49  	})
    50  }