Skip to content

Commit 3403c89

Browse files
committed
feat: expose explanation props json
1 parent 2713ba0 commit 3403c89

File tree

1 file changed

+20
-36
lines changed

1 file changed

+20
-36
lines changed

khata.go

+20-36
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,10 @@ func (kt *KhataTrace) FunctionName() string {
3838
}
3939

4040
type KhataExplanation struct {
41-
message string
42-
file string
43-
line int
44-
functionName string
45-
}
46-
47-
func (ke *KhataExplanation) Message() string {
48-
return ke.message
49-
}
50-
51-
func (ke *KhataExplanation) File() string {
52-
return ke.file
53-
}
54-
55-
func (ke *KhataExplanation) Line() int {
56-
return ke.line
57-
}
58-
59-
func (ke *KhataExplanation) FunctionName() string {
60-
return ke.functionName
41+
Message string `json:"message"`
42+
File string `json:"file"`
43+
Line int `json:"line"`
44+
FunctionName string `json:"functionName"`
6145
}
6246

6347
type KhataTemplate struct {
@@ -414,10 +398,10 @@ func (k *Khata) Explain(explanation string) *Khata {
414398
lastTrace := collectCallerTrace()
415399

416400
k.explanationStack = append(k.explanationStack, KhataExplanation{
417-
message: explanation,
418-
file: lastTrace.file,
419-
line: lastTrace.line,
420-
functionName: lastTrace.functionName,
401+
Message: explanation,
402+
File: lastTrace.file,
403+
Line: lastTrace.line,
404+
FunctionName: lastTrace.functionName,
421405
})
422406

423407
return k
@@ -428,10 +412,10 @@ func (k *Khata) Explainf(format string, args ...interface{}) *Khata {
428412
lastTrace := collectCallerTrace()
429413

430414
k.explanationStack = append(k.explanationStack, KhataExplanation{
431-
message: fmt.Sprintf(format, args...),
432-
file: lastTrace.file,
433-
line: lastTrace.line,
434-
functionName: lastTrace.functionName,
415+
Message: fmt.Sprintf(format, args...),
416+
File: lastTrace.file,
417+
Line: lastTrace.line,
418+
FunctionName: lastTrace.functionName,
435419
})
436420

437421
return k
@@ -462,21 +446,21 @@ func (k *Khata) Debug() *Khata {
462446
println(fmt.Sprintf("\n=== %sExplanations%s", colors.BoldYellow, colors.Reset))
463447

464448
for _, explanation := range explanations {
465-
file := tryTrimmingPath(explanation.file)
466-
funcName := tryTrimmingFunc(explanation.functionName)
449+
file := tryTrimmingPath(explanation.File)
450+
funcName := tryTrimmingFunc(explanation.FunctionName)
467451
p := fmt.Sprintf(
468452
" %s%s%s:%s%d%s (%s%s%s)\n └── %s%s%s",
469453
colors.UnderlineGray,
470454
file,
471455
colors.Reset,
472456
colors.Green,
473-
explanation.line,
457+
explanation.Line,
474458
colors.Reset,
475459
colors.Cyan,
476460
funcName,
477461
colors.Reset,
478462
colors.BoldWhite,
479-
explanation.message,
463+
explanation.Message,
480464
colors.Reset,
481465
)
482466
fmt.Println(p)
@@ -574,10 +558,10 @@ func (k *Khata) ToJSON() string {
574558

575559
for i, e := range explanations {
576560
explanationsMap[i] = map[string]interface{}{
577-
"file": e.file,
578-
"line": e.line,
579-
"functionName": e.functionName,
580-
"message": e.message,
561+
"file": e.File,
562+
"line": e.Line,
563+
"functionName": e.FunctionName,
564+
"message": e.Message,
581565
}
582566
}
583567

0 commit comments

Comments
 (0)