File: config.go

package info (click to toggle)
docker.io 20.10.24%2Bdfsg1-1%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bookworm-proposed-updates
  • size: 60,824 kB
  • sloc: sh: 5,621; makefile: 593; ansic: 179; python: 162; asm: 7
file content (36 lines) | stat: -rw-r--r-- 802 bytes parent folder | download | duplicates (8)
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
package local

import (
	"github.com/pkg/errors"
)

// CreateConfig is used to configure new instances of driver
type CreateConfig struct {
	DisableCompression bool
	MaxFileSize        int64
	MaxFileCount       int
}

func newDefaultConfig() *CreateConfig {
	return &CreateConfig{
		MaxFileSize:        defaultMaxFileSize,
		MaxFileCount:       defaultMaxFileCount,
		DisableCompression: !defaultCompressLogs,
	}
}

func validateConfig(cfg *CreateConfig) error {
	if cfg.MaxFileSize < 0 {
		return errors.New("max size should be a positive number")
	}
	if cfg.MaxFileCount < 0 {
		return errors.New("max file count cannot be less than 0")
	}

	if !cfg.DisableCompression {
		if cfg.MaxFileCount <= 1 {
			return errors.New("compression cannot be enabled when max file count is 1")
		}
	}
	return nil
}