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 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 [bash] package main import ( "net" "fmt" "log" ) func main(){ ifaces, err := net.Interfaces() if err != nil { log.Print(fmt.Errorf("localAddresses: %v\n", err.Error())) return } fmt.Println("Total interfaces : ", len(ifaces)) for … Read more

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

$ vim networkInterfaceDetails.go [bash] package main import ( "fmt" "log" "net" "strings" ) func networkInterfaceDetails() { var count int ifaces, err := net.Interfaces() if err != nil { log.Print(fmt.Errorf("localAddresses: %v\n", err.Error())) return } for _, i := range ifaces { addrs, err := i.Addrs() if err != nil { log.Print(fmt.Errorf("localAddresses: %v\n", err.Error())) continue } for … 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 [bash] package main import ( "fmt" ) func main() { array_name … Read more