gopp/server/tool.go

43 lines
892 B
Go
Raw Normal View History

package server
import (
//"github.com/d5/tengo/v2"
"github.com/d5/tengo/v2/stdlib"
"vultras.su/util/tpp"
"vultras.su/core/cli/mtool"
"net/http"
"log"
)
var Tool = mtool.T("tht").Func(func(flags *mtool.Flags){
var (
addr string
handler Handler
)
flags.StringVar(&addr, "addr", ":3000", "address to serve at")
flags.StringVar(&handler.SourcePath, "src", "./src", "directory with source files")
flags.StringVar(&handler.Ext, "ext", ".tpp", "extension for TPP files")
flags.Parse()
t := tpp.NewTengo().SetPreCompile(func(s *tpp.Script){
s.SetImports(stdlib.GetModuleMap(
stdlib.AllModuleNames()...,
))
s.EnableFileImport(true)
s.SetImportDir(handler.SourcePath)
})
handler.PP = tpp.New(t)
srv := &http.Server{
Addr: addr,
Handler: &handler,
}
err := srv.ListenAndServe()
if err != nil {
log.Printf("Error: srv.ListenAndServe(...): %s\n", err)
}
})