docs: pkg inline

This commit is contained in:
Mohamed Sohail 2023-02-17 11:43:20 +03:00
parent 4d13a14dc2
commit fb5ab81be5
Signed by: kamikazechaser
GPG Key ID: 7DD45520C01CD85D
6 changed files with 8 additions and 59 deletions

View File

@ -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,

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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

View File

@ -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
}

View File

@ -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 (