1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
package main
import (
"flag"
"fmt"
"gopkg.in/yaml.v3"
"log"
"net/http"
"os"
"time"
"riedstra.dev/mitch/go-website/page"
)
var VersionString = ""
func VersionPrint() {
fmt.Println(VersionString)
os.Exit(0)
}
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")
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:])
if *version {
VersionPrint()
}
if err := os.Chdir(*directory); err != nil {
log.Fatal(err)
}
app, err := loadConf(*confFn)
if err != nil {
log.Println(err)
app = &App{}
}
if app.ReIndexPath == "" || *indexPath != defaultIndexPath {
app.ReIndexPath = *indexPath
}
if *verbose {
b, _ := yaml.Marshal(app)
os.Stderr.Write(b)
}
srv := &http.Server{
Handler: app,
Addr: *listen,
WriteTimeout: 15 * time.Second,
ReadTimeout: 15 * time.Second,
}
log.Fatal(srv.ListenAndServe())
}
|