...

Source file src/github.com/Microsoft/hcsshim/internal/wclayer/nametoguid.go

Documentation: github.com/Microsoft/hcsshim/internal/wclayer

     1  //go:build windows
     2  
     3  package wclayer
     4  
     5  import (
     6  	"context"
     7  
     8  	"github.com/Microsoft/go-winio/pkg/guid"
     9  	"github.com/Microsoft/hcsshim/internal/hcserror"
    10  	"github.com/Microsoft/hcsshim/internal/oc"
    11  	"go.opencensus.io/trace"
    12  )
    13  
    14  // NameToGuid converts the given string into a GUID using the algorithm in the
    15  // Host Compute Service, ensuring GUIDs generated with the same string are common
    16  // across all clients.
    17  func NameToGuid(ctx context.Context, name string) (_ guid.GUID, err error) {
    18  	title := "hcsshim::NameToGuid"
    19  	ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck
    20  	defer span.End()
    21  	defer func() { oc.SetSpanStatus(span, err) }()
    22  	span.AddAttributes(trace.StringAttribute("objectName", name))
    23  
    24  	var id guid.GUID
    25  	err = nameToGuid(name, &id)
    26  	if err != nil {
    27  		return guid.GUID{}, hcserror.New(err, title, "")
    28  	}
    29  	span.AddAttributes(trace.StringAttribute("guid", id.String()))
    30  	return id, nil
    31  }
    32  

View as plain text