Test Setup Failed
Branch master (edd16e)
by Christian
01:36
created

e2hformat.removeBeforeFolder   A

Complexity

Conditions 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nop 2
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
/*
2
Package e2hformat is the formatter's package of the Enhanced Error Handling module
3
*/
4
package e2hformat
5
6
import (
7
	"fmt"
8
9
	"github.com/cdleo/go-commons/formatter"
10
)
11
12
type Format int8
13
14
// Allowed output formats.
15
const (
16
	Format_Raw Format = iota
17
	Format_JSON
18
)
19
20
type Params struct {
21
	//Sets if the output will be beautified
22
	Beautify bool
23
	//Sets if at top of the stack shows the last trace (invert = true) or the origin error (invert = false)
24
	InvertCallstack bool
25
	//Sets the way in with the filepaths are managed.
26
	PathHidingMethod formatter.HidingMethod
27
	//Value to use, according to the selected 'PathHidingMethod'
28
	PathHidingValue string
29
}
30
31
type Formatter interface {
32
	Source(err error) string
33
	Format(err error, params Params) string
34
}
35
36
func NewFormatter(format Format) (Formatter, error) {
37
38
	switch format {
39
	case Format_Raw:
40
		return newRawFormatter(), nil
41
	case Format_JSON:
42
		return newJSONFormatter(), nil
43
	default:
44
		return nil, fmt.Errorf("unknown format [%d]", format)
45
	}
46
47
}
48