narenarya

go_example.go

Jul 20th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.40 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "crypto/sha1"
  5.     "fmt"
  6.     "time"
  7. )
  8.  
  9. func main() {
  10.     id := make(chan string)
  11.  
  12.     go func() {
  13.         h := sha1.New()
  14.         c := []byte(time.Now().String())
  15.         for {
  16.             h.Write(c)
  17.             id <- fmt.Sprintf("%x", h.Sum(nil))
  18.         }
  19.     }()
  20.  
  21.     fmt.Printf("This program will get 10 IDs from the id channel, print them and terminate\n\n")
  22.  
  23.     for i := 0; i < 10; i++ {
  24.         fmt.Printf("%s\n", <-id)
  25.     }
  26. }
Add Comment
Please, Sign In to add comment