aboutsummaryrefslogtreecommitdiff
path: root/business/business.go
blob: ecb54ad4323002ff364670b372a921920cd545cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package business
 
import (
"fmt"
 
"www.thenautilus.net/cgit/go-example/config"
"www.thenautilus.net/cgit/go-example/something"
)
 
type OverError struct {
Value, Threshold int
}
 
func (e OverError) Error() string {
return fmt.Sprintf("value %d is above threshold %d", e.Value, e.Threshold)
}
 
type Logic struct {
somethingClient *something.Something
threshold       int
}
 
func New(conf *config.BusinessLogicConfig, client *something.Something) Logic {
return Logic{
somethingClient: client,
threshold:       conf.Threshold,
}
}
 
func (bl *Logic) DoSomething() error {
value, err := bl.somethingClient.FetchValue()
if err != nil {
return fmt.Errorf("failed to fetch value: %w", err)
}
 
if value > bl.threshold {
fmt.Printf("OVER! %d > %d\n", value, bl.threshold)
 
return OverError{value, bl.threshold}
}
 
fmt.Printf("all good")
 
return nil
}