-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
60 lines (56 loc) · 2.12 KB
/
config.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
58
59
60
package m3ugen
import (
"fmt"
)
// Config is the configuration a playlist generation needs to be performed.
type Config struct {
// If the detailed information should be outputted to the
// console as it is scanning and generating the playlist.
Verbose bool `json:"verbose"`
// Debug indicates if detailed debug information should be outputted to the console.
Debug bool `json:"debug"`
// The path of the output playlist.
OutputPath string `json:"output"`
// The list of folders to scan for files.
ScanFolders []string `json:"scan"`
// List of extensions to filter for. If empty, do not filter on extensions.
Extensions []string `json:"extensions"`
// If the list should be written in the order the files were
// scanned (false) or in a randomised way (true).
RandomizeList bool `json:"randomize"`
// Maximum entries to output in the playlist -1 means "none".
MaximumEntries int `json:"maximum"`
// If the tool should report duplicate entries in the detected files
// (the configured path could be duplicates or include one another).
DetectDuplicates bool `json:"detect_duplicates"`
// Number of workers scanning the folders.
ScanFolderWorkers int `json:"scan_folder_workers"`
// Number of workers filtering the files.
ReceiveFilesWorkers int `json:"receive_files_workers"`
// Buffer size of the various Go channels used while scanning.
ChannelsBufferSize int `json:"channels_buffer_size"`
}
// NewDefaultConfig creates a configuration with default values.
func NewDefaultConfig() *Config {
return &Config{
Verbose: false,
Debug: false,
OutputPath: "",
ScanFolders: nil,
Extensions: nil,
RandomizeList: false,
MaximumEntries: 0, // no maximum
ScanFolderWorkers: 4,
ReceiveFilesWorkers: 4,
ChannelsBufferSize: 1024,
}
}
func (c *Config) Validate() error {
if c.OutputPath == "" { // TODO: Make it so no output path = output to stdout
return fmt.Errorf("configuration requires an output file path (OutputPath)")
}
if len(c.ScanFolders) < 1 {
return fmt.Errorf("configuration requires at least one folder to scan (ScanFolders)")
}
return nil
}