kyra/tool.go

53 lines
1.2 KiB
Go
Raw Normal View History

2024-08-02 18:30:32 +03:00
package kyra
2024-06-09 15:16:38 +03:00
import (
2024-08-02 18:30:32 +03:00
"surdeus.su/core/xgo/v2"
"surdeus.su/util/kyra/mdx"
2024-06-09 15:16:38 +03:00
"surdeus.su/core/cli/mtool"
"net/http"
"log"
)
// Simple PHP-like server implementation.
2024-08-02 18:30:32 +03:00
var Tool = mtool.T("kyra").Func(func(flags *mtool.Flags) {
2024-06-09 15:16:38 +03:00
var (
addr, ext, src, mod, index string
2024-08-02 18:30:32 +03:00
noLog bool
2024-06-09 15:16:38 +03:00
)
flags.StringVar(&addr, "addr", ":3000", "address to serve at")
flags.StringVar(&mod, "mod", "./mod", "path to store Tengo modules")
flags.StringVar(&src, "src", "./src", "directory with source files")
2024-08-02 18:30:32 +03:00
flags.StringVar(&ext, "ext", ".kr", "extension for Kyra files")
2024-06-09 15:16:38 +03:00
flags.StringVar(&index, "index", "index.htm", "index file name")
2024-08-02 18:30:32 +03:00
flags.BoolVar(&noLog, "no-log", false, "disable logging")
2024-06-09 15:16:38 +03:00
flags.Parse()
2024-06-09 16:26:31 +03:00
handler := &LoggerMiddle{
After: NewHandler(
2024-06-09 15:16:38 +03:00
DefaultPP(mod),
src, ext, index,
2024-08-02 18:30:32 +03:00
map[string]xgo.Object{},
2024-06-09 15:16:38 +03:00
).SetMD(mdx.MakeDefaultMarkdown()),
}
2024-06-09 16:26:31 +03:00
if !noLog {
handler.Logger = log.Default()
}
srv := &http.Server{
Addr: addr,
Handler: handler,
}
2024-06-09 15:16:38 +03:00
log.Printf("Listening on %q\n", addr)
err := srv.ListenAndServe()
if err != nil {
log.Printf("Error: srv.ListenAndServe(...): %s\n", err)
}
2024-08-02 18:30:32 +03:00
}).Ldesc(`
Simple PHP-like server implementation of the Kyra
suitable for the most of the needs of websites.
`)