Skip to content

Commit 3e0229d

Browse files
committed
Move all debugging stuff to debug.go, move context keys out of hooks.go into a new file
1 parent bb0f7ca commit 3e0229d

File tree

4 files changed

+24
-22
lines changed

4 files changed

+24
-22
lines changed

boil/context_keys.go

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package boil
2+
3+
type contextType int
4+
5+
const (
6+
ctxSkipHooks contextType = iota
7+
ctxSkipTimestamps
8+
ctxDebug
9+
ctxDebugWriter
10+
)

boil/debug.go

+14-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,21 @@ package boil
33
import (
44
"context"
55
"io"
6+
"os"
67
)
78

8-
// WithDebug modifies a context to configure debug writing.
9+
// DebugMode is a flag controlling whether generated sql statements and
10+
// debug information is outputted to the DebugWriter handle
11+
//
12+
// NOTE: This should be disabled in production to avoid leaking sensitive data
13+
var DebugMode = false
14+
15+
// DebugWriter is where the debug output will be sent if DebugMode is true
16+
var DebugWriter io.Writer = os.Stdout
17+
18+
// WithDebug modifies a context to configure debug writing. If true,
19+
// all queries made using this context will be outputted to the io.Writer
20+
// returned by DebugWriterFrom.
921
func WithDebug(ctx context.Context, debug bool) context.Context {
1022
return context.WithValue(ctx, ctxDebug, debug)
1123
}
@@ -26,7 +38,7 @@ func WithDebugWriter(ctx context.Context, writer io.Writer) context.Context {
2638
return context.WithValue(ctx, ctxDebugWriter, writer)
2739
}
2840

29-
// DebugWriterFrom returns the debug writer for the contexts, or DebugWriter
41+
// DebugWriterFrom returns the debug writer for the context, or DebugWriter
3042
// if not set.
3143
func DebugWriterFrom(ctx context.Context) io.Writer {
3244
writer, ok := ctx.Value(ctxDebugWriter).(io.Writer)

boil/global.go

-11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package boil
22

33
import (
4-
"io"
5-
"os"
64
"time"
75
)
86

@@ -15,15 +13,6 @@ var (
1513
timestampLocation = time.UTC
1614
)
1715

18-
// DebugMode is a flag controlling whether generated sql statements and
19-
// debug information is outputted to the DebugWriter handle
20-
//
21-
// NOTE: This should be disabled in production to avoid leaking sensitive data
22-
var DebugMode = false
23-
24-
// DebugWriter is where the debug output will be sent if DebugMode is true
25-
var DebugWriter io.Writer = os.Stdout
26-
2716
// SetDB initializes the database handle for all template db interactions
2817
func SetDB(db Executor) {
2918
currentDB = db

boil/hooks.go

-9
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,6 @@ package boil
22

33
import "context"
44

5-
type contextType int
6-
7-
const (
8-
ctxSkipHooks contextType = iota
9-
ctxSkipTimestamps
10-
ctxDebug
11-
ctxDebugWriter
12-
)
13-
145
// SkipHooks modifies a context to prevent hooks from running for any query
156
// it encounters.
167
func SkipHooks(ctx context.Context) context.Context {

0 commit comments

Comments
 (0)