moth/cmd/mothd/main.go

62 lines
1.2 KiB
Go
Raw Normal View History

2019-09-02 19:47:24 -06:00
package main
import (
2020-02-29 16:59:44 -07:00
"flag"
2019-12-05 22:25:03 -07:00
"mime"
"time"
2020-08-14 20:26:04 -06:00
"github.com/spf13/afero"
2019-09-02 19:47:24 -06:00
)
func main() {
themePath := flag.String(
"theme",
"theme",
"Path to theme files",
)
statePath := flag.String(
"state",
"state",
"Path to state files",
)
mothballPath := flag.String(
"mothballs",
"mothballs",
2020-08-17 17:43:57 -06:00
"Path to mothball files",
)
refreshInterval := flag.Duration(
"refresh",
2*time.Second,
"Duration between maintenance tasks",
)
bindStr := flag.String(
"bind",
2020-02-29 16:59:44 -07:00
":8080",
"Bind [host]:port for HTTP service",
)
base := flag.String(
"base",
"/",
"Base URL of this instance",
)
2020-02-29 16:59:44 -07:00
flag.Parse()
theme := NewTheme(afero.NewBasePathFs(afero.NewOsFs(), *themePath))
state := NewState(afero.NewBasePathFs(afero.NewOsFs(), *statePath))
puzzles := NewMothballs(afero.NewBasePathFs(afero.NewOsFs(), *mothballPath))
2019-12-07 21:17:13 -07:00
// Add some MIME extensions
// Doing this avoids decompressing a mothball entry twice per request
mime.AddExtensionType(".json", "application/json")
mime.AddExtensionType(".zip", "application/zip")
2020-08-18 17:04:23 -06:00
go theme.Maintain(*refreshInterval)
go state.Maintain(*refreshInterval)
go puzzles.Maintain(*refreshInterval)
2019-12-07 21:17:13 -07:00
2020-03-01 16:10:55 -07:00
server := NewMothServer(puzzles, theme, state)
httpd := NewHTTPServer(*base, server)
2020-08-19 18:01:21 -06:00
httpd.Run(*bindStr)
}