Last active
June 24, 2025 21:27
-
-
Save taman-islam/319ede3322a647c4fdae42a13309d253 to your computer and use it in GitHub Desktop.
Example: ServicePool
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package example | |
import ( | |
"database/sql" | |
"fmt" | |
"time" | |
"go.mongodb.org/mongo-driver/mongo" | |
"your_project/cacheService" | |
"your_project/servicePool" | |
) | |
type FooService struct { | |
db *sql.DB | |
mdb *mongo.Client | |
cs *cacheService.CacheService | |
} | |
var fooServicePool = servicePool.NewServicePool[*FooService](10, 10*time.Minute) | |
func GetFooService(db *sql.DB, mdb *mongo.Client, cs *cacheService.CacheService) *FooService { | |
key := fmt.Sprintf("fooService:%p:%p:%p", db, mdb, cs) | |
return fooServicePool.GetOrPut(key, func() *FooService { | |
return &FooService{db: db, mdb: mdb, cs: cs} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment