Total Lines | 41 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | /* |
||
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 | } |
||
48 |