Fix Go format
This commit is contained in:
parent
14e763c65a
commit
256f79a099
32
main.go
32
main.go
|
@ -1,9 +1,9 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -18,28 +18,30 @@ import "C"
|
||||||
|
|
||||||
//export callOnMeGo
|
//export callOnMeGo
|
||||||
func callOnMeGo(n int) {
|
func callOnMeGo(n int) {
|
||||||
printerCallback(n)
|
printerCallback(n)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Printer func(int)
|
type Printer func(int)
|
||||||
|
|
||||||
var printerCallback Printer
|
var (
|
||||||
var printerCallbackLock sync.RWMutex
|
printerCallback Printer
|
||||||
|
printerCallbackLock sync.RWMutex
|
||||||
|
)
|
||||||
|
|
||||||
func usePrinter(p Printer) {
|
func usePrinter(p Printer) {
|
||||||
printerCallbackLock.Lock()
|
printerCallbackLock.Lock()
|
||||||
printerCallback = p
|
printerCallback = p
|
||||||
C.use_printer((C.printer_t)(unsafe.Pointer(C.callOnMeGo_cgo)))
|
C.use_printer((C.printer_t)(unsafe.Pointer(C.callOnMeGo_cgo)))
|
||||||
printerCallback = nil
|
printerCallback = nil
|
||||||
printerCallbackLock.Unlock()
|
printerCallbackLock.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
var myPrinter Printer = Printer(func(n int) {
|
var myPrinter Printer = Printer(func(n int) {
|
||||||
for i := 0; i < n; i++ {
|
for i := 0; i < n; i++ {
|
||||||
fmt.Printf("%d\n", i)
|
fmt.Printf("%d\n", i)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
usePrinter(myPrinter)
|
usePrinter(myPrinter)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue