How to execute C code from go – c to golang binding

package main // If a Go source file imports “C”, it is using cgo. The Go file will have access to anything appearing in the comment immediately preceding the line import “C”, and will be linked against all other cgo comments in other Go files, and all C files included in the build process. /* … Read more

How to resolve error : ” no buildable Go source files in “

Sometimes when we try to compile an unknown go package, we can see an error like “no buildable Go source files in”, the possible solution could be, Check if the package which shows error “no buildable Go source files in” is using C code, like import “C” in the source file, in that case, we … Read more

Bitbake / Yocto recipes for cross compiling golang program

For compiling simple golang helloworld program as part of yocto build framework, we need to download meta-golang from https://github.com/madisongh/meta-golang and use this meta layer along with poky to build our written bitbake recipes for cross compilation of golang program. PLEASE NOTE: Starting with OE-Core ‘rocko’ (Yocto Project 2.4), Go support is available directly in OE-Core, … Read more

How to use slices ( like dynamic array ) in go language ?

An array has a fixed size. A slice, on the other hand, is a dynamically-sized, flexible view into the elements of an array. In practice, slices are much more common than arrays. The type []T is a slice with elements of type T. A slice is formed by specifying two indices, a low and high … Read more

Go Program : Identify total number of network interfaces and display the details using index

Following example shows how to identify total number of available network interfaces and display its details using network packages InterfaceByIndex API. $ vim InterfaceByIndex.go $ go build InterfaceByIndex.go $ ./InterfaceByIndexTotal interfaces : 3Index: 1 interface &{1 65536 lo up|loopback}Index: 2 interface &{2 1500 eth0 00:26:b9:11:51:48 up|broadcast|multicast}Index: 3 interface &{3 1500 wlan0 0c:60:76:61:ce:49 up|broadcast|multicast} OR you … Read more

Print details of network interface ( IP address, mac, status etc ) using go language program

$ vim networkInterfaceDetails.go Now, we can compile the go program as, $ go build networkInterfaceDetails.go and execute as, $ ./networkInterfaceDetails 2018/09/04 09:01:23 Index:1 Name:lo addr:127.0.0.1/8, mac: Status : UP 2018/09/04 09:01:23 Index:1 Name:lo addr:::1/128, mac: Status : UP 2018/09/04 09:01:23 Index:3 Name:wlan0 addr:192.168.0.109/24, mac:0c:60:76:61:ce:49 Status : UP 2018/09/04 09:01:23 Index:3 Name:wlan0 addr:fe80::a2ca:2820:a122:7db4/64, mac:0c:60:76:61:ce:49 Status : … Read more

How to use static arrays in go language ?

The below program initialises a static array of 7 elements and prints the values of each element using for loop, this this program demonstrates how to initialise a static array and also how to use a for loop in go language. $ vim static_array_example.go Compile the go program using “go build” command as, $ go … Read more