What i am trying to do is get candidat1, candidat2 and entreprise1 but i am facing a problem where the second map is in fact an array of map in value field.
from your code snippet, sounds your map like this
map[string]map[id]map[string]string
for example
map[“google.fr”]map[3766423]map[“canditat1”]=“”
map[“google.fr”]map[3766423]map[“canditat2”]=“aa9dfcea-e4ae-4087-95da-5352f8b7efaa”
map[“google.fr”]map[3766423]map[“entreprise1”]=“35252bb8-5434-ef11-8409-7c1e5220b4fd”
so if you want fo search for canditat2
you should
var myMap map[string]map[id]map[string]string
try this code
package main
import (
"fmt"
)
func main() {
// Define the nested map
myMap := map[string]map[int]map[string]string{
"google.fr": {
3766423: {
"canditat1": "",
"canditat2": "aa9dfcea-e4ae-4087-95da-5352f8b7efaa",
"entreprise1": "35252bb8-5434-ef11-8409-7c1e5220b4fd",
},
},
}
// Search for "entreprise1"
searchKey := "entreprise1"
found := false
for domain, idMap := range myMap {
for id, innerMap := range idMap {
if value, exists := innerMap[searchKey]; exists {
fmt.Printf("Found %s: %s in domain: %s with ID: %d\n", searchKey, value, domain, id)
found = true
}
}
}
if !found {
fmt.Printf("%s not found in the map\n", searchKey)
}
}