[go-nuts] ANN: "Essential Go" - a free programming book

2018-02-12 Thread Krzysztof Kowalczyk
I'm sharing this hoping it'll be useful for some. I'm working on https://www.programming-books.io/essential/go/, which is a free, open-source, collaborative book about programming in Go. It's based on content generated by Stack Overflow Documentation project. The project was abandoned so I pick

[go-nuts] Re: Proposal: return if any not nil

2018-02-17 Thread Krzysztof Kowalczyk
Even simpler: r, err := try os.Open("blah.text") Similar to Swift and what Rust used to have. "try foo()" means: if "foo()" returns an error, return the error to the caller. If function returns multiple values, it would return zero value for non-error values. I believe now Rust has the follow

[go-nuts] Re: Question about casting

2018-02-18 Thread Krzysztof Kowalczyk
2 things: 1. plus() returns interface{}. "%T" prints underlying dynamic type of interface{} value, but static type of returned value of plus is interface{} You can assign any type to interface{} without a cast by definition (see e.g. https://www.programming-books.io/essential/go/a-90100072-em

Re: [go-nuts] Re: Question about casting

2018-02-18 Thread Krzysztof Kowalczyk
I'm far from the expert on the spec but the behavior seems to follow the rules. https://golang.org/ref/spec#Arithmetic_operators "Arithmetic operators apply to numeric values and yield a result of the same type as the first operand." myInt + myInt returns myInt because it's the type of first o

Re: [go-nuts] json encoding & decoding interface types

2018-02-19 Thread Krzysztof Kowalczyk
The core issue seems to be that that round-tripping via json looses information i.e. type of serialized record. You solved it by embedding type as field of the record, which works. You could embed type implicitly. One way to do it is to use a separate file for each type. The type is implicitly

[go-nuts] Re: strings.Split behavior

2018-02-20 Thread Krzysztof Kowalczyk
Maybe this will help understand what Split() does: https://play.golang.org/p/U7gkrBs8IaZ func main() { s := "this/that there/here that/this" tmp := strings.Split(s, "/") fmt.Printf("%#v\n", tmp) } Output: []string{"this", "that there", "here that", "this"} So when you loop over strings, i

[go-nuts] Re: Cannot take the adress of.....

2018-02-27 Thread Krzysztof Kowalczyk
This is a shallow, visual symmetry. Per Go spec, Foo{} and 5 are not related in a meaningful way. Foo{} denotes a runtime operation that creates a new instance of Foo struct, and & takes an address of this instance. 5 is an integer literal https://golang.org/ref/spec#Integer_literals. While i

[go-nuts] Re: A go document layout problem

2018-03-01 Thread Krzysztof Kowalczyk
Which browser are you using? I checked latest Chrome/Safari/Firefox on mac and they all work as expected. On Thursday, March 1, 2018 at 9:22:43 AM UTC-8, www4000 wrote: > > I find in https://golang.org/pkg/bytes/ > in the section *type Buffer*, > > the *Example

[go-nuts] Re: confusing differences in reflect Type knowledge for a receiver vs. an argument

2018-03-05 Thread Krzysztof Kowalczyk
(in *Inner) InFunc() can't possibly say `in` is Outer. This piece of code: var := Outer{} val.InFunc() Is really: val := Outer{} var tmpInner *Inner = &(val.Inner) tmpInner.InFunc() What is passed to InFunc is a pointer to Inner struct embedded inside Outer struct, not a pointer to Outer stru

[go-nuts] Re: Array in Structs

2018-03-05 Thread Krzysztof Kowalczyk
A an array in JSON maps to a slice of a given type in Go i.e. []*Foo, where Foo is a struct describing the type of array element. You can read up more on JSON mappings: https://www.programming-books.io/essential/go/a-994-json You can use https://mholt.github.io/json-to-go/ which is a tool where

[go-nuts] Re: About a channel detail, bug, defect, or intended?

2018-03-25 Thread Krzysztof Kowalczyk
The way to guarantee that you wait until goroutines are finished is by using sync.WaitGroup. See https://www.programming-books.io/essential/go/139-wait-for-goroutines-to-finish for example and longer description. Alternatively, use range over a channel and arrange the code so that you close t

[go-nuts] Re: ThreadSanitizer: DenseSlabAllocator overflow. Dying.

2018-04-13 Thread Krzysztof Kowalczyk
Based on https://opensource.apple.com/source/clang/clang-700.1.81/src/projects/compiler-rt/lib/tsan/rtl/tsan_dense_alloc.h.auto.html it's an internal thing to thread sanitizer. It seems to be running out of memory when trying to instrument the code. It uses a cache of fixed size of kL1Size en

[go-nuts] Re: I don't know about callbacks in Golang

2018-05-04 Thread Krzysztof Kowalczyk
You can read Essential Go (https://www.programming-books.io/essential/go/) On Friday, May 4, 2018 at 5:53:13 PM UTC-7, Eduardo Moseis Fuentes wrote: > > HI everyone I´m Eduardo from Guatemala and I'm beginer. I'm interesting > in all scope golang in fact I was download a little book about it, b

Re: [go-nuts] Go license and fitness for purpose

2018-05-14 Thread Krzysztof Kowalczyk
On Monday, May 14, 2018 at 7:25:03 AM UTC-7, matthe...@gmail.com wrote: > > But you aren't going to get much in the way of guarantees when you >> receive and use something for free. > > > My work is not free, I want to contribute time back. > >> >> It's unclear if you understand the implications.

[go-nuts] Re: dynamic programming or something else

2018-05-14 Thread Krzysztof Kowalczyk
You can memoize i.e. cache results of kbonacci(). See https://play.golang.org/p/Q2RjWZ2VTh3 for a working but not production ready implementation (for example, cache is specific to k etc.). When running locally for (5,35): Running for n=35 res: 2809074173, time: 12.189908825s res: 2809074173, ti

[go-nuts] Re: Reliable dns client library

2018-05-16 Thread Krzysztof Kowalczyk
miekg/dns is the best dns library by far and is actively maintained. If you see strange results I suggest submitting a bug report. -- kjk https://www.programming-books.io/essential/go/ On Wednesday, May 16, 2018 at 2:16:11 PM UTC-7, sbez...@cisco.com wrote: > > Hello, > > > > Appreciate if som

[go-nuts] Re: runtime: invalid pc-encoded table (invalid runtime symbol table)

2018-08-30 Thread Krzysztof Kowalczyk
The second issue is a bug in runtime, which might be fixed in 1.11 (https://github.com/golang/go/issues/24925 and https://github.com/golang/go/issues/25499 and https://github.com/golang/go/issues/24634 look like might be the issue). The original issue is that storage library calls Client.Do() o

[go-nuts] Re: Go 1.12 with Modules enabled leading to compilation error during tests - wehre as all is OK without modules enabled

2019-02-27 Thread Krzysztof Kowalczyk
https://github.com/golang/go/issues/30374 seems to be the issue and apparently, there's a workaround: > The workaround for now is to include at most one `main` package in the `-coverpkg` arguments, or to run coverage in `GOPATH` mode. On Wednesday, February 27, 2019 at 6:01:33 AM UTC-8, Step

[go-nuts] Re: How do you retrieve certs from the Windows Local Machine cert store with Go?

2019-03-19 Thread Krzysztof Kowalczyk
To get the real error, you probably need to call GetLastError() ( https://docs.microsoft.com/en-us/windows/desktop/api/wincrypt/nf-wincrypt-certopenstore#return-value ). In principle, Go code should behave the same as C++ code, but syscall.CertOpenStore is a wrapper which doesn't seem to use Get

[go-nuts] Re: Launching a windows app from command line with paths in arguments problem

2019-03-21 Thread Krzysztof Kowalczyk
As a total work-around you can always write start_chrome.bat:: your command to launch chrome. and then from go execute as: "cmd.exe", "/k", "start_chrome.bat" (double-check the "/k", I'm writing from memory). Also, to me the red flag is using -foo="quoted argument".parts. On windows, cmd-line a

[go-nuts] Re: Urgent Need - Interview and OFFER tomorrow!

2019-03-28 Thread Krzysztof Kowalczyk
When posting a job opportunity it's helpful to include: * at least a hint as to what the job is * at least a hint as to what the salary will be * since it's a contract, how long and what are the terms * since it's in Plano, TX, is it a remote gig or in office? I certainly wouldn't jump on an inter

[go-nuts] Re: Is go1.10beta1 a debug or unoptimized build? (possible regression)

2017-12-23 Thread Krzysztof Kowalczyk
Most likely it's https://github.com/golang/go/commit/d8ff3d592088ef175222dbf69991887f0dd458d6#diff-b884a414ef2918cd3d75c6799cb62581 which seems to add fair amount of code to time.Now() You can see history of commits to that file with https://github.com/golang/go/commits/master/src/runtime/sys

[go-nuts] Re: [golang-dev] Go 1.10 Beta 2 is released

2018-01-18 Thread Krzysztof Kowalczyk
Make sure to disable anti-virus software. Such software hooks into file operations in order to scan files for viruses and can keep files open longer than you expect. That would be consistent with the error message you're seeing. This is not limited to anti-virus software but it's most common wi

[go-nuts] Re: How to control go routine numbers in function call

2019-06-07 Thread Krzysztof Kowalczyk
See https://www.programming-books.io/essential/go/limiting-concurrency-with-a-semaphore-26ac6084d7404f7385e4eccaa3fd20de for one way that uses a channel as a semaphore to limit concurrency. On Friday, June 7, 2019 at 6:28:01 PM UTC-7, Joseph Wang wrote: > > Hi everyone > > I have a simple ques

[go-nuts] Re: Is slice in golang thread-safe for appending

2017-01-19 Thread Krzysztof Kowalczyk
It's not and it's easy to test: Save as t.go: package main import "fmt" func main() { var s []int for i := 0; i < 10; i++ { go func(n int) { s = append(s, n) }(i) } fmt.Printf("%d\n", s[0]) } hen `go run -race t.go` and watch race detector complain. -- kjk On Thursday, January 19

Re: [go-nuts] go get failing In Mac 10.11.4

2016-06-21 Thread Krzysztof Kowalczyk
My guess is that's because Mac filesystem is case preserving but not case-sensitive, meaning that in mac os "floRest" and "florest" is the same file/directory while on linux those are 2 distinct files. (you can configure mac filesystem to be case-sensitive as well, but that's not the default).