Skip to content

Instantly share code, notes, and snippets.

@Reine0017
Created August 9, 2022 10:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Reine0017/ad50a871ce5dae1865fc300583619a11 to your computer and use it in GitHub Desktop.
Save Reine0017/ad50a871ce5dae1865fc300583619a11 to your computer and use it in GitHub Desktop.
complex channel
package main
import (
"fmt"
"strings"
)
type FullName struct {
firstName string
lastName string
}
func NameFunc(nameChannel chan FullName, name string) {
splitName := strings.Split(name, " ")
res := FullName{}
res.firstName = "firstName: " + splitName[0]
res.lastName = "lastName: " + splitName[1]
nameChannel <- res
}
func main() {
nameChannel := make(chan FullName)
go NameFunc(nameChannel, "Reine Fang")
value := <-nameChannel //blocking call
fmt.Println("Full Name", value)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment