mirror of
https://github.com/grassrootseconomics/cic-custodial.git
synced 2024-11-21 22:06:47 +01:00
docs: pkg inline
This commit is contained in:
parent
4d13a14dc2
commit
fb5ab81be5
@ -6,6 +6,7 @@ type AsynqLogg struct {
|
||||
logg *logf.Logger
|
||||
}
|
||||
|
||||
// NewAsynqLogg creates a logf based logging adapter for asynq.
|
||||
func NewAsynqLogg(lo logf.Logger) AsynqLogg {
|
||||
return AsynqLogg{
|
||||
logg: &lo,
|
||||
|
@ -1,21 +0,0 @@
|
||||
package logg
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/zerodha/logf"
|
||||
)
|
||||
|
||||
type RedisLogg struct {
|
||||
logg *logf.Logger
|
||||
}
|
||||
|
||||
func NewRedisTraceLogg(lo logf.Logger) RedisLogg {
|
||||
return RedisLogg{
|
||||
logg: &lo,
|
||||
}
|
||||
}
|
||||
|
||||
func (l RedisLogg) Printf(ctx context.Context, format string, v ...interface{}) {
|
||||
l.logg.Debug("redis", "debug", "format", format, "data", v)
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package logg
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/tracelog"
|
||||
"github.com/zerodha/logf"
|
||||
)
|
||||
|
||||
type PgxLogg struct {
|
||||
logg *logf.Logger
|
||||
}
|
||||
|
||||
func NewPgxTraceLogg(lo logf.Logger) PgxLogg {
|
||||
return PgxLogg{
|
||||
logg: &lo,
|
||||
}
|
||||
}
|
||||
|
||||
func (l PgxLogg) Log(ctx context.Context, level tracelog.LogLevel, msg string, data map[string]any) {
|
||||
l.logg.Debug("pgx", "level", level, "msg", msg, "data", data)
|
||||
}
|
@ -9,23 +9,15 @@ import (
|
||||
|
||||
type PostgresPoolOpts struct {
|
||||
DSN string
|
||||
// Debug bool
|
||||
// Logg tracelog.Logger
|
||||
}
|
||||
|
||||
// NewPostgresPool creates a reusbale connection pool across the cic-custodial component.
|
||||
func NewPostgresPool(o PostgresPoolOpts) (*pgxpool.Pool, error) {
|
||||
parsedConfig, err := pgxpool.ParseConfig(o.DSN)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// if o.Debug {
|
||||
// parsedConfig.ConnConfig.Tracer = &tracelog.TraceLog{
|
||||
// Logger: o.Logg,
|
||||
// LogLevel: tracelog.LogLevelDebug,
|
||||
// }
|
||||
// }
|
||||
|
||||
dbPool, err := pgxpool.NewWithConfig(context.Background(), parsedConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -8,9 +8,7 @@ import (
|
||||
)
|
||||
|
||||
type RedisPoolOpts struct {
|
||||
DSN string
|
||||
// Debug bool
|
||||
// Logg logg.RedisLogg
|
||||
DSN string
|
||||
MinIdleConns int
|
||||
}
|
||||
|
||||
@ -18,6 +16,8 @@ type RedisPool struct {
|
||||
Client *redis.Client
|
||||
}
|
||||
|
||||
// NewRedisPool creates a reusable connection across the cic-custodial componenent.
|
||||
// Note: Each db namespace requires its own connection pool.
|
||||
func NewRedisPool(o RedisPoolOpts) (*RedisPool, error) {
|
||||
redisOpts, err := redis.ParseURL(o.DSN)
|
||||
if err != nil {
|
||||
@ -28,10 +28,6 @@ func NewRedisPool(o RedisPoolOpts) (*RedisPool, error) {
|
||||
|
||||
redisClient := redis.NewClient(redisOpts)
|
||||
|
||||
// if o.Debug {
|
||||
// redis.SetLogger(o.Logg)
|
||||
// }
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
|
||||
@ -45,6 +41,7 @@ func NewRedisPool(o RedisPoolOpts) (*RedisPool, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Interface adapter for asynq to resuse the same Redis connection pool.
|
||||
func (r *RedisPool) MakeRedisClient() interface{} {
|
||||
return r.Client
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package status
|
||||
|
||||
// Status represents enum-like values received in the dispatcher from the RPC node.
|
||||
// It includes a subset of well-known and likely failures the dispatcher may encounter.
|
||||
type Status string
|
||||
|
||||
const (
|
||||
|
Loading…
Reference in New Issue
Block a user