@@ -31,10 +31,10 @@ This struct allows to wrap useful messages to describe the behaviour of a functi
3131[source, go]
3232----
3333type Wrapper struct {
34- BeforeMessage [] string
35- Task task.Task
36- AfterMessage [] string
37- ErrorMessage [] string
34+ BeforeMessage string
35+ Task task.Task
36+ AfterMessage string
37+ ErrorMessage string
3838}
3939
4040type task.Task func() task.Result
@@ -45,71 +45,4 @@ type task.Result struct {
4545}
4646----
4747
48- Where `BeforeMessage`, `AfterMessage` and `ErrorMessage` are slices of different strings, one string per verbosity level supported.
49- Example : `verbosity = 2` equals to print second cell of each slice (`index = 1`).
50-
51- `Task` is the task to accomplish and `Result` represents a possible return value, with an error.
52-
53- Let's put everything in practice with the following example:
54- [source, go]
55- ----
56- myWrapper := task.Wrapper{
57- BeforeMessage: []string{
58- "Hello",
59- },
60- AfterMessage: []string{
61- "Good bye",
62- "Farewell, my friend",
63- },
64- ErrorMessage: []string{
65- "There's something's rotten in Denmark...",
66- `Through me the way into the suffering city
67- Through me the way to eternal pain,
68- Through me the way that runs among the lost....`,
69- },
70- Task: func() task.Result {
71- fmt.Println("Printing awesome poetry quotes on error")
72- return task.Result{
73- Error: errors.New("poetry error")
74- }
75- },
76- }
77- ----
78-
79- We espect this wrapper to print different stuff when executed. For example:
80- [source, go]
81- ----
82- var verbosity int = 1
83- myWrapper.Execute(verbosity)
84- fmt.Println()
85- verbosity++
86- myWrapper.Execute(verbosity)
87- fmt.Println()
88- verbosity++ // Note that verbosity = 3 and there is no slice in BeforeMessage,
89- // AfterMessage, ErrorMessage with 3 elements
90- myWrapper.Execute(verbosity)
91- ----
92-
93- Expects to print:
94- ----
95- Hello
96- Printing awesome poetry quotes on error
97- There's something's rotten in Denmark...
98- Good bye
99-
100- Hello
101- Printing awesome poetry quotes on error
102- Through me the way into the suffering city
103- Through me the way to eternal pain,
104- Through me the way that runs among the lost....
105- Farewell, my friend
106-
107- Hello
108- Printing awesome poetry quotes on error
109- Through me the way into the suffering city
110- Through me the way to eternal pain,
111- Through me the way that runs among the lost....
112- Farewell, my friend
113- ----
114-
115- Check out the documentation for further details
48+ Check out the documentation for further details
0 commit comments