Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cjoudrey/gluaurl
gluaurl: a url parser/builder module for gopher-lua
https://github.com/cjoudrey/gluaurl
Last synced: 2 months ago
JSON representation
gluaurl: a url parser/builder module for gopher-lua
- Host: GitHub
- URL: https://github.com/cjoudrey/gluaurl
- Owner: cjoudrey
- License: mit
- Created: 2015-05-23T20:13:20.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-10-28T22:26:12.000Z (about 8 years ago)
- Last Synced: 2024-06-18T18:33:02.713Z (6 months ago)
- Language: Go
- Size: 5.86 KB
- Stars: 6
- Watchers: 3
- Forks: 9
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gluaurl
[![](https://travis-ci.org/cjoudrey/gluaurl.svg)](https://travis-ci.org/cjoudrey/gluaurl)
gluahttp provides an easy way to parse and build URLs from within [GopherLua](https://github.com/yuin/gopher-lua).
## Installation
```
go get github.com/cjoudrey/gluaurl
```## Usage
```go
import "github.com/yuin/gopher-lua"
import "github.com/cjoudrey/gluaurl"func main() {
L := lua.NewState()
defer L.Close()L.PreloadModule("url", gluaurl.Loader)
if err := L.DoString(`
local url = require("url")
parsed_url = url.parse("http://example.com/")
print(parsed_url.host)
`); err != nil {
panic(err)
}
}
```## API
- [`url.parse(url)`](#urlparseurl)
- [`url.build(options)`](#urlbuildoptions)
- [`url.build_query_string(query_params)`](#urlbuild_query_stringquery_params)
- [`url.resolve(from, to)`](#urlresolvefrom-to)### url.parse(url)
Parse URL into a table of key/value components.
**Attributes**
| Name | Type | Description |
| ------- | ------ | ----------- |
| url | String | URL to parsed |**Returns**
Table with parsed URL or (nil, error message)
| Name | Type | Description |
| -------- | ------ | ----------- |
| scheme | String | Scheme of the URL |
| username | String | Username |
| password | String | Password |
| host | String | Host and port of the URL |
| path | String | Path |
| query | String | Query string |
| fragment | String | Fragment |### url.build(options)
Assemble a URL string from a table of URL components.
**Attributes**
| Name | Type | Description |
| ------- | ----- | ----------- |
| options | Table | Table with URL components, see [`url.parse`](#urlparseurl) for list of valid components |**Returns**
String
### url.build_query_string(query_params)
Assemble table of query string parameters into a string.
**Attributes**
| Name | Type | Description |
| ------------ | ----- | ----------- |
| query_params | Table | Table with query parameters |**Returns**
String
### url.resolve(from, to)
Take a base URL, and a href URL, and resolve them as a browser would for an anchor tag.
| Name | Type | Description |
| ---- | ------ | ----------- |
| from | String | base URL |
| to | String | href URL |**Returns**
String or (nil, error message)