registry.go 826 B

1234567891011121314151617181920212223242526272829
  1. package apiv1
  2. import (
  3. "context"
  4. "sync"
  5. )
  6. var (
  7. registry = new(sync.Map)
  8. )
  9. // CertificateAuthorityServiceNewFunc is the type that represents the method to initialize a new
  10. // CertificateAuthorityService.
  11. type CertificateAuthorityServiceNewFunc func(ctx context.Context, opts Options) (CertificateAuthorityService, error)
  12. // Register adds to the registry a method to create a KeyManager of type t.
  13. func Register(t Type, fn CertificateAuthorityServiceNewFunc) {
  14. registry.Store(t.String(), fn)
  15. }
  16. // LoadCertificateAuthorityServiceNewFunc returns the function to initialize a KeyManager.
  17. func LoadCertificateAuthorityServiceNewFunc(t Type) (CertificateAuthorityServiceNewFunc, bool) {
  18. v, ok := registry.Load(t.String())
  19. if !ok {
  20. return nil, false
  21. }
  22. fn, ok := v.(CertificateAuthorityServiceNewFunc)
  23. return fn, ok
  24. }