yatwiki/cmd/yatwiki-server/main.go

42 lines
873 B
Go
Raw Normal View History

2017-07-08 23:13:36 +00:00
package main
import (
"flag"
"fmt"
"net/http"
"os"
2017-07-09 06:48:59 +00:00
"time"
2017-07-08 23:13:36 +00:00
"code.ivysaur.me/yatwiki3"
)
func main() {
bindAddr := flag.String("listen", "127.0.0.1:80", "Bind address")
dbPath := flag.String("database", "wiki.db", "Database file")
2017-07-09 00:14:28 +00:00
faviconPath := flag.String("favicon", "", "Local disk path to favicon.ico file (leave blank for no favicon)")
2017-07-08 23:13:36 +00:00
flag.Parse()
opts := yatwiki3.DefaultOptions()
opts.DBFilePath = *dbPath
2017-07-09 00:14:28 +00:00
opts.FaviconFilePath = *faviconPath
2017-07-09 06:48:59 +00:00
opts.Timezone = time.Local.String()
2017-07-11 07:08:22 +00:00
opts.ExternalBaseURL = "http://" + *bindAddr + "/"
2017-07-08 23:13:36 +00:00
ws, err := yatwiki3.NewWikiServer(opts)
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
defer ws.Close()
2017-07-09 00:14:59 +00:00
fmt.Printf("YATWiki now listening on %s\n", *bindAddr)
2017-07-08 23:13:36 +00:00
err = http.ListenAndServe(*bindAddr, ws)
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
os.Exit(0)
}