Answers for "go example"

Go
0

go new example

package main

import "fmt"

func main() {

	var data int = 10
	x := &data
	fmt.Println(*x)
	
	xx := new(int)
	*xx = 10
	fmt.Println(*xx)
}
Posted by: Guest on September-29-2021
0

golang example

Gopack CLI is instant package downloader for Go Programming, 
if you use Gopack CLI you can download your favorite package library 
with very easy, just play the keyboard and select the package you need,
wait a while until your package is installed and Gopack CLI 
also supports installing multiple modules at the same time.

npm i gopack-cli
Posted by: Guest on July-20-2021
0

go make example

package main
type Foo map[string]string
type Bar struct {
         s string
         i int
}
func main() {
         // OK:
         y := new(Bar)
         (*y).s = "hello"
         (*y).i = 1

         // NOT OK:
         z := make(Bar) // compile error: cannot make type Bar
         z.s = "hello"
         z.i = 1

         // OK:
         x := make(Foo)
         x["x"] = "goodbye"
         x["y"] = "world"

         // NOT OK:
         u := new(Foo)
         (*u)["x"] = "goodbye" // !!panic!!: runtime error: 
                   // assignment to entry in nil map
         (*u)["y"] = "world"
}
Posted by: Guest on September-29-2021
0

go make example

var p *[]int = new([]int)
or
p := new([]int)
Posted by: Guest on September-29-2021
0

go make example

func main() {
    // OK:
    ch := make(chan string)
    go sendData(ch)
    go getData(ch)
    time.Sleep(1e9)

    // NOT OK:
    ch := new(chan string)
    go sendData(ch) // cannot use ch (variable of type *chan string) 
                   // as chan string value in argument to sendData
    go getData(ch)
    time.Sleep(1e9)
}

func sendData(ch chan string) {
    ch <- "Washington"
    ch <- "Tripoli"
    ch <- "London"
    ch <- "Beijing"
    ch <- "Tokio"
}

func getData(ch chan string) {
    var input string
    for {
        input = <-ch
        fmt.Printf("%s ", input)

    }
}
Posted by: Guest on September-29-2021

Browse Popular Code Answers by Language