github.com/webonyx/up@v0.7.4-0.20180808230834-91b94e551323/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  	// Prefix is an optional URL prefix for serving static files.
    15  	Prefix string `json:"prefix"`
    16  }
    17  
    18  // Validate implementation.
    19  func (s *Static) Validate() error {
    20  	info, err := os.Stat(s.Dir)
    21  
    22  	if os.IsNotExist(err) {
    23  		return nil
    24  	}
    25  
    26  	if err != nil {
    27  		return errors.Wrap(err, ".dir")
    28  	}
    29  
    30  	if !info.IsDir() {
    31  		return errors.Errorf(".dir %s is not a directory", s.Dir)
    32  	}
    33  
    34  	return nil
    35  }