contented/cmd/contented/main.go

52 lines
1.7 KiB
Go
Raw Permalink Normal View History

2017-10-06 07:02:57 +00:00
package main
import (
"flag"
"log"
"net/http"
"os"
"code.ivysaur.me/contented"
)
func main() {
cwd, _ := os.Getwd()
2017-10-08 02:06:54 +00:00
listenAddr := flag.String("listen", "127.0.0.1:80", "IP/Port to bind server")
2017-10-06 07:02:57 +00:00
dataDir := flag.String("data", cwd, "Directory for stored content")
dbPath := flag.String("db", "contented.db", "Path for metadata database")
appTitle := flag.String("title", "contented", "Title used in web interface")
maxUploadMb := flag.Int("max", 8, "Maximum size of uploaded files in MiB (set zero for unlimited)")
2017-10-08 02:06:46 +00:00
maxUploadSpeed := flag.Int("speed", 0, "Maximum upload speed in bytes/sec (set zero for unlimited)")
2017-10-15 06:09:14 +00:00
trustXForwardedFor := flag.Bool("trustXForwardedFor", false, "Trust X-Forwarded-For reverse proxy headers")
2017-10-15 06:16:22 +00:00
enableHomepage := flag.Bool("enableHomepage", true, "Enable homepage (disable for embedded use only)")
diskFilesWorldReadable := flag.Bool("diskFilesWorldReadable", false, "Save files as 0644 instead of 0600")
maxConcurrentThumbs := flag.Int("concurrentthumbs", contented.DEFAULT_MAX_CONCURRENT_THUMBS, "Simultaneous thumbnail generation")
2017-10-08 02:06:46 +00:00
2017-10-06 07:02:57 +00:00
flag.Parse()
svr, err := contented.NewServer(&contented.ServerOptions{
DataDirectory: *dataDir,
DBPath: *dbPath,
BandwidthLimit: int64(*maxUploadSpeed),
TrustXForwardedFor: *trustXForwardedFor,
EnableHomepage: *enableHomepage,
DiskFilesWorldReadable: *diskFilesWorldReadable,
MaxConcurrentThumbs: *maxConcurrentThumbs,
ServerPublicProperties: contented.ServerPublicProperties{
AppTitle: *appTitle,
MaxUploadBytes: int64(*maxUploadMb) * 1024 * 1024,
},
2017-10-06 07:02:57 +00:00
})
if err != nil {
log.Println(err.Error())
os.Exit(1)
}
err = http.ListenAndServe(*listenAddr, svr)
if err != nil {
log.Println(err.Error())
os.Exit(1)
}
}