You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.0 KiB
Go

package Configuration
// Imports
import (
"errors"
"net/url"
"os"
)
// Validate File Server
func validateFileServer(fileServerConfiguration FileServerConfiguration) error {
// If Active
if fileServerConfiguration.Active == true {
// Route Number
var routeNumber uint
// Routes
for routeNumber = 0; routeNumber < uint(len(fileServerConfiguration.Routes)); routeNumber++ {
// Resource Path
item, err := os.Stat(fileServerConfiguration.Routes[routeNumber].ResourcePath)
// Handle Error
if err != nil {
return errors.New("Error With Resource Path")
}
// Resource Path
if item.IsDir() == false {
return errors.New("Error With Resrouce Path")
}
// Serve Path
if string(fileServerConfiguration.Routes[routeNumber].ServePath[0]) != "/" {
return errors.New("Error With Serve Path")
}
// Serve Path
_, err = url.ParseRequestURI(fileServerConfiguration.Routes[routeNumber].ServePath)
// Handle Error
if err != nil {
return errors.New("Error With Serve Path")
}
}
}
// Return
return nil
}