extract out protocol

This commit is contained in:
2026-02-14 08:26:50 -05:00
parent d340c55e8c
commit 8bfe979093
3 changed files with 109 additions and 58 deletions

View File

@@ -1,6 +1,7 @@
package server
import (
"errors"
"fes/modules/config"
"io/fs"
"os"
@@ -16,8 +17,16 @@ type reqData struct {
params map[string]string
}
/* returns a string of rendered html */
func render(luapath string, requestData reqData) ([]byte, error) {
/* declarative sets in the page declaration */
type DeclarativeSets struct {
protos struct {
http bool
gemini bool
}
}
/* returns a string of rendered markup */
func render(luapath string, requestData reqData, setBuffer *DeclarativeSets) ([]byte, error) {
L := lua.NewState()
defer L.Close()
@@ -160,5 +169,35 @@ func render(luapath string, requestData reqData) ([]byte, error) {
return []byte(s), nil
}
L.GetGlobal("require")
L.Push(lua.LString("std"))
L.Call(1, 1)
ret := L.Get(-1)
L.Pop(1)
tbl, ok := ret.(*lua.LTable)
if !ok {
return nil, errors.New("Could not determine protocol")
}
proto := tbl.RawGetString("proto")
protoTbl, ok := proto.(*lua.LTable)
if !ok {
return nil, errors.New("Could not determine protocol")
}
protoTbl.ForEach(func(key lua.LValue, value lua.LValue) {
if str, ok := value.(lua.LString); ok {
switch str.String() {
case "http":
setBuffer.protos.http = true
case "gemini":
setBuffer.protos.gemini = true
}
}
})
return []byte(""), nil
}