File: README.md

package info (click to toggle)
golang-github-cjoudrey-gluaurl 0.0~git20161028.31cbb9b-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 84 kB
  • sloc: makefile: 2
file content (109 lines) | stat: -rw-r--r-- 2,319 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# 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)