43 lines
		
	
	
		
			1023 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			43 lines
		
	
	
		
			1023 B
		
	
	
	
		
			Go
		
	
	
	
	
	
package file
 | 
						|
 | 
						|
import (
 | 
						|
	"github.com/asaskevich/govalidator"
 | 
						|
	"github.com/juju/errors"
 | 
						|
)
 | 
						|
 | 
						|
// ConfigStruct is the configuration for File Provider.
 | 
						|
type ConfigStruct struct {
 | 
						|
	Filename   string `yaml:"filename"`
 | 
						|
	MaxLines   int    `yaml:"max_lines"`
 | 
						|
	MaxSize    int    `yaml:"max_size"`
 | 
						|
	Daily      bool   `yaml:"daily"`
 | 
						|
	MaxDays    int    `yaml:"max_days"`
 | 
						|
	Rotate     bool   `yaml:"rotate"`
 | 
						|
	Perm       string `yaml:"perm"`
 | 
						|
	RotatePerm string `yaml:"rotate_perm"`
 | 
						|
}
 | 
						|
 | 
						|
// IsValid will check that the File configuration is valid.
 | 
						|
func (c *ConfigStruct) IsValid() error {
 | 
						|
 | 
						|
	if c.Filename == "" {
 | 
						|
		return errors.NotValidf("Path is empty in File configuration")
 | 
						|
	} else if isValid, _ := govalidator.IsFilePath(c.Filename); !isValid {
 | 
						|
		return errors.NotValidf("Path is invalid in File configuration")
 | 
						|
	}
 | 
						|
 | 
						|
	return nil
 | 
						|
}
 | 
						|
 | 
						|
// ApplyDefault will check config and apply default on mandatory values.
 | 
						|
func (c *ConfigStruct) ApplyDefault() {
 | 
						|
 | 
						|
	if c.Perm == "" {
 | 
						|
		c.Perm = "0660"
 | 
						|
	}
 | 
						|
 | 
						|
	if c.RotatePerm == "" {
 | 
						|
		c.RotatePerm = "0440"
 | 
						|
	}
 | 
						|
}
 |