Go project’s main goroutine sleep forever?

“Sleeping” You can use numerous constructs that block forever without “eating” up your CPU. For example a select without any case (and no default): select{} Or receiving from a channel where nobody sends anything: <-make(chan int) Or receiving from a nil channel also blocks forever: <-(chan int)(nil) Or sending on a nil channel also blocks … Read more

Go Auto-Recompile and Reload Server on file change

Another option, if you have nodejs installed on your machine install nodemon with -g npm i -g nodemon go to your code dir and run: nodemon –watch ‘./**/*.go’ –signal SIGTERM –exec ‘go’ run cmd/MyProgram/main.go This will send SIGTERM every time any .go files changes and will run go run cmd/Myprogram/main.go Fully cross platform.

Decreasing slice capacity

You can read more about slices here. But I think this passage answers your question: Slicing does not copy the slice’s data. It creates a new slice value that points to the original array. This makes slice operations as efficient as manipulating array indices. Therefore, modifying the elements (not the slice itself) of a re-slice … Read more

time.Millisecond * int confusion

Operators Operators combine operands into expressions. Comparisons are discussed elsewhere. For other binary operators, the operand types must be identical unless the operation involves shifts or untyped constants. For operations involving constants only, see the section on constant expressions. Except for shift operations, if one operand is an untyped constant and the other operand is … Read more

reflection on embedded structs

The ‘transparency’ you expected is just syntactic sugar and has nothing to do with the data representation. If you want to have a function that flattens your data structure, you would have to write it by yourself. For example (On play): func DeepFields(iface interface{}) []reflect.Value { fields := make([]reflect.Value, 0) ifv := reflect.ValueOf(iface) ift := … Read more

How to get name of current package in go?

There is no runtime or reflect method or function that provides the functionality that you are looking for. The closest thing I could find is: package main import ( “azul3d.org/lmath.v1” “fmt” “reflect” ) type Empty struct{} func main() { fmt.Println(reflect.TypeOf(Empty{}).PkgPath()) fmt.Println(reflect.TypeOf(lmath.Vec3{0, 0, 0}).PkgPath()) } This would output: main azul3d.org/lmath.v1 You could also read the first … Read more

golang: how to simulate union type efficiently

You can use arrays to represent a single int32 as two int16s and then assemble them with shifts as Rob Pike recommends: func test3() (total int64) { type A struct { t int32 u [2]int16 } a := […]A{ {1, [2]int16{100, 0}}, {2, [2]int16{3, 0}}, } for i := 0; i < N; i++ { … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)