pool.go 567 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package service
  2. import (
  3. "fmt"
  4. "github.com/google/uuid"
  5. )
  6. const (
  7. META = "service"
  8. )
  9. func NewPool(services ...Service) (pool map[string]Service) {
  10. pool = make(map[string]Service)
  11. for i := range services {
  12. if services[i] == nil {
  13. continue
  14. }
  15. sid := services[i].String()
  16. if sid == "" {
  17. sid = uuid.NewString()
  18. }
  19. pool[sid] = services[i]
  20. }
  21. return
  22. }
  23. func Pool(v any) (map[string]Service, error) {
  24. pool, ok := v.(map[string]Service)
  25. if !ok {
  26. return nil, fmt.Errorf("illegal state: could not extract service pool")
  27. }
  28. return pool, nil
  29. }