marosmars / vppapisamples

Demonstration of VPP managment using API bindings with various languages
16 stars 9 forks source link

Golang API cannot find package #2

Open kongyanye opened 3 years ago

kongyanye commented 3 years ago

Hi marosmars,

Thanks for sharing your blog and example scripts. I'm currently trying to use the GO version VPP api from https://github.com/fdio/govpp. I've installed the VPP binaries on Ubuntu 20 (including the vpp-dev optional package) and followed their official github repo to install the GO package. But I can't successfully run neither their quick start script nor your example script.

There are mainly two problems:

1) Seems the API structure is broken. I successfully installed binapi-generator and generated the GO bindings, and then put the generated files under $GOROOT/vppapi (/usr/local/go/src/vppapi). After that, when importing package "interfaces" and "l2", it shows error "cannot find package std/std/vppapi/ethernet_types" and several other packages like "ip_types" and "vpe". These packages indeed exist under $GOROOT/vppapi, but GO seems can't find it because they automatically add the "std/std" prefix before module name. How can I fix it?

2) The package "interfaces" actually does not exist (you can check it in their official example and repo files), but there do exist a package called "interface". I don't know how it can be imported.

Their official repo does not provide the issue function and there are almost no materials I can find online to use VPP api in GO. So I ask the question here. I would really appreciate it if you can give me some insights. Thanks!

pan2za commented 3 years ago

you'd first build the bin-api using command like,

cd $GOPATH/src/git.fd.io/govpp.git binapi-generator --output-dir=binapi

the binapi locates at, $GOPATH/src/git.fd.io/govpp.git/binapi

kongyanye commented 3 years ago

I figured out the problem. The api source file should be placed under $GOPATH/src/git.fd.io/govpp.git and the new packages is indeed called "interfaces" instead of "interface".