-
Notifications
You must be signed in to change notification settings - Fork 0
/
foobar.go
47 lines (37 loc) · 882 Bytes
/
foobar.go
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
46
47
// Package gonew contains a blueprint project skeleton.
package gonew
import (
"context"
"errors"
"github.com/hamba/logger/v2"
)
// Foobar represents a foobar application.
type Foobar struct {
rng int
log *logger.Logger
}
// OptFunc represents an optional foobar configuration.
type OptFunc func(*Foobar)
// WithNotSoRandomOpt applies a not so random foobar configuration option.
func WithNotSoRandomOpt(rng int) OptFunc {
return func(f *Foobar) {
f.rng = rng
}
}
// New returns a new foobar.
func New(log *logger.Logger, opts ...OptFunc) (*Foobar, error) {
f := Foobar{
log: log,
}
for _, opt := range opts {
opt(&f)
}
return &f, nil
}
// Foobar runs foobar.
func (f *Foobar) Foobar(_ context.Context, msg string) (string, error) {
if msg == "foobar" {
return "", errors.New("foobar") //nolint:goerr113 // It's just an example.
}
return msg, nil
}