“golang cartes” Réponses codées

Initialiser la carte à Golang

// By default maps in Go behaves like a default dictionary in python
m := make(map[string]int)

m["Dio"] = 3
m["Jonathan"] = 1
Joseph Joestar

aller ajouter à la carte

m := make(map[string]int)
m["numberOne"] = 1
m["numberTwo"] = 2
Navid2zp

Carte de Golang

package main
import "fmt"

func main() {

  object := map[string]string{
    "name": "john doe",
  }
  
  arrayObject := []map[string]string{
    map[string]string{ "name": "john doe"},
    map[string]string{"name": "jane doe"},
  }

  usingMake := make(map[string] string)
  usingMake["name"] = "max cavalera"
  
  fmt.Printf("this is object %v \n", object)
  fmt.Printf("this is array object %v \n", arrayObject)
  fmt.Printf("using make method %v \n", usingMake)
}
Restu Wahyu Saputra

golang cartes

package main

import (
	"encoding/json"
	"fmt"
	"net/http"
)

type Address struct {
	Street  string `json:"street"`
	Suite   string `json:"suite"`
	Zipcode string `json:"zipcode"`
}

type Users struct {
	Name string `json:"name"`
	Age  uint   `json:"age"`
}

func Mapping() {
   // users 1 example
	var users1 map[string]interface{}

	users1 = map[string]interface{}{"name": "john doe", "age": 23}

   // users 2 example
	users2 := map[string]interface{}{"name": "john doe", "age": 23}

   // users 3 example
	users3 := make(map[string]interface{})
	users3 = map[string]interface{}{"name": "John doe", "age": 23}

   // users 4 example
	var users4 map[string]interface{} = map[string]interface{}{"name": "John doe", "age": 23}

	fmt.Printf("Object mapping 1 %#v \n", users1)
	fmt.Printf("Object mapping 2 %#v \n", users2)
	fmt.Printf("Object mapping 3 %#v \n", users3)
	fmt.Printf("Object mapping 4 %#v \n", users4)
}

func ArrayMapping() {
   // users 1 example
	var users1 []map[string]interface{}

	users1 = []map[string]interface{}{
		map[string]interface{}{"name": "john doe", "age": 23},
	}

   // users 2 example
	users2 := []map[string]interface{}{
		map[string]interface{}{"name": "john doe", "age": 23},
	}

   // users 2 example
	users3 := make([]map[string]interface{}, 1)
	users3 = []map[string]interface{}{
		map[string]interface{}{"name": "John doe", "age": 23},
	}

   // users 4 example
	var users4 []map[string]interface{} = []map[string]interface{}{map[string]interface{}{"name": "John doe", "age": 23}}

	fmt.Printf("Array object mapping 1 %#v \n", users1)
	fmt.Printf("Array object mapping 2 %#v \n", users2)
	fmt.Printf("Array object mapping 3 %#v \n", users3)
	fmt.Printf("Array object mapping 4 %#v \n", users4)
}

func main() {
	Mapping()
	fmt.Printf("\n")
	ArrayMapping()
}
Restu Wahyu Saputra

Carte de Golang

myMap := make(map[(key type)](value type))
Itchy Ibex

Réponses similaires à “golang cartes”

Questions similaires à “golang cartes”

Plus de réponses similaires à “golang cartes” dans Go

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code