nametoguid.go 847 B

1234567891011121314151617181920212223242526272829303132333435
  1. package wclayer
  2. import (
  3. "github.com/Microsoft/hcsshim/internal/guid"
  4. "github.com/Microsoft/hcsshim/internal/hcserror"
  5. "github.com/sirupsen/logrus"
  6. )
  7. // NameToGuid converts the given string into a GUID using the algorithm in the
  8. // Host Compute Service, ensuring GUIDs generated with the same string are common
  9. // across all clients.
  10. func NameToGuid(name string) (id guid.GUID, err error) {
  11. title := "hcsshim::NameToGuid"
  12. fields := logrus.Fields{
  13. "name": name,
  14. }
  15. logrus.WithFields(fields).Debug(title)
  16. defer func() {
  17. if err != nil {
  18. fields[logrus.ErrorKey] = err
  19. logrus.WithFields(fields).Error(err)
  20. } else {
  21. logrus.WithFields(fields).Debug(title + " - succeeded")
  22. }
  23. }()
  24. err = nameToGuid(name, &id)
  25. if err != nil {
  26. err = hcserror.New(err, title+" - failed", "")
  27. return
  28. }
  29. fields["guid"] = id.String()
  30. return
  31. }