https://github.com/emersion/go-varlink
A Go library for Varlink
https://github.com/emersion/go-varlink
Last synced: about 1 year ago
JSON representation
A Go library for Varlink
- Host: GitHub
- URL: https://github.com/emersion/go-varlink
- Owner: emersion
- License: mit
- Created: 2024-05-09T06:28:30.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2025-01-30T22:38:48.000Z (over 1 year ago)
- Last Synced: 2025-05-06T15:18:21.698Z (about 1 year ago)
- Language: Go
- Size: 30.3 KB
- Stars: 5
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-varlink
[](https://pkg.go.dev/github.com/emersion/go-varlink)
A Go library for [Varlink].
## Code generation
Given a Varlink definition file:
```varlink
interface org.example.ftl
method Jump(latitude: float, longitude: float) -> ()
```
Client and server code can be generated:
go run github.com/emersion/go-varlink/cmd/varlinkgen -i org.example.ftl.varlink
This can be performed with `go generate`:
```go
//go:build generate
package ftl
import (
_ "github.com/emersion/go-varlink/cmd/varlinkgen"
)
//go:generate go run github.com/emersion/go-varlink/cmd/varlinkgen -i org.example.ftl.varlink
```
The generated file contains a `Client`, with one Go method per Varlink service
method:
```go
client := Client{varlink.NewClient(conn)}
_, err := client.Jump(&JumpIn{37.56, 126.99})
```
It also contains a `Handler` implementing the Varlink service, and a `Backend`
interface which needs to be implemented:
```go
type backend struct{}
func (backend) Jump(in *JumpIn) (*JumpOut, error) {
log.Print(in.Latitude, in.Longitude)
return nil, nil
}
func main() {
server := varlink.NewServer()
server.Handler = Handler{backend{}}
if err := server.Serve(listener); err != nil {
log.Fatal(err)
}
}
```
## License
MIT
[Varlink]: https://varlink.org/