lang: core: net: Add a new func for URL parsing

This is a first attempt to add a new function for URL parsing, using
go's net/url package and the simple API. This is still a barebones
implementation, there's possibility to expose more information. It also
includes simple tests.
This commit is contained in:
Lourenço
2025-01-31 15:37:21 +01:00
committed by Lourenço Vales
parent b5384d1278
commit 1f90de31e7
2 changed files with 115 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
-- main.mcl --
import "net"
import "fmt"
$url1 = "https://www.example.com/search?q=mgmt"
$url2 = "ftp://example.com/apath"
$url3 = "https://www3.weird.url/?qu=ery"
$url_parse1 = net.url_parser($url1)
$url_parse2 = net.url_parser($url2)
$url_parse3 = net.url_parser($url3)
test [fmt.printf("%s %s %s %s", $url_parse1->scheme, $url_parse1->host, $url_parse1->path, $url_parse1->raw_query),] {}
test [fmt.printf("%s %s %s %s", $url_parse2->scheme, $url_parse2->host, $url_parse2->path, $url_parse2->raw_query),] {}
test [fmt.printf("%s %s %s %s", $url_parse3->scheme, $url_parse3->host, $url_parse3->path, $url_parse3->raw_query),] {}
-- OUTPUT --
Vertex: test[https www.example.com /search q=mgmt]
Vertex: test[ftp example.com /apath ]
Vertex: test[https www3.weird.url / qu=ery]