diff options
author | Nathan Skrzypczak <nathan.skrzypczak@gmail.com> | 2021-08-19 11:38:06 +0200 |
---|---|---|
committer | Dave Wallace <dwallacelf@gmail.com> | 2021-10-13 23:22:32 +0000 |
commit | 9ad39c026c8a3c945a7003c4aa4f5cb1d4c80160 (patch) | |
tree | 3cca19635417e28ae381d67ae31c75df2925032d /docs/interfacing/go | |
parent | f47122e07e1ecd0151902a3cabe46c60a99bee8e (diff) |
docs: better docs, mv doxygen to sphinx
This patch refactors the VPP sphinx docs
in order to make it easier to consume
for external readers as well as VPP developers.
It also makes sphinx the single source
of documentation, which simplifies maintenance
and operation.
Most important updates are:
- reformat the existing documentation as rst
- split RELEASE.md and move it into separate rst files
- remove section 'events'
- remove section 'archive'
- remove section 'related projects'
- remove section 'feature by release'
- remove section 'Various links'
- make (Configuration reference, CLI docs,
developer docs) top level items in the list
- move 'Use Cases' as part of 'About VPP'
- move 'Troubleshooting' as part of 'Getting Started'
- move test framework docs into 'Developer Documentation'
- add a 'Contributing' section for gerrit,
docs and other contributer related infos
- deprecate doxygen and test-docs targets
- redirect the "make doxygen" target to "make docs"
Type: refactor
Change-Id: I552a5645d5b7964d547f99b1336e2ac24e7c209f
Signed-off-by: Nathan Skrzypczak <nathan.skrzypczak@gmail.com>
Signed-off-by: Andrew Yourtchenko <ayourtch@gmail.com>
Diffstat (limited to 'docs/interfacing/go')
-rw-r--r-- | docs/interfacing/go/add_plugin_goapi.rst | 83 | ||||
-rw-r--r-- | docs/interfacing/go/index.rst | 10 |
2 files changed, 93 insertions, 0 deletions
diff --git a/docs/interfacing/go/add_plugin_goapi.rst b/docs/interfacing/go/add_plugin_goapi.rst new file mode 100644 index 00000000000..dce35b8f0a2 --- /dev/null +++ b/docs/interfacing/go/add_plugin_goapi.rst @@ -0,0 +1,83 @@ +.. _add_plugin_goapi: + +Add a plugin's GO API +===================== + +In order to use your plugin's API with GO, you will need to use +a GO client and GO definitions of the API messages that you defined +in ``myplugin.api`` (go bindings). + +These two things can be found in `govpp <https://github.com/FDio/govpp>`_ + +* The API client lives in `./core` +* The api-generator lives in `./binapigen` +* A sample of its output (the go bindings) for VPP's latest version lives in `./binapi` + +To generate the go bindings for your plugin. Assuming : +* ``/home/vpp`` is a VPP clone with your plugin in it. +* ``/home/controlplane`` is a go controlplane repo + +.. code-block:: console + + $ mkdir /home/controlplane/vpp-go-bindings + $ git clone https://github.com/FDio/govpp> + $ cd govpp + $ BINAPI_DIR=/home/controlplane/vpp-go-bindings VPP_DIR=/home/vpp make gen-binapi-from-code + +This will generate the go-bindings in ``/home/controlplane/vpp-go-bindings`` +For example ``vpp-go-bindings/myplugin/myplugin.ba.go`` will contain : + +.. code-block:: go + + // MypluginEnableDisable defines message 'myplugin_enable_disable'. + type MypluginEnableDisable struct { + EnableDisable bool `binapi:"bool,name=enable_disable" json:"enable_disable,omitempty"` + SwIfIndex interface_types.InterfaceIndex `binapi:"interface_index,name=sw_if_index" json:"sw_if_index,omitempty"` + } + + +You can then use the generated go bindings in your go code like this : + +.. code-block:: go + + package main + + import ( + "fmt" + "git.fd.io/govpp.git" + "git.fd.io/govpp.git/binapi/interfaces" + "git.fd.io/govpp.git/binapi/vpe" + + "myplugin.io/controlplane/vpp-go-bindings/myplugin/myplugin" + ) + + func main() { + // Connect to VPP + conn, _ := govpp.Connect("/run/vpp/api.sock") + defer conn.Disconnect() + + // Open channel + ch, _ := conn.NewAPIChannel() + defer ch.Close() + + request := &vpe.MypluginEnableDisable{ + EnableDisable: true, + } + reply := &vpe.MypluginEnableDisableReply{} + + err := ch.SendRequest(request).ReceiveReply(reply) + if err != nil { + fmt.Errorf("SendRequest: %w\n", err) + } + } + +As you will need to import (or ``go get "git.fd.io/govpp.git"``) to leverage the API +client in your code, you might want to use the api-generator directly from the +clone ``go build`` fetches for you. You can do this with : + +.. code-block:: console + + $ export GOVPP_DIR=$(go list -f '{{.Dir}}' -m git.fd.io/govpp.git) + $ cd $GOVPP_DIR && go build -o /some/bin/dir ./cmd/binapi-generator + $ # instead of make gen-binapi-from-code you can rewrite the code to target + $ # your version ./binapi-generator diff --git a/docs/interfacing/go/index.rst b/docs/interfacing/go/index.rst new file mode 100644 index 00000000000..68c01e086b0 --- /dev/null +++ b/docs/interfacing/go/index.rst @@ -0,0 +1,10 @@ +.. _govpp: + +============== +Go api (govpp) +============== + +.. toctree:: + :maxdepth: 2 + + add_plugin_goapi |