Added static serving
This commit is contained in:
@@ -13,10 +13,13 @@ type GlobalConfig struct {
|
||||
}
|
||||
|
||||
type SiteConfig struct {
|
||||
Repo string `yaml:"repo"`
|
||||
Owner string `yaml:"owner"`
|
||||
Branch string `yaml:"branch"`
|
||||
Domain string `yaml:"domain"`
|
||||
Name string `yaml:"name"`
|
||||
Repo string `yaml:"repo"`
|
||||
Owner string `yaml:"owner"`
|
||||
Branch string `yaml:"branch"`
|
||||
Domain string `yaml:"domain"`
|
||||
SPA bool `yaml:"spa"`
|
||||
NotFoundFile string `yaml:"not_found_file"`
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
@@ -44,6 +47,9 @@ func validateConfig(config *Config) error {
|
||||
return &Error{Field: "global.storage_path", Message: "Storage path is required"}
|
||||
}
|
||||
for i, site := range config.Sites {
|
||||
if site.Name == "" {
|
||||
return &Error{Field: "sites[" + string(i) + "].name", Message: "Name is required"}
|
||||
}
|
||||
if site.Repo == "" {
|
||||
return &Error{Field: "sites[" + string(i) + "].repo", Message: "Repo is required"}
|
||||
}
|
||||
@@ -60,6 +66,14 @@ func validateConfig(config *Config) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func applyDefaults(config *Config) {
|
||||
for i := range config.Sites {
|
||||
if config.Sites[i].NotFoundFile == "" {
|
||||
config.Sites[i].NotFoundFile = "404.html"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Load(path string) (*Config, error) {
|
||||
f, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
@@ -72,6 +86,8 @@ func Load(path string) (*Config, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
applyDefaults(&config)
|
||||
|
||||
err = validateConfig(&config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user