package config import ( "os" "gopkg.in/yaml.v3" ) var defaultCfg = ServerConfig{ ServerName: "My Fileserver", WebPort: 8080, Directories: []DirectoryConfig{ { Id: "example", DisplayName: "Example Directory", Path: "/path/to/directory", }, }, } // Directory represents a configuration for a directory to be served. type DirectoryConfig struct { Id string `yaml:"id"` DisplayName string `yaml:"display_name"` Description string `yaml:"description"` Path string `yaml:"path"` } // ServerConfig represents a configuration for the fileserver. type ServerConfig struct { ServerName string `yaml:"server_name"` WebPort int `yaml:"web_port"` Directories []DirectoryConfig `yaml:"directories"` } // LoadConfig loads configuration from a YAML file. func LoadConfig(path string) (*ServerConfig, error) { data, err := os.ReadFile(path) if err != nil { return nil, err } var cfg ServerConfig if err := yaml.Unmarshal(data, &cfg); err != nil { return nil, err } return &cfg, nil } // WriteExampleConfig writes an example configuration to a YAML file. func WriteExampleConfig(filepath string) error { data, err := yaml.Marshal(&defaultCfg) if err != nil { return err } return os.WriteFile(filepath, data, 0644) }