github.com/motyar/up@v0.2.10/config/static.go (about)

     1  package config
     2  
     3  import (
     4  	"os"
     5  
     6  	"github.com/pkg/errors"
     7  )
     8  
     9  // Static configuration.
    10  type Static struct {
    11  	// Dir containing static files.
    12  	Dir string `json:"dir"`
    13  }
    14  
    15  // Default implementation.
    16  func (s *Static) Default() error {
    17  	if s.Dir == "" {
    18  		s.Dir = "."
    19  	}
    20  
    21  	return nil
    22  }
    23  
    24  // Validate implementation.
    25  func (s *Static) Validate() error {
    26  	info, err := os.Stat(s.Dir)
    27  
    28  	if os.IsNotExist(err) {
    29  		return nil
    30  	}
    31  
    32  	if err != nil {
    33  		return errors.Wrap(err, ".dir")
    34  	}
    35  
    36  	if !info.IsDir() {
    37  		return errors.Errorf(".dir %s is not a directory", s.Dir)
    38  	}
    39  
    40  	return nil
    41  }