📜 feeds is a multi-protocol / multi-platform feed aggregation service that produces twtxt feeds for consumption by twtxt clients. https://feeds.twtxt.net
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

47 lines
898 B

package main
import (
"io/ioutil"
"github.com/go-yaml/yaml"
)
type Config struct {
Root string
BaseURL string
MaxSize int64 // maximum feed size before rotating
Feeds map[string]string // name -> url
path string // path to config file that was loaded used by .Save()
}
func (conf *Config) Parse(data []byte) error {
return yaml.Unmarshal(data, conf)
}
func (conf *Config) Save() error {
data, err := yaml.Marshal(conf)
if err != nil {
return err
}
data = append([]byte("---\n"), data...)
return ioutil.WriteFile(conf.path, data, 0644)
}
func LoadConfig(filename string) (*Config, error) {
data, err := ioutil.ReadFile(filename)
if err != nil {
return nil, err
}
conf := &Config{}
if err := conf.Parse(data); err != nil {
return nil, err
}
conf.path = filename
if conf.Feeds == nil {
conf.Feeds = make(map[string]string)
}
return conf, nil
}