forked from mutablelogic/go-whisper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopt.go
57 lines (48 loc) · 1000 Bytes
/
opt.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
48
49
50
51
52
53
54
55
56
57
package whisper
import (
// Namespace imports
. "github.com/djthorpe/go-errors"
)
///////////////////////////////////////////////////////////////////////////////
// TYPES
type opts struct {
MaxConcurrent int
logfn LogFn
debug bool
gpu int
}
type Opt func(*opts) error
type LogFn func(string)
///////////////////////////////////////////////////////////////////////////////
// PUBLIC METHODS
// Set maximum number of concurrent tasks
func OptMaxConcurrent(v int) Opt {
return func(o *opts) error {
if v < 1 {
return ErrBadParameter.With("max concurrent must be greater than zero")
}
o.MaxConcurrent = v
return nil
}
}
// Set logging function
func OptLog(fn LogFn) Opt {
return func(o *opts) error {
o.logfn = fn
return nil
}
}
// Set debugging
func OptDebug() Opt {
return func(o *opts) error {
o.debug = true
return nil
}
}
// Disable GPU acceleration
func OptNoGPU() Opt {
return func(o *opts) error {
o.gpu = -1
return nil
}
}