https://github.com/gongo/text-parameters
Encoding and decoding of text/parameters written by Go
https://github.com/gongo/text-parameters
Last synced: 10 months ago
JSON representation
Encoding and decoding of text/parameters written by Go
- Host: GitHub
- URL: https://github.com/gongo/text-parameters
- Owner: gongo
- License: mit
- Created: 2014-08-14T14:41:04.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2014-09-18T13:03:06.000Z (over 11 years ago)
- Last Synced: 2024-12-31T16:32:40.766Z (over 1 year ago)
- Language: Go
- Size: 180 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
go-text-parameters
==================
[](http://godoc.org/github.com/gongo/text-parameters)
[](https://travis-ci.org/gongo/text-parameters)
[](https://coveralls.io/r/gongo/text-parameters)
Encoding and decoding of text/parameters written by Go
## Description
**text/parameters** is consists of either a list of parameters or a list of parameters and associated values.
Each entry of the list is a single line of text, and parameters are separated from values by a colon.
This package provides a read and write function of `text/parameters` format text from your Go programs.
### Spec
- [RFC 2326 - Real Time Streaming Protocol (RTSP)](http://tools.ietf.org/html/rfc2326)
- [draft-ietf-mmusic-rfc2326bis-40 - Real Time Streaming Protocol 2.0 (RTSP)](http://tools.ietf.org/html/draft-ietf-mmusic-rfc2326bis-40#page-297)
## Usage
### Decoder
```go
package main
import (
"fmt"
"strings"
"github.com/gongo/text-parameters"
)
func main() {
body := "Name: Wataru MIYAGUNI\nlogin: gongo\nAge: 30\n"
u := struct {
Name string
LoginId string `parameters:"login"`
Age int
}{}
decoder := parameters.NewDecorder(strings.NewReader(body))
decoder.Decode(&u)
fmt.Println("u.Name =", u.Name)
fmt.Println("u.LoginId =", u.LoginId)
fmt.Println("u.Age =", u.Age)
}
```
Output:
```
u.Name = Wataru MIYAGUNI
u.LoginId = gongo
u.Age = 30
```
### Encoder
```go
package main
import (
"bytes"
"fmt"
"github.com/gongo/text-parameters"
)
func main() {
var body bytes.Buffer
u := struct {
Name string
LoginId string `parameters:"login_id"`
Rate float64
}{
Name: "Wataru MIYAGUNI",
LoginId: "gongo",
Rate: 0.923,
}
encoder := parameters.NewEncoder(&body)
encoder.Encode(&u)
fmt.Println(body.String())
}
```
Output:
```
Name: Wataru MIYAGUNI
Rate: 0.923
login_id: gongo
```
## Install
```
$ go get github.com/gongo/text-parameters
```
## LICENSE
[MIT License](./LICENSE.txt)