Skip to content

Instantly share code, notes, and snippets.

@taman-islam
Last active June 24, 2025 21:27
Show Gist options
  • Save taman-islam/319ede3322a647c4fdae42a13309d253 to your computer and use it in GitHub Desktop.
Save taman-islam/319ede3322a647c4fdae42a13309d253 to your computer and use it in GitHub Desktop.
Example: ServicePool
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