# go-varlink example

This directory suggests a code organization for projects using this library.

Whether you have your application in `cmd/` or in the project root, create a
dedicated directory for the `.varlink` files and their generated code. This
will make it easier to manage and grow over time -- and it will ensure
autogenerated code never pollutes your own code's namespace.

To generate the Go bindings, run this command from the current directory:

```shell
$ go generate ./...
```

This will run commands specified in `generate.go`.

Then, run the server:

```shell
$ go build && ./example
```

You can serve multiple namespaces at once:

```shell
$ varlinkctl call ./org.example.sock org.example.calc.Multiply '{"a": 2, "b": 4}'
{"result": 8}
$ varlinkctl call ./org.example.sock org.example.calc.Divide '{"a": 12, "b": 0}'
Method call org.example.calc.Divide() failed: org.example.calc.DivisionByZero
$ varlinkctl call ./org.example.sock org.example.string.Reverse '{"input": "foo"}'
{"output": "oof"}
```
