MakeFile multi example for multi layer with golang application or other applications
Go
Makefile
make -h
gomodinitgithub.com/ahmed82/go-makefile
Manual run without make , Makefile
gorun main.gomutex.goorgorun .
Mutex example
var (
mutex sync.Mutexbalanceint
)
funcwithdraw(valueint, wg*sync.WaitGroup) {
mutex.Lock()
fmt.Printf("Withdrawing %d to account with balance %d\n ", value, balance)
balance-=valuemutex.Unlock()
wg.Done()
}
funcdeposit(valueint, wg*sync.WaitGroup) {
mutex.Lock()
fmt.Printf("Depositing %d to account with balance %d\n ", value, balance)
balance+=valuemutex.Unlock()
wg.Done()
}
funcmain() {
fmt.Println("Mutext")
balance=1000varwg sync.WaitGroupwg.Add(2)
gowithdraw(700, &wg)
godeposit(500, &wg)
wg.Wait()
fmt.Printf(" New balance %d\n", balance)
}
Go Channel's Select operetor
funcmain() {
one:=make(chanstring)
two:=make(chanstring)
quit:=make(chanstring)
gofunc() {
time.Sleep(2*time.Second)
one<-"Hey From Channel One"
}()
gofunc() {
time.Sleep(3*time.Second)
two<-"Hello From Channel Two"
}()
select {
caseres1:=<-one:
fmt.Println("I get from channel One!", res1)
caseres2:=<-two:
fmt.Println("I get from channel Two!", res2)
// if any value has been pushed to the quit channel then it is true for this case// amd it will quit the select by running the returncase<-quit:
return
}
}