Skip to content

Commit

Permalink
add url parsing to lua
Browse files Browse the repository at this point in the history
  • Loading branch information
Isan-Rivkin committed Sep 13, 2023
1 parent 5df2067 commit 6da922a
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions pkg/actions/lua/net/url/url.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package url

import (
neturl "net/url"

"github.com/Shopify/go-lua"
"github.com/treeverse/lakefs/pkg/actions/lua/util"
)

func Open(l *lua.State) {
open := func(l *lua.State) int {
lua.NewLibrary(l, library)
return 1
}
lua.Require(l, "net/url", open, false)
l.Pop(1)
}

var library = []lua.RegistryFunction{
{Name: "parse", Function: Parse},
}

func Parse(l *lua.State) int {
rawURL := lua.CheckString(l, 1)
u, err := neturl.Parse(rawURL)
if err != nil {
lua.Errorf(l, err.Error())
panic("unreachable")
}
return util.DeepPush(l, map[string]string{
"host": u.Host,
"path": u.Path,
"scheme": u.Scheme,
"query": u.RawQuery,
})
}

0 comments on commit 6da922a

Please sign in to comment.