diff options
| author | Mitchell Riedstra <mitch@riedstra.dev> | 2021-07-12 23:08:58 -0400 |
|---|---|---|
| committer | Mitchell Riedstra <mitch@riedstra.dev> | 2021-07-12 23:18:44 -0400 |
| commit | 904e37a88a6a2eab3919f7f2c40bbb2c07544a7c (patch) | |
| tree | 07ec38801bf572a2933d51d272fc4cd3ab74b61c /cmd/server/main.go | |
| parent | e6d53f71c9718ecdb9fde16a924d75a71aadd2d2 (diff) | |
| download | go-website-904e37a88a6a2eab3919f7f2c40bbb2c07544a7c.tar.gz go-website-904e37a88a6a2eab3919f7f2c40bbb2c07544a7c.tar.xz | |
Add atom feed to the go website
Diffstat (limited to 'cmd/server/main.go')
| -rw-r--r-- | cmd/server/main.go | 42 |
1 files changed, 37 insertions, 5 deletions
diff --git a/cmd/server/main.go b/cmd/server/main.go index 9ec96da..4b2c1ad 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -3,6 +3,7 @@ package main import ( "flag" "fmt" + "gopkg.in/yaml.v3" "log" "net/http" "os" @@ -18,13 +19,28 @@ func VersionPrint() { os.Exit(0) } +func loadConf(fn string) (*App, error) { + fh, err := os.Open(fn) + if err != nil { + return nil, err + } + dec := yaml.NewDecoder(fh) + + app := &App{} + err = dec.Decode(app) + return app, err +} + func main() { fl := flag.NewFlagSet("Website", flag.ExitOnError) listen := fl.String("l", "0.0.0.0:8001", "Listening address") directory := fl.String("d", ".", "Directory to serve.") version := fl.Bool("v", false, "Print the version then exit") - fl.StringVar(&page.TimeFormat, "T", page.TimeFormat, "Print the version then exit") - indexPath := fl.String("i", "/reIndex", + confFn := fl.String("c", "conf.yml", "Location for the config file") + verbose := fl.Bool("V", false, "Be more verbose ( dump config, etc ) ") + fl.StringVar(&page.TimeFormat, "T", page.TimeFormat, "Set the page time format, be careful with this") + defaultIndexPath := "/reIndex" + indexPath := fl.String("i", defaultIndexPath, "Path in which, when called will rebuild the index and clear the cache") _ = fl.Parse(os.Args[1:]) @@ -36,9 +52,25 @@ func main() { log.Fatal(err) } - app := &App{ - ReIndexPath: *indexPath, - StaticDirectory: "static", + app, err := loadConf(*confFn) + if err != nil { + log.Println(err) + app = &App{} + } + + if app.ReIndexPath == "" || *indexPath != defaultIndexPath { + app.ReIndexPath = *indexPath + } + if app.StaticDirectory == "" { + app.StaticDirectory = "static" + } + if app.FeedPrefix == "" { + app.FeedPrefix = FeedPrefixDefault + } + + if *verbose { + b, _ := yaml.Marshal(app) + os.Stderr.Write(b) } srv := &http.Server{ |
