Sorting in Golang
Golang’s sort
package implements sorting for builtins and user-defined types. There are 3 different ways to sort a slice in golang depending on the data stored in the slice.
Golang’s sort
package implements sorting for builtins and user-defined types. There are 3 different ways to sort a slice in golang depending on the data stored in the slice.
Write a program to insert and search in trie data structure.
We suggest you think about a solution before reading further…
Map is a data structure which contains key value pair. In Golang make
function returns a map of the given type, initialized and ready for use. In this article, we will be creating a map using make function and will perform operation on map like add, delete and iterate.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
package main import "fmt" func main() { //create a map m := make(map[string]int) // assign value m["key1"] = 12 m["key2"] = 20 fmt.Println(m) // get value from map value1 := m["key1"] fmt.Printf("key1 : %d", value1) // get length of map fmt.Printf("\nLength : %d", len(m)) // get all key and value from map for key, value := range m { fmt.Printf("\n%s : %d", key, value) } // delete key from map delete(m, "key1") fmt.Println("\ncontent of map after deletion of 'key1'") for key, value := range m { fmt.Printf("%s : %d", key, value) } } |
Output
1 2 3 4 5 6 7 |
map[key1:12 key2:20] key1 : 12 Length : 2 key1 : 12 key2 : 20 content of map after deletion of 'key1' key2 : 20 |
Stay tuned for more updates and tutorials !!!
There are different library available in Golang to publish and subscribe topics in kafka. In this example, we are using sarama library to list all the available topic at kafka broker.
To get sarama library, run below command. …