nametoguid.go 918 B

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