https://github.com/zing-dev/hello-go
hello-go
https://github.com/zing-dev/hello-go
go golang golang-examples golang-library learn-go
Last synced: 9 months ago
JSON representation
hello-go
- Host: GitHub
- URL: https://github.com/zing-dev/hello-go
- Owner: zing-dev
- Created: 2017-09-30T05:33:10.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-10-21T08:48:14.000Z (about 1 year ago)
- Last Synced: 2025-03-24T14:04:32.950Z (9 months ago)
- Topics: go, golang, golang-examples, golang-library, learn-go
- Language: Go
- Homepage: https://github.com/zhangrxiang/hello-go
- Size: 24.1 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# learn-go
> This is an open source project to learn golang
```go
package main
import (
"context"
"log"
"sync"
"time"
)
func HelloWorld() {
time.Sleep(time.Second)
log.Println("Hello, World!")
}
func HelloWorld2() {
c := make(chan struct{})
go func() {
time.Sleep(time.Second)
log.Println("Hello, World chan!")
c <- struct{}{}
}()
<-c
}
func HelloWorld3() {
var g sync.WaitGroup
g.Add(1)
go func(){
time.Sleep(time.Second)
log.Println("Hello, World WaitGroup!")
g.Done()
}()
g.Wait()
}
func HelloWorld4() {
cond := sync.NewCond(new(sync.Mutex))
go func() {
time.Sleep(time.Second)
log.Println("Hello, World Cond!")
cond.Signal()
}()
cond.L.Lock()
cond.Wait()
cond.L.Unlock()
}
func HelloWorld5() {
ctx, cancel := context.WithCancel(context.Background())
go cancel()
select {
case <-ctx.Done():
time.Sleep(time.Second)
log.Println("Hello, World WithCancel!")
}
}
func main() {
HelloWorld()
HelloWorld2()
HelloWorld3()
HelloWorld4()
HelloWorld5()
}
```