Merge pull request #185 from mh-cbon/patch-1

Update README
This commit is contained in:
Matt Joiner 2017-09-12 18:28:35 +10:00 committed by GitHub
commit 76a81b5e54
1 changed files with 37 additions and 0 deletions

View File

@ -1 +1,38 @@
Bencode encoding/decoding sub package. Uses similar API design to Go's json package. Bencode encoding/decoding sub package. Uses similar API design to Go's json package.
## Install
```sh
go get github.com/anacrolix/torrent
```
## Usage
```go
package demo
import (
bencode "github.com/anacrolix/torrent/bencode"
)
type Message struct {
Query string `json:"q,omitempty" bencode:"q,omitempty"`
}
var v Message
func main(){
// encode
data, err := bencode.Marshal(v)
if err != nil {
log.Fatal(err)
}
//decode
err := bencode.Unmarshal(data, &v)
if err != nil {
log.Fatal(err)
}
fmt.Println(v)
}
```