Encoding and decoding of text/parameters written by Go
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.
- RFC 2326 - Real Time Streaming Protocol (RTSP)
- draft-ietf-mmusic-rfc2326bis-40 - Real Time Streaming Protocol 2.0 (RTSP)
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
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
$ go get github.com/gongo/text-parameters
