Browse Source

service.Pool

Alexey Kim 1 year ago
parent
commit
d476587fba
2 changed files with 25 additions and 1 deletions
  1. 1 1
      go.mod
  2. 24 0
      service/pool.go

+ 1 - 1
go.mod

@@ -7,6 +7,7 @@ require (
 	github.com/Nerzal/gocloak/v13 v13.8.0
 	github.com/gofrs/uuid v4.4.0+incompatible
 	github.com/golang-jwt/jwt/v4 v4.5.0
+	github.com/google/uuid v1.3.0
 	github.com/labstack/echo-jwt/v4 v4.2.0
 	github.com/labstack/echo/v4 v4.11.1
 	github.com/urfave/cli/v2 v2.25.7
@@ -22,7 +23,6 @@ require (
 	github.com/go-resty/resty/v2 v2.7.0 // indirect
 	github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
 	github.com/golang-jwt/jwt/v5 v5.0.0 // indirect
-	github.com/google/uuid v1.3.0 // indirect
 	github.com/klauspost/compress v1.16.7 // indirect
 	github.com/labstack/gommon v0.4.0 // indirect
 	github.com/mattn/go-colorable v0.1.13 // indirect

+ 24 - 0
service/pool.go

@@ -0,0 +1,24 @@
+package service
+
+import (
+	"github.com/google/uuid"
+)
+
+func NewPool(services ...Service) (pool map[string]Service) {
+	pool = make(map[string]Service)
+
+	for i := range services {
+		if services[i] == nil {
+			continue
+		}
+
+		sid := services[i].String()
+		if sid == "" {
+			sid = uuid.NewString()
+		}
+
+		pool[sid] = services[i]
+	}
+
+	return
+}