Skip to content

Commit

Permalink
Add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
sas1024 committed Oct 24, 2022
1 parent ec88bc5 commit e233561
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions sql_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ func SqlGroupFromContext(ctx context.Context) string {
return r
}

// WithTiming adds timings in JSON-RPC 2.0 Response via `extensions` field (not in spec). Middleware is active
// when `isDevel=true` or AllowDebugFunc returns `true`.
// WithTiming adds timings in JSON-RPC 2.0 Response via `extensions` field (not in spec).
// Middleware is active when `isDevel=true` or AllowDebugFunc returns `true` and http request is set.
// `DurationLocal` – total method execution time in ms.
// If `DurationRemote` or `DurationDiff` are set then `DurationLocal` excludes these values.
func WithTiming(isDevel bool, allowDebugFunc AllowDebugFunc) zenrpc.MiddlewareFunc {
Expand All @@ -70,6 +70,7 @@ func WithTiming(isDevel bool, allowDebugFunc AllowDebugFunc) zenrpc.MiddlewareFu
if !ok || req == nil {
return h(ctx, method, params)
}

reqClone := req.Clone(ctx)
if reqClone == nil || !allowDebugFunc(reqClone) {
return h(ctx, method, params)
Expand Down Expand Up @@ -102,8 +103,8 @@ func WithTiming(isDevel bool, allowDebugFunc AllowDebugFunc) zenrpc.MiddlewareFu
}

// WithSQLLogger adds `SQL` or `DurationSQL` fields in JSON-RPC 2.0 Response `extensions` field (not in spec).
// `DurationSQL` field is set then `isDevel=true` or AllowDebugFunc(allowDebugFunc) returns `true`.
// `SQL` field is set then `isDevel=true` or AllowDebugFunc(allowDebugFunc, allowSqlDebugFunc) returns `true`.
// `DurationSQL` field is set then `isDevel=true` or AllowDebugFunc(allowDebugFunc) returns `true` and http request is set.
// `SQL` field is set then `isDevel=true` or AllowDebugFunc(allowDebugFunc, allowSqlDebugFunc) returns `true` and http request is set.
func WithSQLLogger(db *pg.DB, isDevel bool, allowDebugFunc, allowSqlDebugFunc AllowDebugFunc) zenrpc.MiddlewareFunc {
// init sql logger
ql := NewSqlQueryLogger()
Expand All @@ -119,6 +120,7 @@ func WithSQLLogger(db *pg.DB, isDevel bool, allowDebugFunc, allowSqlDebugFunc Al
if !ok || req == nil {
return h(ctx, method, params)
}

reqClone := req.Clone(ctx)
if reqClone == nil || !allowDebugFunc(reqClone) {
return h(ctx, method, params)
Expand Down

0 comments on commit e233561

Please sign in to comment.