[go-nuts] GCP will lowercase header names from September 30. – I would like to update my code to only send lowercase headers

2019-08-27 Thread martin
I received this email the other day:


Hello Google HTTP(S) Load Balancing Customer,
> We’re writing to let you know about a change to the behavior of HTTP(S) 
> Load Balancers 
> <https://www.google.com/appserve/mkt/p/AFnwnKV6zRxIMF-67TmW7W5HvnDdf-QAcingmd5i49SjY2PNzfS3NJMTGC8kkgPg4HrPsLrxNG6_La2vPBkoj0naADyEkZefRHpWf5kKwcN7xfh9uo8DXUqNbr4>
>  
> that is being rolled out gradually, beginning September 30, 2019. We are 
> making this change to standardize HTTP(S) load balancer behavior across 
> HTTP/1.1 and more modern protocols, including HTTP/2 and QUIC.
> What do I need to know?
> After September 30, HTTP(S) Load Balancers will convert HTTP/1.1 header 
> names to lowercase in the request and response directions; header values 
> will not be affected.


I would prefer not do delegate the responsibility of my HTTP header casing 
to GCP. Who knows, perhaps this code will live somewhere else one day?
Is there a way I could "easily" lowercase all the HTTP headers I send?

e.g.
w.Header().Set("x-sync-token", csrf.Token(r))
Will be sent as *X-Sync-Token*


What do you guys do? Do you think it's necessary to update the headers sent 
as long as the clients are case insensitive? 



Best,
Martin

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/be3bf673-5ac1-4a01-a39c-325480254734%40googlegroups.com.


[go-nuts] Several issues on macOS Sierra

2016-09-22 Thread martin
Hello,

Since upgrading to macOS Sierra, I've stumbled upon a few issues that were 
not present when using OSX El Capitan.

All issues arise when using this package 
https://github.com/jteeuwen/go-bindata however from my cursory glance 
there's nothing specific about that code that seems troublesome.

Stack traces for the issues I've stumbled on are below - I can't reliably 
reproduce them and I haven't been able to create a minimal test case to 
reproduce it either. Sometimes it works, sometimes it doesn't. However I 
can say that it panics more often than not.

Specs:
Go 1.7.1
MacBook Pro Retina , 16GB RAM, 2.3 GHz Intel Core i7

I've changed my working directory to say "GOROOT" in the pastebins - but 
there's nothing special about that path. Just my home working directory. 
Also the script to invoke go-bindata, generate_models.sh, is bare bones and 
just invoked the binary ./bin/go-bindata/ several times, one after another. 
I can post that, too, but I don't think it'll be very helpful because again 
- this all used to work.

Stack trace 1:
http://pastebin.com/X8Zv7Hy8

Stack trace 2:
This one has the same panic as #1 but also has an issue with entersyscall
http://pastebin.com/MzFuaVCe

I know I'm a bit light on details here but I'm hoping a core Go dev might 
see these stack traces and know what's up.

Please let me know what other info I can produce to help track the issue 
down.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Several issues on macOS Sierra

2016-09-22 Thread martin
Dave you were right, just had to rebuild the binary.

On Thursday, September 22, 2016 at 4:48:44 PM UTC-4, Dave Cheney wrote:
>
> Sierra broke programs compiled with previous versions of Go. You've 
> probably got an old version of go-bindata in your path, delete that, and 
> run go install -v github.com/jteeuwen/go-bindata/go-bindata
>
> If this line does not return at least one line of output, there is a 
> problem in with your Go installation.
>
> On Friday, 23 September 2016 01:26:30 UTC+10, mar...@repustate.com wrote:
>>
>> Hello,
>>
>> Since upgrading to macOS Sierra, I've stumbled upon a few issues that 
>> were not present when using OSX El Capitan.
>>
>> All issues arise when using this package 
>> https://github.com/jteeuwen/go-bindata however from my cursory glance 
>> there's nothing specific about that code that seems troublesome.
>>
>> Stack traces for the issues I've stumbled on are below - I can't reliably 
>> reproduce them and I haven't been able to create a minimal test case to 
>> reproduce it either. Sometimes it works, sometimes it doesn't. However I 
>> can say that it panics more often than not.
>>
>> Specs:
>> Go 1.7.1
>> MacBook Pro Retina , 16GB RAM, 2.3 GHz Intel Core i7
>>
>> I've changed my working directory to say "GOROOT" in the pastebins - but 
>> there's nothing special about that path. Just my home working directory. 
>> Also the script to invoke go-bindata, generate_models.sh, is bare bones and 
>> just invoked the binary ./bin/go-bindata/ several times, one after another. 
>> I can post that, too, but I don't think it'll be very helpful because again 
>> - this all used to work.
>>
>> Stack trace 1:
>> http://pastebin.com/X8Zv7Hy8
>>
>> Stack trace 2:
>> This one has the same panic as #1 but also has an issue with entersyscall
>> http://pastebin.com/MzFuaVCe
>>
>> I know I'm a bit light on details here but I'm hoping a core Go dev might 
>> see these stack traces and know what's up.
>>
>> Please let me know what other info I can produce to help track the issue 
>> down.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Go 1.22.0: Alpine: go test with coverage works but returns exit status 1

2024-02-07 Thread Martin
I am using the new `golang:1.22.0-alpine3.19` Alpine image to build and 
test a Golang 1.22.0 application. The test uses coverage like that `go test 
-v ./... -coverprofile=coverage.out -coverpkg=./internal/... -covermode 
count`. The test command seems to work fine, but the exit status is 1. The 
created coverage.out seems also fine, as I could use go tool cover with it, 
see below.

Golang version: 1.22.0
Container Image: golang:1.22.0-alpine3.19

Reproducer:

main.go:
package main

import (
  "example.com/m/internal"
  "fmt"
)

func main() {
  fmt.Println(internal.Helloer())
}


internal/helloer.go:
package internal

func Helloer() string {
  return "Hello, world!"
}

internal/helloer_test.go:
package internal

import "testing"

func TestHelloer(t *testing.T) {
  want := "Hello, world!"
  got := Helloer()
  t.Errorf("Helloer() = %v, want %v", got, want)
}

go.mod:
module example.com/m

go 1.22

Shell commands for testing:

apk add --no-cache build-base
go test -v ./... -coverprofile=coverage.out -coverpkg=./internal/... 
-covermode count || echo "flaky:$?"
go tool cover -html=coverage.out -o coverage.html
go tool cover -func=coverage.out


Is it a bug or exepected behaviour?



-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/9fe031e4-7f3d-4508-b194-bd9074b3dcfcn%40googlegroups.com.


[go-nuts] Re: Go 1.22.0: Alpine: go test with coverage works but returns exit status 1

2024-02-07 Thread Martin
I need to add:

In the post the reproducer test is of course to short, so the test show 
that it fails all the time. But that triggers the problem anyway. Better 
would be this:

func TestHelloer(t *testing.T) {
  want := "Hello, world!"
  got := Helloer()
  if got != want {
t.Errorf("Helloer() = %v, want %v", got, want)
  }
}

Also, the output of the go test call has a inidication why it has exit 
status 1:

$ go test -v ./... -coverprofile=coverage.out -coverpkg=./internal/... 
-covermode count
example.com/m: open 
/tmp/go-build1679138031/b002/covmeta.f6e4431d5ec1fd71f02b3ce4e56eb691a86525173d917007425576a7d9db7c72:
 
no such file or directory
=== RUN   TestHelloer
helloer_test.go:8: Helloer() = Hello, world!, want Hello, world!
--- FAIL: TestHelloer (0.00s)
FAIL
coverage: 100.0% of statements in ./internal/...
FAILexample.com/m/internal0.003s


Also this happens with the Alpine based image, but also for the Debian 
based image as well.

On Thursday, February 8, 2024 at 12:43:32 AM UTC+1 Martin wrote:

> I am using the new `golang:1.22.0-alpine3.19` Alpine image to build and 
> test a Golang 1.22.0 application. The test uses coverage like that `go 
> test -v ./... -coverprofile=coverage.out -coverpkg=./internal/... 
> -covermode count`. The test command seems to work fine, but the exit status 
> is 1. The created coverage.out seems also fine, as I could use go tool 
> cover with it, see below.
>
> Golang version: 1.22.0
> Container Image: golang:1.22.0-alpine3.19
>
> Reproducer:
>
> main.go:
> package main
>
> import (
>   "example.com/m/internal"
>   "fmt"
> )
>
> func main() {
>   fmt.Println(internal.Helloer())
> }
>
>
> internal/helloer.go:
> package internal
>
> func Helloer() string {
>   return "Hello, world!"
> }
>
> internal/helloer_test.go:
> package internal
>
> import "testing"
>
> func TestHelloer(t *testing.T) {
>   want := "Hello, world!"
>   got := Helloer()
>   t.Errorf("Helloer() = %v, want %v", got, want)
> }
>
> go.mod:
> module example.com/m
>
> go 1.22
>
> Shell commands for testing:
>
> apk add --no-cache build-base
> go test -v ./... -coverprofile=coverage.out -coverpkg=./internal/... 
> -covermode count || echo "flaky:$?"
> go tool cover -html=coverage.out -o coverage.html
> go tool cover -func=coverage.out
>
>
> Is it a bug or exepected behaviour?
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/c2fcc039-075e-4208-879e-5fdc11a0a18dn%40googlegroups.com.


[go-nuts] Re: Go 1.22.0: Alpine: go test with coverage works but returns exit status 1

2024-02-10 Thread Martin
Hey Aldemar and Thomas,

thanks for your hints.

>  While trying to upgrade a go package to 1.22.0 today, I ran into this 
same issue in my coverage step. From testing different combinations of 
options for `go test`, it seems that the 'no such file or directory' errors 
and resulting non-zero exit code occur when go test processes a 
folder/package that isn't included in the -coverpkg list- e.g. in your 
case, any package that isn't part of ./internal. When I set -coverpkg equal 
to the entire list of packages in the project, the error goes away.

You are right, if I adopt your command, the errors go away.

There seem several issues with the new code coverage design, see
https://github.com/golang/go/issues/65570
https://github.com/golang/go/issues/65636

In both issues its addressed, that with
$ GOEXPERIMENT=nocoverageredesign go test -v ./... 
-coverprofile=coverage.out -coverpkg=./internal/... -covermode count

The old behaviour is used and the error is gone as well.

I assume the root cause is related to the both issues linked above, but 
will create a new issue anyway.
I will include your findings as well.

On Thursday, February 8, 2024 at 11:14:58 PM UTC+1 Thomas McNulty wrote:

> While trying to upgrade a go package to 1.22.0 today, I ran into this same 
> issue in my coverage step. From testing different combinations of options 
> for `go test`, it seems that the 'no such file or directory' errors and 
> resulting non-zero exit code occur when go test processes a folder/package 
> that isn't included in the -coverpkg list- e.g. in your case, any package 
> that isn't part of ./internal. When I set -coverpkg equal to the entire 
> list of packages in the project, the error goes away.
>
> Running with some packages (in this case, mocks) excluded:
>
> % go version
> go version go1.22.0 darwin/arm64
> % CVPKG=$(go list ./... | grep -v mocks | tr '\n' ',')
> % go test -coverpkg=${CVPKG} -coverprofile=coverage.out -covermode=count 
>  ./...
>   ... (tests passing)
> github.com///internal/mocks/a/b: open 
> /var/folders/c4/kbr99g196216gsv36c94cp84gn/T/go-build466145861/b849/covmeta.3a394ea9611306b457bfb2f5b2169adffc13123f3b07d667fd86b58eac717920:
>  
> no such file or directory
> github.com///internal/mocks/c: open 
> /var/folders/c4/kbr99g196216gsv36c94cp84gn/T/go-build466145861/b851/covmeta.5fc2c6ff11ae04da5c2cdbbb4c9e9e64d515086b2a7a7f5660d5dc409cdf5724:
>  
> no such file or directory
> github.com///internal/mocks/e/f: open 
> /var/folders/c4/kbr99g196216gsv36c94cp84gn/T/go-build466145861/b853/covmeta.2405ba52a1121a0f4a20da157347d9217eff95f8d18b9ae656cf0414aefe8221:
>  
> no such file or directory
>   ... (more tests passing)
> % echo $? 
>  
> 1
>
>
> Vs. running with no packages excluded:
>
> % go version
> go version go1.22.0 darwin/arm64
> % CVPKG=$(go list ./... | tr '\n' ',')
> % go test -coverpkg=${CVPKG} -coverprofile=coverage.out -covermode=count 
> ./...
>  (all tests passing)
> % echo $?
> 0
> On Thursday, February 8, 2024 at 2:41:18 PM UTC-5 Martin Schallnahs wrote:
>
>> Hey Brian,
>>
>> dont get me wrong!
>>
>> My usual setup is Continuous Integration Pipeline running in Linux VMs 
>> which, in case of my golang projects, start fresh golang docker container 
>> images from DockerHub.
>> In case of this problem I used golang:1.22.0-alpine3.19 and golang:1.22.0 
>> (debian basd).
>> For both I have the problem I describe.
>> I just wanted to show, that its not a Docker problem and used my local 
>> Windows machine do prove that.
>>
>> I grabbed my Macbook Pro (Intel), installed freshly Golang 1.22.0 and run 
>> the mentioned go test command on the reproducer, and for me here the 
>> problem also gets triggered.
>> As you explained I use the corrected reproducer, with the Test not 
>> failing, and have "go 1.22.0" in the go.mod.
>>
>>
>> $ go version
>> go version go1.22.0 darwin/amd64
>>
>> $ go test -v ./... -coverprofile=coverage.out -coverpkg=./internal/... 
>> -covermode count
>> example.com/m: open 
>> /var/folders/dm/k73ydgtx15l7dzwc3qk_wmhcgn/T/go-build3097649140/b002/covmeta.f6e4431d5ec1fd71f02b3ce4e56eb691a86525173d917007425576a7d9db7c72:
>>  
>> no such file or directory
>>
>> === RUN TestHelloer
>> --- PASS: TestHelloer (0.00s)
>> PASS
>> coverage: 100.0% of statements in ./internal/...
>> ok example.com/m/internal 0.261s coverage: 100.0% of statements in 
>> ./internal/…
>>
>>
>> Bit confusing, that it works for you though.
&g

[go-nuts] Re: Go 1.22.0: Alpine: go test with coverage works but returns exit status 1

2024-02-10 Thread Martin
Created a issue based on our discussion:
https://github.com/golang/go/issues/65653

On Saturday, February 10, 2024 at 10:49:58 PM UTC+1 Martin wrote:

> Hey Aldemar and Thomas,
>
> thanks for your hints.
>
> >  While trying to upgrade a go package to 1.22.0 today, I ran into this 
> same issue in my coverage step. From testing different combinations of 
> options for `go test`, it seems that the 'no such file or directory' errors 
> and resulting non-zero exit code occur when go test processes a 
> folder/package that isn't included in the -coverpkg list- e.g. in your 
> case, any package that isn't part of ./internal. When I set -coverpkg equal 
> to the entire list of packages in the project, the error goes away.
>
> You are right, if I adopt your command, the errors go away.
>
> There seem several issues with the new code coverage design, see
> https://github.com/golang/go/issues/65570
> https://github.com/golang/go/issues/65636
>
> In both issues its addressed, that with
> $ GOEXPERIMENT=nocoverageredesign go test -v ./... 
> -coverprofile=coverage.out -coverpkg=./internal/... -covermode count
>
> The old behaviour is used and the error is gone as well.
>
> I assume the root cause is related to the both issues linked above, but 
> will create a new issue anyway.
> I will include your findings as well.
>
> On Thursday, February 8, 2024 at 11:14:58 PM UTC+1 Thomas McNulty wrote:
>
>> While trying to upgrade a go package to 1.22.0 today, I ran into this 
>> same issue in my coverage step. From testing different combinations of 
>> options for `go test`, it seems that the 'no such file or directory' errors 
>> and resulting non-zero exit code occur when go test processes a 
>> folder/package that isn't included in the -coverpkg list- e.g. in your 
>> case, any package that isn't part of ./internal. When I set -coverpkg equal 
>> to the entire list of packages in the project, the error goes away.
>>
>> Running with some packages (in this case, mocks) excluded:
>>
>> % go version
>> go version go1.22.0 darwin/arm64
>> % CVPKG=$(go list ./... | grep -v mocks | tr '\n' ',')
>> % go test -coverpkg=${CVPKG} -coverprofile=coverage.out -covermode=count 
>>  ./...
>>   ... (tests passing)
>> github.com///internal/mocks/a/b: open 
>> /var/folders/c4/kbr99g196216gsv36c94cp84gn/T/go-build466145861/b849/covmeta.3a394ea9611306b457bfb2f5b2169adffc13123f3b07d667fd86b58eac717920:
>>  
>> no such file or directory
>> github.com///internal/mocks/c: open 
>> /var/folders/c4/kbr99g196216gsv36c94cp84gn/T/go-build466145861/b851/covmeta.5fc2c6ff11ae04da5c2cdbbb4c9e9e64d515086b2a7a7f5660d5dc409cdf5724:
>>  
>> no such file or directory
>> github.com///internal/mocks/e/f: open 
>> /var/folders/c4/kbr99g196216gsv36c94cp84gn/T/go-build466145861/b853/covmeta.2405ba52a1121a0f4a20da157347d9217eff95f8d18b9ae656cf0414aefe8221:
>>  
>> no such file or directory
>>   ... (more tests passing)
>> % echo $? 
>>      
>> 1
>>
>>
>> Vs. running with no packages excluded:
>>
>> % go version
>> go version go1.22.0 darwin/arm64
>> % CVPKG=$(go list ./... | tr '\n' ',')
>> % go test -coverpkg=${CVPKG} -coverprofile=coverage.out -covermode=count 
>> ./...
>>  (all tests passing)
>> % echo $?
>> 0
>> On Thursday, February 8, 2024 at 2:41:18 PM UTC-5 Martin Schallnahs wrote:
>>
>>> Hey Brian,
>>>
>>> dont get me wrong!
>>>
>>> My usual setup is Continuous Integration Pipeline running in Linux VMs 
>>> which, in case of my golang projects, start fresh golang docker container 
>>> images from DockerHub.
>>> In case of this problem I used golang:1.22.0-alpine3.19 and 
>>> golang:1.22.0 (debian basd).
>>> For both I have the problem I describe.
>>> I just wanted to show, that its not a Docker problem and used my local 
>>> Windows machine do prove that.
>>>
>>> I grabbed my Macbook Pro (Intel), installed freshly Golang 1.22.0 and 
>>> run the mentioned go test command on the reproducer, and for me here the 
>>> problem also gets triggered.
>>> As you explained I use the corrected reproducer, with the Test not 
>>> failing, and have "go 1.22.0" in the go.mod.
>>>
>>>
>>> $ go version
>>> go version go1.22.0 darwin/amd64
>>>
>>> $ go test -v ./... -coverprofile=coverage.out -coverpkg=./internal/... 
>>> 

Re: [go-nuts] [ANN] fixed point math library

2018-12-01 Thread Anthony Martin
Nigel Tao  once said:
> Well, there's already context.Context, hash.Hash, image.Image and
> time.Time in the standard library.

All of which are not great. Better names are context.Frame,
hash.Function, raster.Image, and time.Instant.

  Anthony

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: pointer dereference optimization in loops

2018-12-01 Thread Anthony Martin
Mark Volkmann  once said:
> Suppose myPtr is a pointer and I write code like this:
> 
> for _, v := range values {
> fmt.Printf("%v %v\n", *myPtr, v)
> }
> 
> Will the Go compiler optimize the pointer dereference so it doesn't happen
> in every loop iteration? If not, is it common practice to do that outside
> the loop like this?

The comments on https://github.com/golang/go/issues/15635 may be of
particular interest.

  Anthony

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] [ANN] fixed point math library

2018-12-01 Thread Anthony Martin
A hash function is a mathematical construction.
A raster image is a type of graphical representation.
A time instant is a single point in a duration.

All of these are clear as can be.

I'll give you "context frame". It is a bit wonky.
A better phrase is out there somewhere. Scope,
environment, etc. could work but it also must
convey be carried or passed around.

We have lots of English words. Why not use them?

  Anthony

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] parse timestamp in Go

2019-02-08 Thread Martin Schnabel
just for future reference, there is no format for 'this' (the format op 
asked for). because this format does not have a period. i was just as 
surprised. you can try yourself: https://play.golang.org/p/wv_PDwTmEOk


the documentation also states that you do not specify the fraction 
seconds for parsing, when a period follows the seconds field.



On 08.02.19 15:04, Philippe DESJACQUES wrote:

Le 08/02/2019 à 01:10, Burak Serdar a écrit :

On Thu, Feb 7, 2019 at 2:28 PM Rajanikanth Jammalamadaka
  wrote:

How can I parse the following timestamp in Go?

date +%y%m%d%H%M%S%N

190207202017034235995

for the ymdHMS part, you can use:

time.Parse("060102150405",str[:12])

I don't know if time parser has something for the %N, you might need
to do it manually, line strconv.Atoi(str[12:])


Hello,

Yes there is a layout for this according to documentation :

"A fractional second is represented by adding a period and zeros to the 
end of the seconds section of layout string, as in "15:04:05.000" to 
format a time stamp with millisecond precision." -> 
https://golang.org/pkg/time/#Time.Format


So in your case 9 "0" after period ;)

Regards,

Philippe

--
You received this message because you are subscribed to the Google 
Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to golang-nuts+unsubscr...@googlegroups.com 
.

For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: WebAssembly: Auto-generating Go bindings for javascript/DOM from the Web Standards.

2019-02-24 Thread Martin Juhlin
Hi,

I have started to work on DOM binding based on WebIDL and a binding 
generator. I don't have full WebIDL support yet, but it does process idl 
from about 80 specifications. See https://gowebapi.github.io for more 
details.

   Martin

Den fredag 28 december 2018 kl. 13:16:22 UTC+1 skrev Chris FractalBach:
>
> This is in the context of compiling Go to webassembly that will be used 
> with javascript.
>
>
> *Currently:*
>
> We have`syscall/js` which has stuff like this:
> ```go
> js.Global().Get("document").Call("createElement", "div")
> ```
>
> What it could be:
> ```go
> js.document.createElement("div")
> ```
>
>
>
> *Why?*
>
> This would make writing stuff for webassembly WAY easier.
> Auto-generating it would allow it to update definitions whenever the 
> standards
> are updated.  Which would make it easier to maintain.
>
> Also, if there's going to be significant usage of
> Go -> webassembly -> web browser and javascript
> then having all the types and definitions auto-generated would save on tons
> of boilerplate abstractions that people will inevitably create for their 
> own sanity.
>
> Advantages:
> - more natural to use
> - more readable
> - type safe
>
> Disadvantages:
> - less flexible
> - when the APIs are updated, it might result in loss of 
> backwards-compatibility
>
>
>
>
> *How?*
>
> WebIDL --> Go source code
>
> - https://www.w3.org/TR/WebIDL/
> - https://heycam.github.io/webidl/
> - https://www.w3.org/TR/DOM-Level-3-Core/idl-definitions.html
>
>
>
>
> Technical reports published by the W3C that include programming language 
>> interfaces have typically been described using the Object Management 
>> Group’s Interface Definition Language (IDL) [OMGIDL]. The IDL provides a 
>> means to describe these interfaces in a language independent manner. 
>> Usually, additional language binding appendices are included in such 
>> documents which detail how the interfaces described with the IDL correspond 
>> to constructs in the given language.
>
> https://www.w3.org/TR/WebIDL/#introduction
>
>
>
>
>
> *A Possible Conversion:*
>
> *From WebIDL:*
> ```
> [Exposed=Window]
> interface Paint { };
>
>
> [Exposed=Window]
> interface SolidColor : Paint {
>   attribute double red;
>   attribute double green;
>   attribute double blue;
> };
>
>
> [Exposed=Window]
> interface Pattern : Paint {
>   attribute DOMString imageURL;
> };
>
>
> [Exposed=Window, Constructor]
> interface GraphicalWindow {
>   readonly attribute unsigned long width;
>   readonly attribute unsigned long height;
>
>
>   attribute Paint currentPaint;
>
>
>   void drawRectangle(double x, double y, double width, double height);
>
>
>   void drawText(double x, double y, DOMString text);
> };
>
> ```
> Example From: https://heycam.github.io/webidl/
>
>
>
> *To Go:*
>
> This is probably not the best way to do it, but is an example of how it 
> might look.
>
> type Paint struct {}
>
>
> type SolidColor struct {
>  Red   float64
>  Green float64
>  Blue  float64
> }
>
>
> type GraphicalWindow struct {
>  widthuint32
>  height   uint32
>  CurrentPaint Paint
> }
>
>
> func (gw *GraphicalWindow) drawRectangle(x, y, width, height float64) {
> // syscall
> }
>
>
> func (gw *GraphicalWindow) drawText(x, y float64, text string) {
> // syscall
> }
>
>
>
>
>
>
> I know there are some existing examples of Go bindings for DOM, 
> but I don't think they are auto-generated from WebIDL,
> Which I imagine would be easier to maintain in the long-run.
>
>
>
>
> Anybody have thoughts on this?
>
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Announcement: DOM, HTML bindings for Go WASM + binding generator

2019-02-25 Thread Martin Juhlin


Hi,

I like to announce my open source project, https://gowebapi.github.io that 
is Go Web Assembly bindings for things like DOM, HTML, WebGL 1 & 2, SVG 2, 
CSS, media streams, payment etc, etc. It currently consists of about 80 
different standards, see status page for details.

Godocs: https://godoc.org/github.com/gowebapi/webapi (don’t forget the 
directory section)

The bindings is actually generated from WebIDL. The binding program is part 
of the project. WebIDL is commonly used in browser specification and to 
generate the browser javascript api. By taking these files, we get a very 
up to date version of what is supported. There is however a philosophical 
dilemma of what IDL files to use. It currently using an extraction of 
specification document. Maybe it’s better to get the files from Chrome or 
Firefox source code tree instead?

Currently most of the focus have been on creating the binder program, not 
on the API itself. There is a lot of work left to do, like the Promise 
class (that actually require generic) and doing “styling”. Binder can 
perform transformation on final output like moving types into packages and 
renaming (notification.NotificationRequest to notification.Request). 

It doesn’t also have full WebIDL support yet and that is the main blocker 
of the remaining 50 specs.

Another important part is documentation. Does anyone know a good source 
with machine readable API doc that can be used to create godoc’s?

In theory the binder program can be used to create bindings for any 
javascript library as long its API can be expressed within the limitation 
of WebIDL. Some sort of extension is probably needed in the future as 
javascript modules can’t be properly expressed, but that is more a long 
term goal. 

I hope you all will find the project useful as binding code between go web 
assembly and javascript should be generated and not manually written :-)


Martin


-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: WebAssembly: Auto-generating Go bindings for javascript/DOM from the Web Standards.

2019-02-25 Thread Martin Juhlin
Hi,

The code is Parser is actually a fork that I did some modifications to
(like line number). Can be found at https://github.com/gowebapi/webidlparser

The main flow is currently:
* Parse with webidlparser to get a AST tree.
* Convert into internal types in “github.com/gowebapi/webidl-bind/types”.
* Applying transformation like adding Go packages in “
github.com/gowebapi/webidl-bind/transform”.
* And finally the generation step in “github.com/gowebapi/webidl-bind/gowasm
”.

To use WebIDL to create binding for React.js can be problematic as the
standard as-is doesn’t support for javascript modules. The IDL standard
that WebIDL based on however does. It uses C++ like syntax (foo::bar)
inside “namespace” block. It’s probably not hard to solve.

In the current handwritten library, how is the interaction with JSX solved?
It feels like that normal react.js code is compiled.

Martin


On Mon, Feb 25, 2019 at 7:41 AM Paul Jolly  wrote:

> I have started to work on DOM binding based on WebIDL and a binding
>> generator. I don't have full WebIDL support yet, but it does process idl
>> from about 80 specifications. See https://gowebapi.github.io for more
>> details.
>>
>
> Hi Martin,
>
> I'd like to second Tyler's suggestion that you start a new thread, very
> exciting!
>
> My question is: to what extent is your WebIDL parser and AST equivalent
> separate from the Go-WASM target code you are generating?
>
> Reason being, I'd like the use the IDL specs to generate Go code for React
> bindings, replacing currently hand-written code. This will likely require
> some sort of tweaks/annotations atop WebIDL for any React vagaries, hence
> I'm wondering to what extent the WebIDL interface is reusable.
>
> Thanks,
>
>
> Paul
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] email body not showing up

2019-03-21 Thread Martin Tournoij
On Thu, 21 Mar 2019 11:56:21 +0530 pradam  wrote:
> I have implement below code, but body not showing up, so whats wrong
> with the code?
> 
> [..]
>
> _, err = fmt.Fprintf(wc, "This is the email body")
> if err != nil {
> log.Fatal(err)
> }
>
> [..]

You are not sending any header fields; an email should look like:

From: sen...@example.com\r\n
To: r...@example.com\r\n
Date: Thu Mar 21 19:34:02 NZDT 2019
Message-ID: ran...@mail.example.com
Content-Type: txt/plain; charset=utf-8
Subject: Hey there!\r\n
\r\n
The message body\r\n

It's important that you're careful to not allow untrusted user input in the
headers, otherwise someone could inject headers by setting a subject to
something like this:

"spam\r\nCc: vict...@example.com, vict...@exampele.com"

And you'll be spamming all of the internet.

You'll also want to use Transfer-Encoding: quoted-printable
(mime/quotedprintable package).

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


pgpLjoIKyMdIs.pgp
Description: OpenPGP digital signature


[go-nuts] "find" for Slices like "append"

2017-08-07 Thread martin . rode
Being fairly new to Go, I am trying to evaluate if it s possible and worth 
to move our huge C++ codebase over to Go.

1) append(sliceA, my_new_item) sliceA

Why can I not append something to a Slice in place, why does it have to 
return a new Slice?

2) find(sliceB, item_i_look_for) int, -1 for not found

Why can I not find easily search for an item inside a Slice. Every other 
language I know has this. And I need this in a generic form.

Or am I missing something entirely here?

Best
Martin

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] "find" for Slices like "append"

2017-08-07 Thread martin . rode

>
>
> > Why can I not append something to a Slice in place, why does it have to 
> > return a new Slice? 
>
> https://blog.golang.org/slices 
>
> Ok, I will check that, thx.
 

>
> > 2) find(sliceB, item_i_look_for) int, -1 for not found 
> > 
> > Why can I not find easily search for an item inside a Slice. Every other 
> > language I know has this. And I need this in a generic form. 
>
> As you have probably heard, Go does not have generics.  Sorry.  The 
> loop that you need to write is fairly short.


The loop might be short, but I need to know the type of the items in my 
Slice.

So I need a loop for every datatype!? 

And I need to name it for each type differently? 

Why? 

All I want to be able to do is to find an item in a Slice. 

Why does "append" work with all types then?

Martin
 

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] "find" for Slices like "append"

2017-08-07 Thread martin . rode


>
>
> Because it's easy to write a short correct find loop for the type you 
> are using, but a good implementation of append is a much larger 
> function.  See also http://www.airs.com/blog/archives/559 . 
>

So "append" is already done. May I propose to implement a generic "find" 
function?

That should be possible without coming up with good general generics 
support, shouldn't it? 

In my everyday programming life a check if an item is inside an Array is 
very common. Often this
is even built-in syntax (like in Python "if a in array...").

I will have a hard time selling this missing feature to my team.

Martin

>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] "find" for Slices like "append"

2017-08-08 Thread martin . rode
Sort.Search is nice, but then the list has to be sorted. Wasnt there a 
lenghty discussion on how awkward sorting is compared to other languages, 
and then in 1.8. finally someone implemented 

func Slice(slice interface{}, less func(i, j int 
) bool 
)

which already makes it easier to Sort a slice.

So why not come up with

func findFirst(slice interface{}, matches func(i int 
) bool 
)

or so?

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] "find" for Slices like "append"

2017-08-08 Thread martin . rode

>
>
> The Go philosophy is explicitly *not* to give you everything you want.  
> It *is* to give you everything you need to build everything you want, 
> like Lego.
>

Yeah right, when men still where real men and programmed their own device 
drivers...

Or take a car, give me parts & tools and I am ready to give you a ride in 
say a year? 


> Every language is different. Any developer worth their salt won't dismiss 
> a tool out-of-hand for such a trivial reason.
>

No nobody would. But trivial things add up and then people run away or 
never sign up.

I have learnt to never not listen to your (potential) users.

If a new project comes on board of the Go train, people already have to 
wrap their heads around new (admittedly interesting) concepts, they have to 
accept "err != nil" spaghetti, distinction between Array and Slices, make 
and new, and so on.

Personally I got really interested when I died around your standard library 
which I really like and it seems to give us exactly what we need, not too 
much, not too little.

>
> Also, consider the fact that in Python, the same loop is happening. Go 
> just doesn't hide that from the developer, making it easier for us to 
> reason about things like performance. You can write your own "find" 
> function in seconds if you want one.
>

It just looks awkward:

contains := false
for _, n := range excluded_numbers {
  if byte(m) == n {
contains = true
  }
}
if !contains {
   ...

Seriously? 2017?

Martin

 
> -- 
> ☕😎
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] "find" for Slices like "append"

2017-08-09 Thread martin . rode
Volker thanks for the reply. Coming from Python I can do a simple test like

if item in my_array:
   # do something
else:
   # do something else

I can understand that it cannot be that easy in Go (and then, why not, 
"equals" is already defined), but image you
have to use a for-loop every time or a specialized function every time. 
That is awkward and unnecessary.

I agree, that the more complex idea to have a "findFirst" with a dedicated 
matching function
is more complicated, but hey, sort.Slice is the same thing, isn't it? It 
takes a comparison func to return -1, 0, or 1.

func findFirst(slice interface{}, matches func(i int 
) int)

Just my 0.02. 


-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Full Time Job Opportunity at Mattel: Remote inside US OK

2017-08-15 Thread martin . ostrovsky
I'm not interested in the job but just wanted to say this is one of the 
best job postings I've ever read.

On Tuesday, August 15, 2017 at 10:54:22 AM UTC-4, Nate Finch wrote:
>
> Mattel (yes the toy company) is hiring full time Go devs to work on its 
> IoT & identity server platform.  Remote is OK if you're within the US. 
>  Both I and my manager (who would be your manager) are remote.  I'm in 
> Massachusetts, manager is in Ohio.  Another dev in SF.  Office is in San 
> Francisco.
>
> We're a small team inside Mattel that is having a huge impact.  We are 
> currently proving our chops with an API and IoT data processing for one 
> product (the Sproutling baby monitor), but we're already working on 
> expanding our service to be used by divisions across all of Mattel, 
> including Hot Wheels, Barbie, and Fisher Price.  
>
> Sproutling is a startup that was bought by Mattel last year. We've been 
> working on a REST API using gin, and backend that stores data in postgres 
> (currently migrating from GORM to database/sql boilerplate generated by 
> github.com/knq/xo).  We run on AWS using nomad, docker, and terraform, 
> but we're investigating other deployment tools (including kubernetes, but 
> we're not sure it fits our needs / timeline).  We use lots of interesting 
> tech, like MQTT, kafka, cassandra, postgres, traefik, logstash, flink, and 
> prometheus.  Oh yeah, and we write our own go services too, of course :)
>
> We use github for all our code, code review everything, slack for 
> communication, google apps for email, jira for bug tracking and sprint 
> planning - we do a very lightweight kanban/scrum style with two week 
> iterations.  All meetings are done in google hangouts. We meet in person 
> approximately every 6 months.
>
> We're fast paced but low stress.  Flexible hours, good home/work balance 
> (and I say this as a parent of three kids ages 6 and under).  Many of our 
> devs have kids (including the manager of our team), so we totally 
> understand about school plays, doctors appointments, etc.  
>
> It's extremely rare to work late nights or weekends (I've worked exactly 
> one weekend in the last 6 months).  Pay is competitive for San Francisco. 
>  Benefits are great - health insurance is low co-pay, low premium (Anthem 
> Blue Cross if you're remote, not sure if you're in California, I'd have to 
> ask).  401k with match, 4-10% based on age.  1/2 day Fridays.  40% off 
> Mattel toys (including American Girl, Power Wheels, Barbie, Fisher Price, 
> Megabloks etc.  A million other small benefits that come with working for 
> the largest toy company in the world (life insurance, discount services, 
> FSA, etc etc etc)
>
> Looking for experienced backend devs, preferably with a year or more 
> writing Go for backend services, but please don't filter yourself out if 
> you're interested, that's our job :)
>
> Respond here with any questions, or contact me on twitter 
> https://twitter.com/natethefinch.  Email me resumes at 
> na...@sproutling.com . 
>
> -Nate
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] error handling needs syntactical sugar

2017-09-04 Thread martin . rode
Hi guys,

at first I though I really like the idea of how Go deals with error 
management and handling, but the more Go code I look at or try to program, 
the more I get scared about checking errors every second line in every 
given block of code.

Take a look at this example here from "Build Web Application with Golang":

// insert
stmt, err := db.Prepare("INSERT INTO userinfo(username, departname, created) 
values(?,?,?)")
if err != nil {
  // handle error
}
res, err := stmt.Exec("astaxie", "研发部门", "2012-12-09")
if err != nil {
  // handle error
}
id, err := res.LastInsertId()
if err != nil {
  // handle error
}
fmt.Println(id)
// update
stmt, err = db.Prepare("update userinfo set username=? where uid=?")
if err != nil {
  // handle error
}
res, err = stmt.Exec("astaxieupdate", id)
if err != nil {
  // handle error
}
affect, err := res.RowsAffected()
if err != nil {
  // handle error
}


Seriously? And yes, I have read https://blog.golang.org/errors-are-values...

The best case reduction I found is:

...
res, err = stmt.Exec("astaxieupdate", id)
checkError(err)
...

Still, I need this after each line of calling a function which may return 
an error.

I bet this is not pleasant to do in larger code bases and it also takes 
away focus from what is actually happening.

50-80% of all lines of code in my example deal with error handling?

This is not good. Seriously.

And don't get me wrong, there is a lot of things I really like, love and 
adore about Go, but catching errors needs an improved syntax!

And I am not proposing try...catch here. 

How about introducing a new piece of syntax 

"watch if   " 

which tells the compiler to watch out for changes in a given SimpleStmt

The same code as above would look like this:

var err Error

watch if err != nil {
  // handle error(s)
}

// insert
stmt, err := db.Prepare("INSERT INTO userinfo(username, departname, 
created) values(?,?,?)")
res, err := stmt.Exec("astaxie", "研发部门", "2012-12-09")
id, err := res.LastInsertId()
fmt.Println(id)

// update
stmt, err = db.Prepare("update userinfo set username=? where uid=?")
res, err = stmt.Exec("astaxieupdate", id)
affect, err := res.RowsAffected()


   - The "watch if" would be executed after each assignment of any of the 
   variables used in SimpleStmt of the statement.
   - Multiple "watch if" would be executed in order or appearance
   - The "watch if" could be used like "defer..." inside functions
   - The "watch if" would work in its full scope of the watched variables

I am not a language expert, so may be there is a saner way of expression 
what I want to achieve.

But bottom line is, there should by an easier to read and write way to deal 
with errors in Go.


Martin





-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: error handling needs syntactical sugar

2017-09-04 Thread martin . rode

On Monday, September 4, 2017 at 10:48:06 PM UTC+2, Tamás Gulácsi wrote:
>
> Why do you Prepare a statement if you don't reuse it? Just use a db.Exec.

 
Just wanted to show a pattern which I see very often in Go code. Its not a 
working example, and I am not asking for improvements in that code. 

But concretes aside: error handling IS important!
>

Yes it is. But as my example shows, it should not get annoying.
 

> But if such code bothers you, create some helper type / function: see one 
> Andy+Brad pair programming video where they create an errWriter struct 
> which is an io.Writer, and just writes to the underlyin Write. Untill the 
> first error. From then on it always returns the fist error.
>

The problem with ANY error handling solution within the existing Go syntax 
will require one of three things:

   - Wrap the call which you need to check the error for
   - Wrap the check into a function, to save code lines
   - Do some tricks to check the error at the end of a block

Neither one of these methods is satisfying for me. I need to be able to 
produce readable, concise code which does the right thing.


-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] error handling needs syntactical sugar

2017-09-04 Thread martin . rode
Axel, 

thanks for the reply.

As I already replied to Tomas, I am not looking for improvements in this 
particular case where I need to call an SQL database.

An no, I dont want to wrap all function I use into something which collects 
the errors for me.

Let's say you want to log & panic & exit after any error.

How do you do that, without putting code after each statement or wrapping?

You can't. And that's why I am proposing to be a little bit open to new 
ideas.

Every modern language I know of has some sort of try...catch construct.


Martin




On Monday, September 4, 2017 at 10:57:51 PM UTC+2, Axel Wagner wrote:
>
> See, e.g. here 
> <https://groups.google.com/d/topic/golang-nuts/ROr5jveMQvg/discussion> or 
> here 
> <https://groups.google.com/d/topic/golang-nuts/68J-mLCC1JI/discussion> for 
> previous discussions of very similar (even mostly identical) proposals.
>
> What I always dislike about these kinds of proposals is, that they are 
> encouraging not handling errors, but instead just passing them up-stack. In 
> general, all of the sites where you are checking for errors will signify 
> different error conditions, that should be communicated differently 
> upstream. For example:
>
> db.Prepare("INSERT INTO userinfo(username, departname, created) 
> values(?,?,?)")
> -> This could fail for basically two reasons: Either communication with 
> your database somehow failed (e.g. a broken network connection), in which 
> case you want to return the equivalent of an HTTP 503 error, or the syntax 
> of your statement is wrong, in which case I'd argue panic'ing would be the 
> correct thing - at the very least, returning the equivalent of a 500.
>
> stmt.Exec("astaxie", "研发部门", "2012-12-09")
> -> Either a 503. Or 400, 403, 409…
>
> res.LastInsertId()
> -> 500 or 501?
>
> The issue is, that by simply checking for nil and passing it along, you 
> are *not handling your error*. Different error conditions require different 
> error handling and what the correct error handling is, depends heavily on 
> the application. An ENODIR error in one line of code can signify a totally 
> different error condition than the same error two lines later. So all of 
> these proposals are born out of an exception-style idea of how error 
> handling is supposed to work; deep within the call stack something goes 
> wrong and that something is then just bubbled up to be someone else's 
> problem. Good error handling just can't be well abbreviated in this way - 
> at least not generically. It's too application-specific for that.
>
> On Mon, Sep 4, 2017 at 8:27 PM, > 
> wrote:
>
>> Seriously? And yes, I have read 
>> https://blog.golang.org/errors-are-values...
>>
>> The best case reduction I found is:
>>
>> ...
>> res, err = stmt.Exec("astaxieupdate", id)
>> checkError(err)
>> ...
>>
>> Still, I need this after each line of calling a function which may return 
>> an error.
>>
>
> A better take-away from that blog post would have been, to orient yourself 
> around the example of a writer given. You could, for example, provide a 
> one-time abstraction that wraps *sql.DB and collects the error. I'd agree 
> that the sql package tends to not be amazing for that, because of its set 
> of interdependent types, it is still possible. For example, with this 
> <https://play.golang.org/p/kdgBUqWeR->, you could write
>
> d := &errDB{db: d}
> stmt := d.Prepare("INSERT INTO…")
> res := stmt.Exec(…)
> id := res.LastInsertId()
> stmt := d.Prepare("UPDATE…")
> res := stmt.Exec(…, id)
> affect := res.RowsAffected()
> return d.err
>
> Now… this isn't really nice either (see above. sql isn't really 
> well-designed for this. You'd probably try and implement a driver for this, 
> but sql doesn't make that easy either). And it's a bad idea for all the 
> same reasons the watch-proposal isn't a great idea here. But it illustrates 
> a far more effective take-away from that blog post.
>  
>
>>
>> I bet this is not pleasant to do in larger code bases and it also takes 
>> away focus from what is actually happening.
>>
>> 50-80% of all lines of code in my example deal with error handling?
>>
>> This is not good. Seriously.
>>
>> And don't get me wrong, there is a lot of things I really like, love and 
>> adore about Go, but catching errors needs an improved syntax!
>>
>> And I am not proposing try...catch here. 
>>
>> How about introducing a new piece of syntax 
>>
>> "watch if   

[go-nuts] Re: error handling needs syntactical sugar

2017-09-04 Thread martin . rode
Hi Dorival,

thanks for supporting me with my idea.

And yes, after writing my post yesterday I was thinking, "watchif" or even 
simply "watch".

And yes, today I am more in favor of simply *"watch"*.

And yes, we can constrain this to the context of one function (like defer), 
I am ok with that. 

What you are describing how you work with errors and how you spent hours 
adding 

*if err != nil*

that is *exactly* my point.

On could nicely write this

...
watch err!=nil {
  handle_sql_error(err)
}
...

Of course, watch could also be used to not watch out for errors but any 
other places where new values to get assigned to variables.

Martin

>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] error handling needs syntactical sugar

2017-09-05 Thread martin . rode

>
>
> You don't. But it's a bad idea. And "I want to make writing bad code 
> easier" isn't a very convincing argument for a language-change.
>

Ok, than I want to

   - Make it easier to read and follow
   - Make it possible to handle errors in one place instead of 10

I see you point, and yes, I am also against bubbling errors all the way to 
the top and let it end in "an unknown error occurred", don't get me wrong!

BUT my point is, what do I do with 10 or more sql statements, when it 
doesn't really matter which one fails why?

Some libraries only return error and an explanation as a String (e.g. 
Postgres), so you don't really have a choice but return anyway.
 

>
> You can't. And that's why I am proposing to be a little bit open to new 
>> ideas.
>>
>
> And how open are you to the idea that good error handling isn't about 
> writing the least amount of code or bubbling up an error in the most 
> efficient way, but about *handling errors*? Because you haven't really 
> replied to that part.
>

I hope my sentence above explains that. Another idea would be: Look at 
common go code and see how often people just check for err != nil 10 times 
in a single function, calling always the SAME error handler. In programming 
you sometimes simply want to get things done and if it is really not 
important where exactly an error occurred, a construct like my `watch` 
comes in handy.

 

>
> (and FTR, one of the points I was making is, that this isn't a new idea. 
> It's proposed fairly frequently)
>  
>
>> Every modern language I know of has some sort of try...catch construct.
>>
>
> Go is modern and doesn't have it. So this seems cherry-picked.
>

Well, I am not saying Go needs it to, I am saying there is a demand for 
error handling of some sort.

C had nothing besides returning -MYERRORCONST, Go can return errors more 
explicitly, but in its current state it is not saving me much in terms of 
lines of code compared to C nor does it help with readability.

And, I have another argument against your "I want people to deal with their 
errors". You cannot force people into too much. That's why you see SOOO 
much Go code which simply copy & pastes long long chains of "if err != nil" 
statements.

Martin

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] error handling needs syntactical sugar

2017-09-05 Thread martin . rode
Dorival,

thanks for counting your error calls, but without any other number showing 
the size of your project they cannot really put in perspective ;-)

And I think *watch* should not only be function bound, but bound to the 
current scope, same as *var*.

Martin


On Tuesday, September 5, 2017 at 9:20:10 AM UTC+2, Dorival Pedroso wrote:
>
> And I've written 231 error messages (I use a function called chk.Err() to 
> do so):
> find . -iname "*.go" -exec grep -inH "chk.Err" {} \; | wc -l
> 231
>
> See the messages here: 
> https://gist.github.com/cpmech/d2e36dcbe277cd72605f3732d79c798b 
>
> And I have a feeling that I've done only 20% of the error messages... 
> (lots of work still needed...)
>
>
> On Tuesday, September 5, 2017 at 5:15:16 PM UTC+10, Dorival Pedroso wrote:
>>
>> I'm working on a Go project right now and I realised I've written 569 "if 
>> err != nil":
>> find . -iname "*.go" -exec grep -inH "if err != nil" {} \; | wc -l
>> 569
>>
>>
>> On Tuesday, September 5, 2017 at 4:57:45 PM UTC+10, Axel Wagner wrote:
>>>
>>>
>>>
>>> On Tue, Sep 5, 2017 at 8:49 AM,  wrote:
>>>
>>>> Axel, 
>>>>
>>>> thanks for the reply.
>>>>
>>>> As I already replied to Tomas, I am not looking for improvements in 
>>>> this particular case where I need to call an SQL database.
>>>>
>>>> An no, I dont want to wrap all function I use into something which 
>>>> collects the errors for me.
>>>>
>>>> Let's say you want to log & panic & exit after any error.
>>>>
>>>> How do you do that, without putting code after each statement or 
>>>> wrapping?
>>>>
>>>
>>> You don't. But it's a bad idea. And "I want to make writing bad code 
>>> easier" isn't a very convincing argument for a language-change.
>>>
>>> You can't. And that's why I am proposing to be a little bit open to new 
>>>> ideas.
>>>>
>>>
>>> And how open are you to the idea that good error handling isn't about 
>>> writing the least amount of code or bubbling up an error in the most 
>>> efficient way, but about *handling errors*? Because you haven't really 
>>> replied to that part.
>>>
>>> (and FTR, one of the points I was making is, that this isn't a new idea. 
>>> It's proposed fairly frequently)
>>>  
>>>
>>>> Every modern language I know of has some sort of try...catch construct.
>>>>
>>>
>>> Go is modern and doesn't have it. So this seems cherry-picked.
>>>  
>>>
>>>>
>>>>
>>>> Martin
>>>>
>>>>
>>>>
>>>>
>>>> On Monday, September 4, 2017 at 10:57:51 PM UTC+2, Axel Wagner wrote:
>>>>>
>>>>> See, e.g. here 
>>>>> <https://groups.google.com/d/topic/golang-nuts/ROr5jveMQvg/discussion> or 
>>>>> here 
>>>>> <https://groups.google.com/d/topic/golang-nuts/68J-mLCC1JI/discussion> 
>>>>> for 
>>>>> previous discussions of very similar (even mostly identical) proposals.
>>>>>
>>>>> What I always dislike about these kinds of proposals is, that they are 
>>>>> encouraging not handling errors, but instead just passing them up-stack. 
>>>>> In 
>>>>> general, all of the sites where you are checking for errors will signify 
>>>>> different error conditions, that should be communicated differently 
>>>>> upstream. For example:
>>>>>
>>>>> db.Prepare("INSERT INTO userinfo(username, departname, created) 
>>>>> values(?,?,?)")
>>>>> -> This could fail for basically two reasons: Either communication 
>>>>> with your database somehow failed (e.g. a broken network connection), in 
>>>>> which case you want to return the equivalent of an HTTP 503 error, or the 
>>>>> syntax of your statement is wrong, in which case I'd argue panic'ing 
>>>>> would 
>>>>> be the correct thing - at the very least, returning the equivalent of a 
>>>>> 500.
>>>>>
>>>>> stmt.Exec("astaxie", "研发部门", "2012-12-09")
>>>>> -> Either a 503. Or 400, 403, 409…
>>>>>
>>

[go-nuts] Re: error handling needs syntactical sugar

2017-09-05 Thread martin . rode
Dorival,

I think we can celebrate already if we achieve anything with this 
discussion. Let's not ask for too much, plus let's not make it too 
complicated.

I think your proposed "watch err", hides too much and does too little.

You can simply write (the inline code editor is broken, BTW)

func ... {
var err
watch err != nil {
// handle error
return
}
// do stuff
yo1, err := do_stuff1()
yo2, err := do_stuff2()
yo3, err := do_stuff3()
}


Martin


On Tuesday, September 5, 2017 at 9:32:50 AM UTC+2, Dorival Pedroso wrote:
>
> Hi Martin;
>
> What about two commands "*watch*" and "*watchif*"?
>
> The first works as the "*var*" command and the second as the "*if*" 
> command.
>
> "*watch*" does:
>
>1. In a function with *error* as an output (anywhere): returns in case 
>the *err* declared with *watch err* (or *watch myerror*) becomes 
>non-nil. *watch err* would declare *err*" as *var* does. Most use 
>cases would put *watch err* at the beginning of a function (although 
>this is optional as it is with *defer*)
>2. In a test function; aka TestSomething(something *testing.T), *watch 
>err error* would declare *err* (or *watch myerror error*) and if an 
>error occurs, it would call something.FailNow() after (printing the error 
>message?---still need to think this part better)
>3. In the main function: *watch err error* would print the error 
>message (or maybe pipe to stderr) and os.Exist(1)
>4. *watchif err != nil {HERE}* would be more powerful because it would 
>allow us to do other things. But the mechanism is similar (as you proposed 
>initially): if *err* becomes non-nil anywhere, the execution in *HERE* 
>would take place.
>
> Cheers!
>
>
> On Tuesday, September 5, 2017 at 4:55:59 PM UTC+10, 
> marti...@programmfabrik.de wrote:
>>
>> Hi Dorival,
>>
>> thanks for supporting me with my idea.
>>
>> And yes, after writing my post yesterday I was thinking, "watchif" or 
>> even simply "watch".
>>
>> And yes, today I am more in favor of simply *"watch"*.
>>
>> And yes, we can constrain this to the context of one function (like 
>> defer), I am ok with that. 
>>
>> What you are describing how you work with errors and how you spent hours 
>> adding 
>>
>> *if err != nil*
>>
>> that is *exactly* my point.
>>
>> On could nicely write this
>>
>> ...
>> watch err!=nil {
>>   handle_sql_error(err)
>> }
>> ...
>>
>> Of course, watch could also be used to not watch out for errors but any 
>> other places where new values to get assigned to variables.
>>
>> Martin
>>
>>>
>>>>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: error handling needs syntactical sugar

2017-09-07 Thread martin . rode
On Tuesday, September 5, 2017 at 10:39:05 AM UTC+2, Rob 'Commander' Pike 
wrote:
>
> If you find that lines like if err != nil are a significant fraction 
> of non-test code, your code probably needs a better error handling 
> strategy, not a language change. I have done measurements in the past 
> and although people complain a lot about the presence of that 
> statement, it shows up much less often in practice than people claim, 
> and when it does appear a lot it's usually because the programmer is 
> not thinking enough about how errors should work. 
>

Well, I can try to find more examples, but whenever you interact with say 
SQL or other libraries, errors can occur at each call into that library.

Very often it is enough to check the errors for one block (think try... 
catch)

The problem with all suggested solutions so far is, that it requires 
wrapping function calls of some sort.

Personally, I don't like this. There are calls (say to interact with an SQL 
library), and once you start wrapping them in order for an improved error 
management, the solution is very local and personal and less readable.

This does not support Go's idea of producing readable code across 
developers and styles.

After all the responses in this thread, I thought about my proposal a 
little more carefully, so how about this, and it is a construct which can 
be used not only for errors:


watch err != nil {
yo1, err = do_stuff1()
yo2, err = do_stuff2()
yo3, err = do_stuff3()
} then {
// handle your error
}

This statement could be used for other cases as well, it is easy to read 
and understand, and it saves the programmer from line duplication.

Martin

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] SIGILL: illegal instruction when making cgo call

2017-11-01 Thread martin . ostrovsky
Hello,

Encountered this issue running a statically compiled binary that uses cgo 
(Compiled using go1.8.3). It works OK on one CPU type but not on another. 
The binary is built on a server which is neither of the two below. Is this 
a Go issue or something to do with how the C library is built (gcc version 
mismatch, compiler flags etc.)?  

SIGILL: illegal instruction
PC=0x1283c22 m=0 sigcode=2
signal arrived during cgo execution
goroutine 1 [syscall, locked to thread]:
runtime.cgocall(0x11a2c80, 0xc4219e9c70, 0x4e7e960)
/usr/local/go/src/runtime/cgocall.go:131 +0xe2 fp=0xc4219e9c30 
sp=0xc4219e9bf0
xxx-wv._Cfunc_d2v_init(0x4e7e9a0, 0x4e7e9d0, 0xc, 0x4e7e960, 0x0, 0x0)
/tmp/go-build684597318/xxx-wv/_obj/_cgo_gotypes.go:137 +0x4e 
fp=0xc4219e9c70 sp=0xc4219e9c30
xxx-wv.NewFromFile(0xc430df8fc0, 0x26, 0xc430df9170, 0x26, 0x101, 0x0, 0x0, 
0x0, 0x0, 0x10005, ...)
/home/ubuntu/go/src/xxx-wv/wv.go:100 +0xe5 fp=0xc4219e9cf0 sp=0xc4219e9c70
xxx-ent.init.1()
/home/ubuntu/go/src/xxx-ent/ent.go:132 +0x425 fp=0xc4219e9ef0 
sp=0xc4219e9cf0
xxx-ent.init()
/home/ubuntu/go/src/xxx-ent/util.go:109 +0x2cc fp=0xc4219e9f68 
sp=0xc4219e9ef0
xxx-api.init()
/home/ubuntu/go/src/xxx-api/s.go:203 +0x89 fp=0xc4219e9f78 sp=0xc4219e9f68
main.init()
/home/ubuntu/go/src/xxx.go:122 +0x8e fp=0xc4219e9f88 sp=0xc4219e9f78
runtime.main()
/usr/local/go/src/runtime/proc.go:173 +0x1ca fp=0xc4219e9fe0 sp=0xc4219e9f88
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:2197 +0x1 fp=0xc4219e9fe8 
sp=0xc4219e9fe0
goroutine 17 [syscall, locked to thread]:
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:2197 +0x1
goroutine 20 [syscall]:
os/signal.signal_recv(0x0)
/usr/local/go/src/runtime/sigqueue.go:116 +0x104
os/signal.loop()
/usr/local/go/src/os/signal/signal_unix.go:22 +0x22
created by os/signal.init.1
/usr/local/go/src/os/signal/signal_unix.go:28 +0x41
rax0x4e7f130
rbx0x7fff1a258190
rcx0x7fff1a257e18
rdx0x0 
rdi0x7fff1a257e20
rsi0x1283e2a
rbp0x7fff1a2581b8
rsp0x7fff1a257e20
r8 0x1283e2a
r9 0x7fff1a257a50
r100x301fdb0
r110x1283e2a
r120x4e7f130
r130x4e7f150
r140x7fff1a257e50
r150x7fff1a257fe0
rip0x1283c22
rflags 0x10206
cs 0x33
fs 0x0 
gs 0x0 


Architecture for the server that doesn't work:

processor: 7
vendor_id: GenuineIntel
cpu family: 6
model: 44
model name: Intel(R) Xeon(R) CPU   X5680  @ 3.33GHz
stepping: 2
microcode: 0x15
cpu MHz: 3325.000
cache size: 12288 KB
physical id: 1
siblings: 4
core id: 3
cpu cores: 4
apicid: 7
initial apicid: 7
fpu: yes
fpu_exception: yes
cpuid level: 11
wp: yes
flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca 
cmov pat pse36 clflush dts mmx fxsr sse sse2 ss ht syscall nx rdtscp lm 
constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc 
aperfmperf pni pclmulqdq ssse3 cx16 sse4_1 sse4_2 x2apic popcnt aes 
hypervisor lahf_lm ida arat dtherm
bogomips: 6650.00
clflush size: 64
cache_alignment: 64
address sizes: 40 bits physical, 48 bits virtual
power management:

The same binary works properly on a server with this architecture:

processor: 7
vendor_id: GenuineIntel
cpu family: 6
model: 45
model name: Intel(R) Xeon(R) CPU E5-2690 0 @ 2.90GHz
stepping: 7
microcode: 0x70d
cpu MHz: 2900.000
cache size: 20480 KB
physical id: 1
siblings: 4
core id: 3
cpu cores: 4
apicid: 7
initial apicid: 7
fpu: yes
fpu_exception: yes
cpuid level: 13
wp: yes
flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca 
cmov pat pse36 clflush dts mmx fxsr sse sse2 ss ht syscall nx rdtscp lm 
constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc 
aperfmperf pni pclmulqdq ssse3 cx16 pcid sse4_1 sse4_2 x2apic popcnt 
tsc_deadline_timer aes xsave avx hypervisor lahf_lm ida arat pln pts dtherm
bogomips: 5800.00
clflush size: 64
cache_alignment: 64
address sizes: 42 bits physical, 48 bits virtual
power management:

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Random panic in production with Sprintf

2019-05-02 Thread Anthony Martin
What version of Go are you using?

XXX ZZZ  once said:
> fmt.(*pp).fmtString(0xc023c17740, 0x0, 0x5, 0xc00076)
> /usr/local/go/src/fmt/print.go:448 +0x132
> fmt.(*pp).printArg(0xc023c17740, 0x9978e0, 0xc016a68a30, 0x76)
> /usr/local/go/src/fmt/print.go:684 +0x880
> fmt.(*pp).doPrintf(0xc023c17740, 0xa6e22f, 0x5, 0xc048c27818, 0x1, 0x1)
> /usr/local/go/src/fmt/print.go:1112 +0x3ff
> fmt.Sprintf(0xa6e22f, 0x5, 0xc048c27818, 0x1, 0x1, 0x80, 0xa36200)
> /usr/local/go/src/fmt/print.go:214 +0x66

This shows signs of memory corruption. The last argument passed to
fmtString (0xc00076) should be the same as the last argument
passed to printArg (0x76 or 'v') but it has some high bits set. Also,
the pointer to the format string data changes from 0xa6e22f (which is
probably in the .rodata section of the binary) to 0x0.

Something is amiss.

  Anthony

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Random panic in production with Sprintf

2019-05-02 Thread Anthony Martin
Ian Lance Taylor  once said:
> I don't *think* the format string is changing.  I think the 0 is from
> the string being printed, not the format string.  They both happen to
> be length 5.

Misled by the pair of fives. Mea culpa.

  Anthony

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Interesting public commentary on Go...

2019-05-23 Thread Anthony Martin
Sam Whited  once said:
> This is especially a problem when these proposals further tie Go to
> Google web services run by the Go team (though I'm veering off into a
> separate problem here). To me this feels like it's almost a type of
> vertical integration and it's an absolutely disgusting thing to do, and
> I don't use that word lightly. Not because I think the Go team is
> planning on doing anything bad with the information all Go users will
> now be sending to them, or because I think Google executives are putting
> down mandates and influencing Go, but because we don't know what future
> Go team members or Google execs will do. We don't know who will be
> running the Go project in 10 or 20 years, so the Go team now should be
> making sure they limit the potential for abuse, especially when they
> work for a company with a long history of anti- competitive behavior and
> abuse of its size and power.

How do you square this opinion with the fact that the Go team
went out of their way to enable the use of third-party module
proxies, something that is good for the community but would be
of little practical use to Google?

  Anthony

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/20190523222743.GA28121%40alice.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go 2 generics counterproposal: giving up restricting types

2019-06-03 Thread Martin Schnabel

Hi,

is my impression correct, that this proposal adds types as values to the 
language? It's seems like it does the section 'Unnamed generic 
arguments'. That by itself would go a long way and warrants some 
discussion, I'd say.


If so, then why use a new keyword 'gen'? Why not 'type' itself.
It would have some symmetry with how the func and struct keywords are
used for closures and unnamed structs. The 'type' keyword has no
possible meaning in the parameter list currently.

I use the 'gen' keyword a lot as identifier, mostly for generators
and generated code. While nobody can claim to use 'type'. This would
make converting code so much easier, if this proposal is accepted.

Just a though. Please tell me whether this would be possible.

Thanks for your work, it's much appreciated.
  Martin


On 30.05.19 14:08, Michal Strba wrote:

Hi Gophers! :)

I've been thinking about generics in Go 2 ever since the original 
contracts proposal and few days ago, ideas finally clicked. One of the 
main things about this proposal is that it deliberately omits the 
ability to restrict the set of types a function can work with. This is a 
limitation, but I hope to convince you that we can still do a vast 
majority of the things we were missing, when we were missing generics.


I'd love to share my proposal with you and engage in a good faith 
conversation.


Link to the proposal. 
<https://gist.github.com/faiface/e5f035f46e88e96231c670abf8cab63f>


Here's what the proposal covers:

1. Syntax of a new gen keyword.
2. Generic functions.
3. Unnamed generic arguments (a.k.a. a way to gve a type to the built-in 
newfunction).

4. Semantics of generic values (ability to use them as map keys, ...).
5. Generic array lengths.
6. Reflection and interface{}.
7. Generic types (with two examples: Listand Matrix).
8. Generic methods and their limitations due to reflection.
9. Generic interfaces.
10. List of things this proposal can't do.

Thanks,
faiface

--
You received this message because you are subscribed to the Google 
Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to golang-nuts+unsubscr...@googlegroups.com 
<mailto:golang-nuts+unsubscr...@googlegroups.com>.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/6f5f0785-93f7-475a-991c-fc919c5e6730%40googlegroups.com 
<https://groups.google.com/d/msgid/golang-nuts/6f5f0785-93f7-475a-991c-fc919c5e6730%40googlegroups.com?utm_medium=email&utm_source=footer>.

For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/739d147e-162d-14fc-a13a-9e7962f074e2%40mb0.org.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go 2 generics counterproposal: giving up restricting types

2019-06-03 Thread Martin Schnabel

Hi Michal,

I would argue that the 'const' keyword would by more correct. Because 
the array length is and needs to be constant anyway. And it has 
currently no valid meaning in a parameter list, just like with
the 'type' keyword. However i would argue that the array length, if 
written as part of the array syntax, as in '[n]elem' does not need an 
explicit keyword qualifier, because - again - it's unambiguous in the 
parameter context. Would you agree?


Best regards
  Martin

On 03.06.19 14:20, Michal Strba wrote:

Hi Martin.

The proposal adds types as "values", but not really. You can only accept 
a type to a function, but you cannot return a type. That makes the 
system far from a dependent type system, even with the support for 
generic array lengths.


Being able to return types from functions and use those functions in 
types is what brings all the power (and complexity) of dependent typing, 
but what I proposed is just a simple system for explicit type anotation 
directly in the function signature.


Regarding the 'gen' keyword, I chose it because I propose not only 
generic types, but also generic array lengths. But you are right that 
using 'type' would probably be better. Do you think that using the 
'type' keyword also in the context of generic array lengths would be fine?


On Mon, Jun 3, 2019, 12:53 Martin Schnabel <mailto:m...@mb0.org>> wrote:


Hi,

is my impression correct, that this proposal adds types as values to
the
language? It's seems like it does the section 'Unnamed generic
arguments'. That by itself would go a long way and warrants some
discussion, I'd say.

If so, then why use a new keyword 'gen'? Why not 'type' itself.
It would have some symmetry with how the func and struct keywords are
used for closures and unnamed structs. The 'type' keyword has no
possible meaning in the parameter list currently.

I use the 'gen' keyword a lot as identifier, mostly for generators
and generated code. While nobody can claim to use 'type'. This would
make converting code so much easier, if this proposal is accepted.

Just a though. Please tell me whether this would be possible.

Thanks for your work, it's much appreciated.
    Martin


On 30.05.19 14:08, Michal Strba wrote:
 > Hi Gophers! :)
 >
 > I've been thinking about generics in Go 2 ever since the original
 > contracts proposal and few days ago, ideas finally clicked. One
of the
 > main things about this proposal is that it deliberately omits the
 > ability to restrict the set of types a function can work with.
This is a
 > limitation, but I hope to convince you that we can still do a vast
 > majority of the things we were missing, when we were missing
generics.
 >
 > I'd love to share my proposal with you and engage in a good faith
 > conversation.
 >
 > Link to the proposal.
 > <https://gist.github.com/faiface/e5f035f46e88e96231c670abf8cab63f>
 >
 > Here's what the proposal covers:
 >
 > 1. Syntax of a new gen keyword.
 > 2. Generic functions.
 > 3. Unnamed generic arguments (a.k.a. a way to gve a type to the
built-in
 > newfunction).
 > 4. Semantics of generic values (ability to use them as map keys,
...).
 > 5. Generic array lengths.
 > 6. Reflection and interface{}.
 > 7. Generic types (with two examples: Listand Matrix).
 > 8. Generic methods and their limitations due to reflection.
 > 9. Generic interfaces.
 > 10. List of things this proposal can't do.
 >
 > Thanks,
 > faiface
 >
 > --
 > You received this message because you are subscribed to the Google
 > Groups "golang-nuts" group.
 > To unsubscribe from this group and stop receiving emails from it,
send
 > an email to golang-nuts+unsubscr...@googlegroups.com
<mailto:golang-nuts%2bunsubscr...@googlegroups.com>
 > <mailto:golang-nuts+unsubscr...@googlegroups.com
<mailto:golang-nuts%2bunsubscr...@googlegroups.com>>.
 > To view this discussion on the web visit
 >

https://groups.google.com/d/msgid/golang-nuts/6f5f0785-93f7-475a-991c-fc919c5e6730%40googlegroups.com

 >

<https://groups.google.com/d/msgid/golang-nuts/6f5f0785-93f7-475a-991c-fc919c5e6730%40googlegroups.com?utm_medium=email&utm_source=footer>.
 > For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google

Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it,
s

Re: [go-nuts] Go 2 generics counterproposal: giving up restricting types

2019-06-03 Thread Martin Schnabel
I agree. That is a good point. I consider arrays an edge case. Although 
still important, it will probably not be all too common. So the extra 
verbosity should not be a problem.


I am happy you generally agree and think these minor tweaks can make a 
big difference for the roll-out of the proposed feature, if accepted.


I also think, that this is one of the better proposals. It at least
feels more like go, syntax-wise, than most, except for the num part, 
which seems like an afterthought.


Again thank you for your work exploring this!

Best regards
  Marin

On 03.06.19 15:49, Michal Strba wrote:
'const' could be fine too. I guess this is mostly a matter of personal 
preference.


Regarding the array length syntax. It does require qualifying for two 
reasons:


1. Unnamed arguments.
2. Using 'gen' (or 'type', 'const') makes it easy to say "gen is not 
allowed in the return types", which is an important rule. Without 
qualification, this rule would be hard to express.


On Mon, Jun 3, 2019, 15:26 Martin Schnabel <mailto:m...@mb0.org>> wrote:


Hi Michal,

I would argue that the 'const' keyword would by more correct. Because
the array length is and needs to be constant anyway. And it has
currently no valid meaning in a parameter list, just like with
the 'type' keyword. However i would argue that the array length, if
written as part of the array syntax, as in '[n]elem' does not need an
explicit keyword qualifier, because - again - it's unambiguous in the
parameter context. Would you agree?

Best regards
    Martin

On 03.06.19 14:20, Michal Strba wrote:
 > Hi Martin.
 >
 > The proposal adds types as "values", but not really. You can only
accept
 > a type to a function, but you cannot return a type. That makes the
 > system far from a dependent type system, even with the support for
 > generic array lengths.
 >
 > Being able to return types from functions and use those functions in
 > types is what brings all the power (and complexity) of dependent
typing,
 > but what I proposed is just a simple system for explicit type
anotation
 > directly in the function signature.
 >
 > Regarding the 'gen' keyword, I chose it because I propose not only
 > generic types, but also generic array lengths. But you are right
that
 > using 'type' would probably be better. Do you think that using the
 > 'type' keyword also in the context of generic array lengths would
be fine?
 >
 > On Mon, Jun 3, 2019, 12:53 Martin Schnabel mailto:m...@mb0.org>
 > <mailto:m...@mb0.org <mailto:m...@mb0.org>>> wrote:
 >
 >     Hi,
 >
 >     is my impression correct, that this proposal adds types as
values to
 >     the
 >     language? It's seems like it does the section 'Unnamed generic
 >     arguments'. That by itself would go a long way and warrants some
 >     discussion, I'd say.
 >
 >     If so, then why use a new keyword 'gen'? Why not 'type' itself.
 >     It would have some symmetry with how the func and struct
keywords are
 >     used for closures and unnamed structs. The 'type' keyword has no
 >     possible meaning in the parameter list currently.
 >
 >     I use the 'gen' keyword a lot as identifier, mostly for
generators
 >     and generated code. While nobody can claim to use 'type'.
This would
 >     make converting code so much easier, if this proposal is
accepted.
 >
 >     Just a though. Please tell me whether this would be possible.
 >
 >     Thanks for your work, it's much appreciated.
 >         Martin
 >
 >
 >     On 30.05.19 14:08, Michal Strba wrote:
 >      > Hi Gophers! :)
 >      >
 >      > I've been thinking about generics in Go 2 ever since the
original
 >      > contracts proposal and few days ago, ideas finally
clicked. One
 >     of the
 >      > main things about this proposal is that it deliberately
omits the
 >      > ability to restrict the set of types a function can work with.
 >     This is a
 >      > limitation, but I hope to convince you that we can still
do a vast
 >      > majority of the things we were missing, when we were missing
 >     generics.
 >      >
 >      > I'd love to share my proposal with you and engage in a
good faith
 >      > conversation.
 >      >
 >      > Link to the proposa

Re: [go-nuts] Parsing time zone +07:00

2019-07-02 Thread Martin Schnabel

the format time uses a minus sign '-' instead of a plus

https://play.golang.org/p/pXDXm0KmwTz

have fun!

On 02.07.19 20:11, 'Константин Иванов' via golang-nuts wrote:


https://play.golang.org/p/4Rr2xVGKnQg


|
packagemain

import(
"fmt"
"time"
)

constin="+03:00"// "2019-07-02T19:28:39.403+03:00"

constTIME ="+07:00"// "2006-01-02T15:04:05.999+07:00"

func main(){
     fmt.Println(time.Parse(TIME,in))
}
|


Got << parsing time "+03:00" as "+07:00": cannot parse "3:00" as "+07:00" >>

Godoc says:

Numeric time zone offsets format as follows:

-0700  ±hhmm
-07:00 ±hh:mm
-07±hh

Am I doind something wrong or it is bug?

--
You received this message because you are subscribed to the Google 
Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to golang-nuts+unsubscr...@googlegroups.com 
.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/5c6cdaa3-b549-4583-aa19-d4231605953e%40googlegroups.com 
.

For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/001734e0-8b48-6a89-9a04-4ec46b782e80%40mb0.org.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Citation Needed

2019-07-08 Thread Martin Schnabel




On 06.07.19 08:50, go je wrote:

Is the Category "Games" gaining attention in the go community?
Are the Developers writing for production level?
Do we have an examples?
image.png

I would guess, that most of respondents using go for game development, 
use it on the server side. Think multi-, browser- or mobile-games.


Have fun!

--
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/935eda32-0317-b643-e07e-ab941f60255d%40mb0.org.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Does invoking a method with an interface variable avoid dependency analysis?

2019-07-08 Thread Martin Schnabel




On 08.07.19 02:51, Il-seob Bae wrote:

As per the spec ,

A reference to a method m is a method value or method expression of
the form t.m, where the (static) type of t is not an interface type,
and the method m is in the method set of t. It is immaterial whether
the resulting function value t.m is invoked.


In other words, the mere presence of an interface variable guarantees 
/no/ dependency analysis? Here, I did a test 
, but it indeed suffers the 
analysis. Any thoughts?




The key part is that i has dependencies and is not ready and d has no
dependencies and is ready for initialization. If you change the
initialization expression of d from a constant to a function you see
initialization in source order.

https://play.golang.org/p/0D8Lxw_KBz-

--
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/455d59c2-5e22-5071-717e-8b12b3c0b110%40mb0.org.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Does invoking a method with an interface variable avoid dependency analysis?

2019-07-08 Thread Martin Schnabel

sorry. i misunderstood your question. the paragraph you quoted refers to
reference to methods values (t.m) or expressions (T.m) and not method
calls t.m() as in your example. does that help solve the question?

On 08.07.19 20:09, Martin Schnabel wrote:



On 08.07.19 02:51, Il-seob Bae wrote:

As per the spec <https://golang.org/ref/spec#Package_initialization>,

    A reference to a method m is a method value or method expression of
    the form t.m, where the (static) type of t is not an interface type,
    and the method m is in the method set of t. It is immaterial whether
    the resulting function value t.m is invoked.


In other words, the mere presence of an interface variable guarantees 
/no/ dependency analysis? Here, I did a test 
<https://play.golang.org/p/8Fo4nUgGLBP>, but it indeed suffers the 
analysis. Any thoughts?




The key part is that i has dependencies and is not ready and d has no
dependencies and is ready for initialization. If you change the
initialization expression of d from a constant to a function you see
initialization in source order.

https://play.golang.org/p/0D8Lxw_KBz-



--
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/0f2e0bf3-d156-8507-155c-620f41342ede%40mb0.org.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] get interface and method name

2019-07-12 Thread Martin Schnabel

Because AccountService.Create is a method expression you can get to the
interface type by inspecting its first argument. Then you could check
the interface type for all methods and compare the input and output
parameters. This however is brittle and only works if you can guarantee
that there is no other method in the interface with the same parameter
lists.

So i would think using the runtime package is the only and therefor
best option for what you are asking.

Have fun!


On 12.07.19 11:06, Vasiliy Tolstov wrote:

чт, 11 июл. 2019 г. в 00:27, Ian Lance Taylor :


On Wed, Jul 10, 2019 at 1:40 PM Vasiliy Tolstov  wrote:


Hi! i have interface like

type AccountService interface {
   Create(context.Context) error
}

if i need to get string representation of this interface from passed
AccountService.Create how can i do that?

Now i create POC like this:
parts := 
strings.Split(runtime.FuncForPC(reflect.ValueOf(iface).Pointer()).Name(),
".")
return parts[len(parts)-2] + "." + parts[len(parts)-1]

it returns string "AccountService.Create"
Does it possible to get this not using runtime? only via reflect and
may be without strings ?


Can you show us a working example in the Go playground to demonstrated
what you are looking for?

If your interface is named AccountService, I would not expect any
method to be named AccountService.Create.  The Create method will be
defined on other types converted to the interface type, not on the
interface type itself.  So I'm not sure what you are actually looking
for.

Ian


https://play.golang.org/p/VZhO4KdKk-J
I need to return textual representation of interface name and method name.



--
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/1dbff307-443d-826c-8ecb-339107f7e573%40mb0.org.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Get struct type , save and reconstruct empty struct later

2019-07-20 Thread Martin Schnabel

If you only need any unnamed struct type you can create one with reflect
from the field information that you can write to text somewhere.

https://godoc.org/reflect#StructOf

These unnamed struct types however do not have any methods and do not
wrap embedded named type methods.

Otherwise you probably want to register your struct types on program
initialization; for later lookup and so that they are part of the
compiled binary. The gob package does it like that for example.

Have fun!


On 20.07.19 10:44, Vasiliy Tolstov wrote:
Thanks, something like this, but i need to store type in string or 
[]byte in db, and based on this create new empty struct.


сб, 20 июл. 2019 г., 10:55 Jan Mercl <0xj...@gmail.com 
>:


On Sat, Jul 20, 2019 at 9:28 AM Vasiliy Tolstov mailto:v.tols...@selfip.ru>> wrote:

 > Hi. I have reflection based question.
 > I need to store type of struct passed to func and later based on
this stored type reconstruct empty needed struct.
 > Does this possible ?

Not sure I understood the question:
https://play.golang.org/p/5AEn3IsKObo

--
You received this message because you are subscribed to the Google 
Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to golang-nuts+unsubscr...@googlegroups.com 
.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CACaajQsO90D5iDOZEpsgwbPBgEu%3DU8eLpYeg%3D2b2odAcp55f9g%40mail.gmail.com 
.


--
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/df1d238c-4884-93a3-c5de-0fc56a3c928e%40mb0.org.


Re: [go-nuts] Regarding strings replace functions issues

2019-08-27 Thread Martin Schnabel

You can use the go playground to share an example. Like this:

https://play.golang.org/p/8RJXT-e91T5

As you can see in that example both functions work as expected.
We can only guess what the problem might be without a concrete
example.

One guess would be that your input has not the newline byte, but
instead the escaped sequence '\' and 'n'? Then you would need
to use the escape sequence for the slash in the search string:

https://play.golang.org/p/O-c76dM_E5B


On 27.08.19 20:06, Durga Someswararao G wrote:

Hi,

Can anyone help me in this case.

I was reading byte data(array of bytes) from another process and 
converted that data to string. Now I am trying to replace escape 
sequences \n with strings.Replace function but golang not detecting it.


Even I tried with bytes.Replace function but no use.

Also observed even strings.Contains function also not detecting \n.

Eg:

strings.Replace("String1\nString2", "\n", "golang",-1 )

Please help to solve this Issue. Can anyone share any issues with 
strings package while after converting bytes to string.


--
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/80a19b01-6843-0b44-1ace-e7b73a0e62c9%40mb0.org.


Re: [go-nuts] Regarding strings replace functions issues

2019-08-28 Thread Martin Schnabel

Somewhere in your code producing the text you seem to escape the
the escape sequence for the newline character.

"\n" is a string with the escape sequence for the newline character '\n'
"\\n" is a string with escaped slash and a lowercase n '\\' 'n'

Again, without seeing the code we can only guess. Here is another one:
Go has raw string literals using back-ticks `like this` those literals
do not use escape sequences (`\n` == "\\n" && `\\` == ""). Could it
be, that you accidentally used those raw string literals in the producer
code with the newline escape sequence that is not supported?



On 28.08.19 12:32, Durga Someswararao G wrote:

Hi,

Manually I tried but here my concern is shall I get the reason, Why that 
was happening like that?

I am trying to debug strings.Replace is not working.

Thanks.

On Wed, Aug 28, 2019 at 3:52 PM Michel Levieux > wrote:


Hi,

Isn't it that from the other side, you escape the string, or call a
method that does it before sending it via tcp? That would explain
that all the "\n" become "\\n".

Le mer. 28 août 2019 à 12:17, Durga Someswararao G
mailto:durgasomeswararao...@gmail.com>> a écrit :

Hi Tamás,

But even in other side also I am using golang to convert string
into bytes. Using tcp connection with net package I am getting
data from other process.

FYI
When I try to replace string with \\n it was working fine.

Like below:
processoutput = strings.Replace("String 1\n String
2","\\n","'@_@_@'",-1)

On Wed, Aug 28, 2019 at 3:26 PM Tamás Gulácsi
mailto:tgulacs...@gmail.com>> wrote:

That means that other process speaks some other encoding,
not utf-8, which the strings package waits.
Use golang.org/x/text/encoding
 to convert to utf-8.

-- 
You received this message because you are subscribed to the

Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails
from it, send an email to
golang-nuts+unsubscr...@googlegroups.com
.
To view this discussion on the web visit

https://groups.google.com/d/msgid/golang-nuts/865188f0-405e-45ee-82b9-7f6d24f1d49f%40googlegroups.com.

-- 
You received this message because you are subscribed to the

Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from
it, send an email to golang-nuts+unsubscr...@googlegroups.com
.
To view this discussion on the web visit

https://groups.google.com/d/msgid/golang-nuts/CA%2Ba9DGr83pA%2Bvrkg-bYkOs-qjsqxkOgEjoGTmigtJsr0hO287w%40mail.gmail.com

.

--
You received this message because you are subscribed to the Google 
Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to golang-nuts+unsubscr...@googlegroups.com 
.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CA%2Ba9DGrM47a%3Dj6Zbk1caY46FYUG7fXC2J0z0QvoJtSp69b6NCQ%40mail.gmail.com 
.


--
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/2c202a4b-1db1-2247-d374-814f66c81b0c%40mb0.org.


Re: [go-nuts] Regarding strings replace functions issues

2019-08-28 Thread Martin Schnabel

Go has a fantastic and very readable language specification with all
the details:  https://golang.org/ref/spec#String_literals

(To my surprise the effective go document does not explain raw string
literals, but uses them in the web server example in the template
string)

Another guess by Michel is that you call a string quote function
like strconv.Quote either directly or indirectly on the producer side.

The following playground link demonstrates some ways you could arrive
at a quoted string. https://play.golang.org/p/-QRz7x00Shn

However, then you would also see double quotes enclosing the quoted text
in your output.

To summarize: we found out that your problem has nothing to do with
strings.Replace, but instead with the way your producer writes its
output. We have two general ideas how this could be the case but
can only help you find the issue if you share reproducible examples.

On 28.08.19 13:15, Martin Schnabel wrote:

Somewhere in your code producing the text you seem to escape the
the escape sequence for the newline character.

"\n" is a string with the escape sequence for the newline character '\n'
"\\n" is a string with escaped slash and a lowercase n '\\' 'n'

Again, without seeing the code we can only guess. Here is another one:
Go has raw string literals using back-ticks `like this` those literals
do not use escape sequences (`\n` == "\\n" && `\\` == ""). Could it
be, that you accidentally used those raw string literals in the producer
code with the newline escape sequence that is not supported?



On 28.08.19 12:32, Durga Someswararao G wrote:

Hi,

Manually I tried but here my concern is shall I get the reason, Why 
that was happening like that?

I am trying to debug strings.Replace is not working.

Thanks.

On Wed, Aug 28, 2019 at 3:52 PM Michel Levieux 
mailto:m.levi...@capitaldata.fr>> wrote:


    Hi,

    Isn't it that from the other side, you escape the string, or call a
    method that does it before sending it via tcp? That would explain
    that all the "\n" become "\\n".

    Le mer. 28 août 2019 à 12:17, Durga Someswararao G
    mailto:durgasomeswararao...@gmail.com>> a écrit :

    Hi Tamás,

    But even in other side also I am using golang to convert string
    into bytes. Using tcp connection with net package I am getting
    data from other process.

    FYI
    When I try to replace string with \\n it was working fine.

    Like below:
    processoutput = strings.Replace("String 1\n String
    2","\\n","'@_@_@'",-1)

    On Wed, Aug 28, 2019 at 3:26 PM Tamás Gulácsi
    mailto:tgulacs...@gmail.com>> wrote:

    That means that other process speaks some other encoding,
    not utf-8, which the strings package waits.
    Use golang.org/x/text/encoding
    <http://golang.org/x/text/encoding> to convert to utf-8.

    --     You received this message because you are 
subscribed to the

    Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails
    from it, send an email to
    golang-nuts+unsubscr...@googlegroups.com
    <mailto:golang-nuts%2bunsubscr...@googlegroups.com>.
    To view this discussion on the web visit

https://groups.google.com/d/msgid/golang-nuts/865188f0-405e-45ee-82b9-7f6d24f1d49f%40googlegroups.com. 



    --     You received this message because you are 
subscribed to the

    Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from
    it, send an email to golang-nuts+unsubscr...@googlegroups.com
    <mailto:golang-nuts+unsubscr...@googlegroups.com>.
    To view this discussion on the web visit

https://groups.google.com/d/msgid/golang-nuts/CA%2Ba9DGr83pA%2Bvrkg-bYkOs-qjsqxkOgEjoGTmigtJsr0hO287w%40mail.gmail.com 


<https://groups.google.com/d/msgid/golang-nuts/CA%2Ba9DGr83pA%2Bvrkg-bYkOs-qjsqxkOgEjoGTmigtJsr0hO287w%40mail.gmail.com?utm_medium=email&utm_source=footer>. 



--
You received this message because you are subscribed to the Google 
Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to golang-nuts+unsubscr...@googlegroups.com 
<mailto:golang-nuts+unsubscr...@googlegroups.com>.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CA%2Ba9DGrM47a%3Dj6Zbk1caY46FYUG7fXC2J0z0QvoJtSp69b6NCQ%40mail.gmail.com 
<https://groups.google.com/d/msgid/golang-nuts/CA%2Ba9DGrM47a%3Dj6Zbk1caY46FYUG7fXC2J0z0QvoJtSp69b6NCQ%40mail.gmail.com?utm_medium=email&utm_source=footer>. 





--
You received this message because you are subscribed to the Google Groups 

[go-nuts] Re: ls: unsupported SSLv2 handshake received

2019-09-18 Thread Anthony Martin
Prabhash Rathore  once said:
> Looking at comment, it seems Golang does not support SSLv2 and SSLV3.

The crypto/tls package can support SSLv3 if you set tls.Config.MinVersion
to tls.VersionSSL30, but only as a server.

> I am reaching out to see if there is anyway possible to add support for 
> older SSL versions or if there are any workarounds. In SMTP world, there 
> are lots of clients who still use old SSL builds and we would like to be 
> able to support them on our MTA servers.

I think it's unlikely that SSLv2 will be supported. There is a very
old discussion about this at https://github.com/golang/go/issues/3930
that you might want to check out.

Cheers,
  Anthony

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/20190918084123.GA4577%40alice.


[go-nuts] JWT validation only in Middleware

2019-09-26 Thread Martin Palma
Hello,

I'm in the process of writing an HTTP API with Go. I use a middleware for 
generating and validating JWT tokens. On any incoming request the 
middleware checks the JWT and validates it. If valid it adds it to the 
request header and calls the next handler. 

Is it save to use the JWT in the next handler without validating it again 
and using the claims?

Best,
Martin

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/69d031e5-2a11-4904-84d6-1e67c0bc85a9%40googlegroups.com.


Re: [go-nuts] JWT validation only in Middleware

2019-09-27 Thread Martin Palma
Yes the handler are arranged as follows:

OAuth2Middleware (JWT token creation on login / JWT validation) ->
InputValidationMiddleware (decoding and validating user input and checks if
the user has the rights to view/request the data according to the claims in
the JWT) -> API Handler (decoding user input and talking to the backend,
return response to the user)

You are right the OAuth2Middlware could instead of passing the token after
validation also pass the claims using the request context. That's right.

Thank you for the feedback.

On Thu, 26 Sep 2019 at 21:36, burak serdar  wrote:

> On Thu, Sep 26, 2019 at 1:14 PM Martin Palma  wrote:
> >
> > Hello,
> >
> > I'm in the process of writing an HTTP API with Go. I use a middleware
> for generating and validating JWT tokens. On any incoming request the
> middleware checks the JWT and validates it. If valid it adds it to the
> request header and calls the next handler.
> >
> > Is it save to use the JWT in the next handler without validating it
> again and using the claims?
>
> If you make sure you have those two handlers in that order, then the
> answer is yes.
>
> Another approach is to validate the JWT in the first handler, and put
> the claims into the request context for the next handler, so the next
> handler doesn't even deal with the JWT, and gets the claims from the
> context. This assumes the second handler won't be called if JWT
> doesn't validate.
>
> >
> > Best,
> > Martin
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups "golang-nuts" group.
> > To unsubscribe from this group and stop receiving emails from it, send
> an email to golang-nuts+unsubscr...@googlegroups.com.
> > To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/69d031e5-2a11-4904-84d6-1e67c0bc85a9%40googlegroups.com
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CANMxC7C_kXNmX1_RCCYwCS3X-7dTrLc_sfzLi-F8mLpcffMY2A%40mail.gmail.com.


[go-nuts] Interface method return other interface?

2019-10-09 Thread Martin Palma
I'm wondering If it is ok (or good Go code) if an interface method returns 
an other interface? Here an example:

type Querier interface {
 Query() string
}

type Decoder interface {
 DecodeAndValidate() Querier
}


-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/531f29a6-ea2e-4416-a0d0-ce697dc7a09b%40googlegroups.com.


Re: [go-nuts] Interface method return other interface?

2019-10-10 Thread Martin Palma
Thank you all for your feedback and input. Shame on me that I didn't
look hard enough through the stdlib for getting some examples, but
thanks Axel for pointing that out.

On Thu, Oct 10, 2019 at 3:11 AM Robert Engels  wrote:
>
> Ugh. Every time I see that I cringe
>
> > On Oct 9, 2019, at 7:58 PM, burak serdar  wrote:
> >
> > On Wed, Oct 9, 2019 at 5:48 PM 'Axel Wagner' via golang-nuts
> >  wrote:
> >>
> >> There's loads of precedence in the stdlib:
> >>
> >> https://godoc.org/net/http/#FileSystem.Open
> >> https://godoc.org/net/http#File.Stat
> >> https://godoc.org/net#Conn.LocalAddr
> >> https://godoc.org/database/sql/driver/#Driver.Open
> >> https://godoc.org/image#Image.ColorModel
> >> https://godoc.org/reflect/#Type.Elem
> >> And don't forget that error itself is an interface.
> >>
> >> Honestly, if you need it, go for it. There are definitely places where 
> >> it's over abstraction to do it, but I don't think there's a good or 
> >> universal rule you can use to decide which is which.
> >>
> >> FWIW, I tend to disagree with the "return structs, accept interfaces" 
> >> advise in general. If go had variant func/methods, that would be useful 
> >> guidance. But as it stands, it is too often necessary to violate it (every 
> >> usage of an error return value is in fact such a violation). And the 
> >> "accept interfaces" part tends to lead to over abstraction (I would 
> >> probably agree with "consider accepting interfaces if they already exist" 
> >> though).
> >
> >
> > There is one point you need to remember when returning interfaces:
> > make sure you handle nil correctly:
> >
> > type S struct {}
> >
> > type I interface {}
> >
> > func f() *S {
> >  return nil
> > }
> >
> > func g() I {
> >  x:=f()
> >  return x
> > }
> >
> > Above, g() is not nil. The correct code would be:
> >
> > func g(() I {
> >  x:=f()
> >  if x==nil {
> >   return nil
> >  }
> >  return x
> >
> > }
> >
> >
> >>
> >>> On Wed, Oct 9, 2019 at 9:39 AM Martin Palma  wrote:
> >>>
> >>> I'm wondering If it is ok (or good Go code) if an interface method 
> >>> returns an other interface? Here an example:
> >>>
> >>> type Querier interface {
> >>> Query() string
> >>> }
> >>>
> >>> type Decoder interface {
> >>> DecodeAndValidate() Querier
> >>> }
> >>>
> >>>
> >>> --
> >>> You received this message because you are subscribed to the Google Groups 
> >>> "golang-nuts" group.
> >>> To unsubscribe from this group and stop receiving emails from it, send an 
> >>> email to golang-nuts+unsubscr...@googlegroups.com.
> >>> To view this discussion on the web visit 
> >>> https://groups.google.com/d/msgid/golang-nuts/531f29a6-ea2e-4416-a0d0-ce697dc7a09b%40googlegroups.com.
> >>
> >> --
> >> You received this message because you are subscribed to the Google Groups 
> >> "golang-nuts" group.
> >> To unsubscribe from this group and stop receiving emails from it, send an 
> >> email to golang-nuts+unsubscr...@googlegroups.com.
> >> To view this discussion on the web visit 
> >> https://groups.google.com/d/msgid/golang-nuts/CAEkBMfHHtn5t3TZOCG4xA_3kVbNqY2_xo7EtHoLyhi6P28ku9g%40mail.gmail.com.
> >
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "golang-nuts" group.
> > To unsubscribe from this group and stop receiving emails from it, send an 
> > email to golang-nuts+unsubscr...@googlegroups.com.
> > To view this discussion on the web visit 
> > https://groups.google.com/d/msgid/golang-nuts/CAMV2Rqp-n0UaxQVpPVgJKayNzY6Voe5QRL4n7MoqmQMavL3oiQ%40mail.gmail.com.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CANMxC7BHfFNduYVqY8xnZyTL8oPzZ2r15ApeGRsVW60Xckswng%40mail.gmail.com.


[go-nuts] Re: [security] Go 1.13.2 and Go 1.12.11 are released

2019-10-18 Thread Anthony Martin
Katie Hockman  once said:
> The Go 1.13.2 release also includes a fix to the compiler that prevents
> improper access to negative slice indexes in rare cases. Affected code, in
> which the compiler can prove that the index is zero or negative, would have
> resulted in a panic in Go 1.12.11, but could have led to arbitrary memory
> read and writes in Go 1.13 and Go 1.13.1. This is Go issue
> golang.org/issue/34802.

Well that's not good. Maybe next time you should lead with the arbitrary
memory r/w instead of the comparatively minor nil-deref panic. I almost
missed it while skimming the end.

Cheers,
  Anthony

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/20191018235835.GA118207%40alice.


[go-nuts] Re: mutual TLS authentication (sometimes)

2019-11-20 Thread Anthony Martin
Matthew Zimmerman  once said:
> I've also thought about authenticating on a different domain name
> auth.service then redirecting to data.service or something like that where
> the cookie would be issued to the *.service domain, however that's still
> one tls.Config and using SNI with tls.Config.GetCertificate() and I don't
> know of a way to change the tls.Config.ClientAuth for a server based upon
> the SNI.
> 
> Any ideas?

% go doc crypto/tls Config.GetConfigForClient
package tls // import "crypto/tls"

type Config struct {
// GetConfigForClient, if not nil, is called after a ClientHello is received
// from a client. It may return a non-nil Config in order to change the 
Config
// that will be used to handle this connection. If the returned Config is 
nil,
// the original Config will be used. The Config returned by this callback 
may
// not be subsequently modified.
//
// If GetConfigForClient is nil, the Config passed to Server() will be used 
for
// all connections.
//
// Uniquely for the fields in the returned Config, session ticket keys will 
be
// duplicated from the original Config if not set. Specifically, if
// SetSessionTicketKeys was called on the original config but not on the
// returned config then the ticket keys from the original config will be 
copied
// into the new config before use. Otherwise, if SessionTicketKey was set in
// the original config but not in the returned config then it will be copied
// into the returned config before use. If neither of those cases applies 
then
// the key material from the returned config will be used for session 
tickets.
GetConfigForClient func(*ClientHelloInfo) (*Config, error)

// ... other fields elided ...
}
%

Cheers,
  Anthony

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/20191120091723.GA87289%40alice.


Re: [go-nuts] Weird slice of struct

2019-12-04 Thread Martin Schnabel




On 04.12.19 22:40, cstige...@gmail.com wrote:

Hello Golang nuts group.

I've tested golang's slice and got a weird result.

Anyone can explain it?



the variable ss in the for range loop is one and the same variable, with 
a different value of AA for each iteration. it has only one address.
after the for loop is done the variable has the value of the last 
iteration. you can declare a new variable within the block scope that 
changes between iterations:


https://play.golang.org/p/UMsez9sX9xO

hope that helps

--
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/d2a1c349-0b4c-9e4f-efbe-e19ed8c4f473%40mb0.org.


Re: [go-nuts] runtime: split stack overflow

2016-08-26 Thread martin . strenge
Hi,

It took a while to understand what's going on.
 

> I'm not sure which part of the os/signal docs you are thinking of. 


I'm referring to "Go programs that use cgo or SWIG", last paragraph ("If 
the Go signal handler is invoked on a non-Go thread not running Go code 
[...]"). I couldn't get any information about the crash in C from the Go 
signal handler. It remained silent and just quitted the program.

Crashes in Go code will work regardless of whether they are running on 

threads started by C or not.  So I assume you are talking about 
> crashes in C.  How do you want to handle those crashes?  Do you just 
> want to try to dump the stack?  How do you want to handle other C 
> threads when one C thread crashes? 
>

Yes, I meant crashes in C. I want to create a crash dump file and dump all 
C threads and Go routines. 

I do agree that your code should work in principle, and I'm not sure 
> why it doesn't. 
>
> If all you wan to do is handle SIGSEGV when it occurs in a C thread, 
> it may work to call signal.Notify(c, syscall.SIGSEGV).  The channel 
> will receive a signal wen a SIGSEGV occurs in C code.  At that point 
> it's not safe to continue, but it is safe to take whatever action you 
> like to dump C threads.  I'm not sure this will work, because it 
> depends on what happens when the SIGSEGV signal handler returns to the 
> C code that triggered the SIGSEGV. 
>

The reason for the morestack call is, that sigtramp is not called in my 
code example. The sa_tramp seems to be overwritten in my call to 
sigaction(int,struct sigaction*,struct sigaction*) and I cannot retrieve 
the original trampoline function via __sigaction(int, struct __sigaction*, 
struct sigaction*), to call it in my handler. Calling it directly would 
probably not work anyway, as sigtrampgo already calls sigreturn, but I want 
to be able to do calculations in the C handler if the Go handler has 
returned. So, I'm quite stuck here. Do you have any ideas?

I will open another thread to discuss the "correct way" to create a crash 
dump file for Go and C, and discuss my experiments. I'll leave this thread 
for the signal handler replacement on Darwin.

Thanks!
Martin

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] runtime: split stack overflow

2016-08-26 Thread martin . strenge

>
> Interesting.  Maybe we need to change this line in setsig in 
> runtime/os_darwin.go 
> *(*uintptr)(unsafe.Pointer(&sa.__sigaction_u)) = fn 
> to be 
> *(*uintptr)(unsafe.Pointer(&sa.__sigaction_u)) = 
> unsafe.Pointer(funcPC(sigtramp))  
>

That's not possible, the signatures of sa_tramp and sa_sigaction do not 
match:

/* union for signal handlers */ 
union __sigaction_u { 
void (*__sa_handler)(int);
void (*__sa_sigaction)(int, struct __siginfo *, void *);
}; 

/* Signal vector template for Kernel user boundary */
struct __sigaction {
union __sigaction_u __sigaction_u; /* signal handler */ 
void (*sa_tramp)(void *, int, int, siginfo_t *, void *);
sigset_t sa_mask; /* signal mask to apply */
int sa_flags; /* see signal options below */
}; 

Martin 

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] runtime: split stack overflow

2016-08-29 Thread martin . strenge

>
> OK, then perhaps we need setsig in os_darwin.go to set 
> the sigaction field to a new function, written in assembler, like 
> sigtramp, but taking just the sigaction arguments.  


Could you please explain, why it is necessary to use sa_tramp with a custom 
function instead of using the default one and do it like in Linux?
 

> And presumably not 
> calling sigreturn. 
>

... and save all registers in plan9 sigtramp functions.

I'll open an issue.

Thanks,
Martin

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] runtime: split stack overflow

2016-08-29 Thread martin . strenge

>
> I'm only talking about changing Darwin. 
>

Sorry, I meant pushing the gcc callee-saved registers in the assembly 
sigtramp functions (for example in sys_darwin_amd64.s) as it is done in 
crosscall2. I ran into the issue, that the content in the rbx register was 
overwritten by the sigfwdgo() function as plan9 does not have the same 
register saving rules.

Martin

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Creating a crash dump file with Go and C stack traces

2016-08-30 Thread martin . strenge
Hi,

I have a Go executable that uses a shared C library which spawns it own 
threads. In case of a crash (in Go or C code), I want to dump all 
stacktraces of all C threads and Go routines into a crash dump file. Go 
does not handle signals in non-Go threads executing non-Go code, so I have 
to install a custom C signal handler to handle those cases. And as Go does 
not invoke a preinstalled C handler in case of crashes in Go code, the C 
handler has to be registered after the Go handler.

After some experiments - restricted to Linux amd64 - I got it working 
somehow (https://gist.github.com/trxa/302c5dbe9055ef287da9139e68d0a93e). 
But it feels a bit hacky with some drawbacks and I wonder if somebody can 
propose a better solution or improvements.


How it basically works:

The Go handlers are stored when the C handler gets installed. 
If invoked, for example by a SIGSEGV, the handler opens a file and writes 
the stack trace of the current thread into that file.
Then, it signals all other threads to dump their stack into the file too.
After all threads are dumped, the IP of the failing instruction is saved 
and the Go handler is invoked by calling it directly to keep the ucontext 
of the crash.
After the Go handler has returned, it is checked whether the IP of the 
uc_mcontext has been changed by Go.
If it is changed, the IP points to runtime.sigpanic which triggers a panic 
and dumps the Go routine stacks to STDERR. 
If it is not changed, the crash was in non-Go code on a non-Go thread and 
Go does not handle the crash. In that case, the IP register in uc_mcontext 
is set to the function pointer of an exposed Cgo function which calls 
panic() to dump the stack to STDERR.
Before returning from the C handler, the STDERR file descriptor is replaced 
by the crash dump file descriptor, so that Go panics into the file. (The Go 
handlers should probably be restored before returning, if Go still wants to 
backtrace the threads via SIGQUIT itself.)
After the C handler has returned, runtime.sigaction or the cgo function is 
executed and does not return. 


Here are the disadvantages and things to watch out, which makes the 
solution a bit creepy:

1. signal.Notify has to be called for all signals you want to handle for C 
crashes, although they are not handled in Go. Otherwise the Go handler does 
not return in the "non-Go-code/thread" case, but creates a core dump.

2. Setting the IP to a cgo function to be executed when the handler 
returns, makes the program panicing synchronously, as with 
runtime.sigpanic, but is probably not async-signal-safe, for example if it 
has to request more stack.
A workaround would be to panic in Go, if the signal is read from the notify 
channel. In addition, the C handler must not return to avoid reexecution of 
the faulting instruction. This can be done by putting the thread to sleep. 
Doing this is probably even more platform independent, but that way, a 
synchronous signal from C is handled as an asynchronous one and you don't 
have a chance to distinguish it in Go by the information you get (in case 
you only want to dump and continue for asynchronous signals).

3. Cloning the STDERR file descriptor to point to a file feels also a bit 
fragile compared to directly writing to it. Another thread might write to 
it. The fd cannot be closed (except maybe in a global destructor) and the 
OS would have to flush the buffers correctly (or I have to use synchronous 
write mode, which slows writing the dump down tremendously).

4. There are duplicate stack traces, and it's not always obvious to match a 
thread stack trace to the running go routine.

5. It would be desirable to have the stack trace of the failing instruction 
redundantly in the crash file and in the log file, but with this solution 
it is only possible for C frames and the first Go frame on top of the 
thread, at least if you use a common unwinder library.

There might be more.


>From my point of view, a better solution would be, when Go has an option 
(maybe via GOTRACEBACK env var) to trace C threads as well, for example by 
using the cgo traceback functions introduced in Go 1.7. Also setting a file 
descriptor/handle as target for a dump should be allowed (maybe in addition 
to the dump on STDERR). In addition to the cgo traceback functions, there 
might be one or more functions for gathering additional information, which 
will be printed in the crash dump. A use case for that would be a list of 
loaded modules/libraries or environment variables.
I can imagine that it's easier said than done, but that's what I would 
prefer.


Thanks for your opinions!
Martin

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] cgo and OSX "main thread"

2016-09-09 Thread Martin Bertschler
There is also a great wiki article on how to execute functions on the main 
thread from multiple goroutines. It helped me a lot when I did some GUI 
development experiments.
https://github.com/golang/go/wiki/LockOSThread

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Idea for versioning in the new Go package manager.

2016-10-26 Thread Martin Bertschler
Hello Gophers!

Yesterday I attended a tech meetup and was introduced to the Elm language 
<http://elm-lang.org/>. The one thing that really stuck with me was how the 
Elm package manager handles semantic versioning for the package developers. 
As soon as things are added to the packages API, the minor version of the 
package is automatically bumped, and if the existing API of the package is 
changed, the major version is bumped.

I think this could be a great idea for the new package manager, since the 
whole Go ecosystem values stability and great tooling a lot. Some benefits 
of this feature that I can imagine:

   - Not having to think about the next version number, especially in small 
   projects where I just want to publish some new code. Let the tool just 
   choose one for you.
   - No accidental changes the public API during development, the tool 
   would point out the API changes to you before publishing. If you didn't 
   intend the change you could fix it.
   - Always correct usage of semantic versioning, that the whole ecosystem 
   can depend on. This could enable automatic updates to always the newest 
   patch version. 

Implementing it should not be hard because we already have things like 
https://golang.org/cmd/api/.

The full specification on how Elm handles that can be found here: 
https://github.com/elm-lang/elm-package. 

What are your thoughts on this matter?

Best,
Martin

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Oxymoron: language spec: ``untyped boolean value''

2016-11-02 Thread Martin Steffen
Hi, in the language spec, e.g. in connection with ``type assertions'' and 
``special forms'', like 

v, ok = x.(T)

it's stated that it yield (in ok) an additional value which is both  untyped 
and boolean
(an ``untyped boolean value'').

How should one interpret that? If ok behaves like a boolean, why is it 
considered as untyped?

Martin


-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Oxymoron: language spec: ``untyped boolean value''

2016-11-02 Thread Martin Steffen
Thanks for all the replies. Basically it is  more like a puzzlement over 
choice of terminology,
not so much what the meaning resp. purpose of the ``special form'' of 
assignments (with ``ok'') is.


So calling the use of "ok"  an ``untyped boolean'' it seems a bit 
Go-specific (and/or go-implementation-centric)
terminology. Indeed the section about "constants" (mentioned in an earlier 
reply) sheds some light,  in 
that it's a special case of how the Go specification speaks about typing 
issues surrounding literals.

But still, the sentence in that section of the language specification there 
spelling it out as

"An untyped constant has a default type" (*)


sounds ``oxymoronic'' to the unsuspecting: something  is called "untyped"
_but_  at the same time ``has a type''. Of course it's the official
specification, so it is how it formulated as it is and one can live with 
it.  but still a
bit strange manner of speaking. 



PS: oxymoron means not being a self-contradictory statement as such, but a 
formulation that "appears to be contradictory''  
which upon first reading applies to the formulation (*) at least for me :-)




On Wednesday, November 2, 2016 at 12:04:39 PM UTC+1, Pietro Gagliardi 
(andlabs) wrote:
>
> It means there is no specific type name, but the resultant type must 
> either be bool or convertible to bool:
>
> type A bool
> var n int
> var ok A
> n, ok = x.(int)
>
> Using bool here is not common, but you see this with int and float, etc. 
> Untyped constants is one of the most prominent Go features.
>
> On Nov 2, 2016, at 4:09 AM, Martin Steffen  > wrote:
>
> Hi, in the language spec, e.g. in connection with ``type assertions'' and 
> ``special forms'', like 
>
> v, ok = x.(T)
>
> it's stated that it yield (in ok) an additional value which is both  untyped 
> and boolean
> (an ``untyped boolean value'').
>
> How should one interpret that? If ok behaves like a boolean, why is it 
> considered as untyped?
>
> Martin
>
>
>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to golang-nuts...@googlegroups.com .
> For more options, visit https://groups.google.com/d/optout.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Oxymoron: language spec: ``untyped boolean value''

2016-11-02 Thread Martin Steffen
Thanks.

I may have been imprecise using ``implementation specific''. I did not mean 
it in the 
C-like manner that the ``meaning''  of some (typed) value depends on the 
platform (length of some words) or the choice of the compiler
writer for a given platform. 


I meant more: the _terminology_ of being untyped may reflect an internal 
treatment of how the go compiler treats
those things: inside the go-compiler, the ``static phase''/type 
checker/type inferencer may treat 
for instance literals as being in  one of 
two states: one which is called "untyped", where said flexibility (or 
polymorphism if you wish) is  possible, and one where this
is not immediatly possible (without conversion). These to states are called 
"untyped" and "typed" in the compiler. In that way, I meant "implementation 
specific". 

Fair enough. I also understand why this flexibility in typing is very 
desirable, useful etc. 

The only thing I maintain is that, if one would ask me (not that it's  
generally recommended), 
I'd had not chosen to call  the phenomenon of  this form of flexible or 
polymorphiic handling
of literals  in a typed language as "untypedness"  
(even if that's accepted terminology in the Go community). 

For me (with my background), I would have called 5 to be "polymorphically 
typed" in that it can carry more
than one type (namely as you said, all types which are ``compatible'' with 
int without conversion).
.

Likewise I maintain that while internally consistent and meaninfull 
thereby, 
purely from the point of view from usage of English.
a sentence  from 

https://golang.org/blog/constants. 

like 
  "an untyped constant has a default type" 

is confusing, especially for beginners: I would simply not call something 
which has a (default)  type "untyped"
(even if the mechanism justifying the distinction is useful). Again one can 
say, the compiler treats it as not having a 
final type yet, but when the time comes for decision, then a type will be 
chosen and then checked to
be compatible with bool. All fine, but reads  confusing for outsiders (the 
mechanism itself is clearer than the terminology),


But I get the _idea_ behind the notion of being "untyped", which is the 
important part, thanks for the discussion. 








But it's a really a terminology question. I only can't imagine explaining 
it to students: ``remember, true is untyped, 
but it can only be used as if it had  type bool''.  


On Wednesday, November 2, 2016 at 2:34:56 PM UTC+1, Ian Lance Taylor wrote:
>
> On Wed, Nov 2, 2016 at 4:27 AM, Martin Steffen  > wrote: 
> > 
> > So calling the use of "ok"  an ``untyped boolean'' it seems a bit 
> > Go-specific (and/or go-implementation-centric) 
> > terminology. Indeed the section about "constants" (mentioned in an 
> earlier 
> > reply) sheds some light,  in 
> > that it's a special case of how the Go specification speaks about typing 
> > issues surrounding literals. 
>
> It's Go-specific, but in the context of Go it's meaningful.  It's not 
> implementation-centric.  Remember that in Go if you write 
>
> type B1 bool 
> type B2 bool 
> var v1 B1 
> var v2 B2 
>
> then it is a type error to write 
>
> v1 = v2 
>
> So an untyped boolean, like an untyped int, etc., is a value that can 
> be assigned to any type whose underlying type is bool without 
> requiring a type conversion. 
>
> It may help to read https://golang.org/blog/constants. 
>
> Ian 
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Shuffle Items in a Slice

2016-06-24 Thread Martin Geisler
On Fri, Jun 24, 2016 at 1:05 PM, dc0d  wrote:
>
> Hi;
>
> To shuffle items in a slice I'm doing this:
>
> var res []Item
>
> //fill res logic
>
> shuffle := make(map[int]*Item)
> for k, v := range res {
>  shuffle[k] = &v
> }
> res = nil
> for _, v := range shuffle {
>  res = append(res, *v)
> }
>
> Which inserts items into a map then ranges over that map. Ranging over a map 
> in Go returns the items in random order.
>
> 1 - I thought it's a cool trick!
> 2 - Is anything bad about doing this?

While iteration over a map is said to be random, it isn't specified
exactly how "random" the iteration is. The spec says

  https://golang.org/ref/spec#RangeClause
  The iteration order over maps is not specified and is not guaranteed
to be the same from one iteration to the next.

That is, the iteration order should not to be relied upon. A simple test like

  https://play.golang.org/p/czRE3pbMzc

shows this: the keys are printed in a scrambled order. When I run this
on my machine, I get a different order every time, but on the
playground the order seems to be fixed and I get "0 5 7 1 2 3 4 6 8 9"
every time. My guess would be that an external input is used to
initialize the hash function used behind the scene -- and on the
playground that input somehow has a fixed value.

Unless you're build a toy application, my advice would be to use a
real random generator to generate indexes into the map. Use these
indexes to swap elements and permute the array as Konstantin mentioned
(https://en.wikipedia.org/wiki/Fisher–Yates_shuffle).

-- 
Martin Geisler

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Append to slice... what happens?

2016-06-26 Thread Martin Geisler
Hi Henry,

On Mon, Jun 27, 2016 at 3:55 AM, Henry  wrote:
> If you were to change the code a bit as follows 
> https://play.golang.org/p/VwtWRQBrEe , it will work as you expect.
>
> I think it is probably safer to instantiate a slice without specifying the 
> initial capacity.

Having the capacity larger than the number of used elements (the
length of the slice) is indeed the problem. However, not specifying
the capacity can also fail you. Here I changed the numbers of elements
appended slightly and print the capacity after each operation:

  https://play.golang.org/p/WBTRvgJJKW

As you can see, append will over-allocate and set the capacity of the
underlying array to 4 when we go from an empty slice to a slice with
length 3. This in turn makes the following appends to a and b share
the 4th slot in the array and appending to a will ultimately update
the value you see in b.

In your example you were "lucky" since you started with a = [1, 2] and
cap(a) = 2. When you create b, append notices that the capacity is
exhausted and *creates a new underlying array for b*. After that step,
a and b are no longer "entangled" like this and updates to one cannot
affect the other.

-- 
Martin Geisler

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Append to slice... what happens?

2016-06-26 Thread Martin Geisler
On Mon, Jun 27, 2016 at 12:34 AM, Jan Mercl <0xj...@gmail.com> wrote:
> On Mon, Jun 27, 2016 at 12:26 AM Peter Kleiweg  wrote:
>
>> I don't know what I expected, but it's weird. Don't mess with slices.
>
> Well, working as expected, considering slice backing array is possibly
> shared wrt the result of append. (Or other slice op, b/c slices _are_
> values.)
>
> However, it's easy to avoid the append sharing when/where not desirable:
> https://play.golang.org/p/oIFHamYWB-

To unpack what Jan wrote a little: when slicing, you can specify a
third integer which becomes the capacity of the new slice. So

  b := a[:len(a):len(a)]

will create a new slice b with len(b) = len(a) and cap(b) = len(a).
Without the third argument, cap(b) = cap(a). When cap(a) > len(a) you
have the situation where append(a, 123) is quick: is can just insert
the element into the underlying array without having to reallocate
anything.

So the line

  b := append(a[:len(a):len(a)], 3, 4)

does two things: it slices a to obtain a new slice with a lower than
normal capacity. Because the capacity exactly matches the length of
the new slice, trying to append to it is guaranteed to reallocate the
underlying array. So append makes a new, larger array and copies
len(a) elements into it. It then writes 3 and 4 into the new array as
well before returning a slice of the array. That slice becomes b.

>From that point onwards, a and a are no longer connected via the
underlying array.

BTW, I was about to say that you could simplify the line one step further with

  b := append(a[::len(a)], 3, 4)

but that gives a compilation error:

  prog.go:11: middle index required in 3-index slice

I wonder what the rationale is for this? It seems inconsistent to me
since the second (middle) index has a useful default (len(a)) that is
used when there are only two indexes used.

-- 
Martin Geisler

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Shuffle Items in a Slice

2016-06-26 Thread Martin Geisler
Hi Val

On Fri, Jun 24, 2016 at 2:48 PM, Val  wrote:
> 2 implementations here :
> http://www.programming-idioms.org/idiom/10/shuffle-a-list/1564/go
>
> As for the map iteration trick, the runtime doesn't guarantee to randomize
> anything, although it often tries to, so developers don't rely on some
> specific order.

That's a nice feature and very helpful when writing tests... otherwise
you end up with a test that works fine on one version/architecture and
"suddenly" breaks later.

Randomizing the order "on purpose" is probably also done for security
reasons. Python works much the same, and some years ago, the CPython
VM began randomizing the dict (map) type. The problem was that
carefully crafted input would trigger a worst-case scenario in the
hash table used behind the scenes and suddenly make your server crawl
to a halt.

The input could be HTTP headers, for example, with carefully chosen
names: these are normally read from the client and used as keys in a
map. With the right keys, you can trigger hash collisions and make the
map allocate much more memory than you would expect with typical keys.

Having the runtime add a bit of randomness to the keys prevents this
scenario. When the randomness changes at every execution, it further
helps the developers by highlighting the nondeterministic iteration
order of the hash table.

> I've seen (in the past) some map iterations consistently not
> randomized at all. This behaviour may have evolved, but don't rely on it.

That's good advice :-)

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Shuffle Items in a Slice

2016-06-26 Thread Martin Geisler
On Fri, Jun 24, 2016 at 2:54 PM, Val  wrote:
> The playground caches everything, so running multiple times the same program
> will just serve the previously generated output.

Thanks, that's good to know! Makes a lot of sense too.

> Also in the playground everything is frozen at some point in the past : the
> clock, the randomness sources, and you can't make outgoing requests to
> import randomness from the network.

I found this blog post with a lot more background information:

  https://blog.golang.org/playground

-- 
Martin Geisler

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Append to slice... what happens?

2016-07-01 Thread Martin Geisler
Hi Ian,

On Mon, Jun 27, 2016 at 8:18 PM, Ian Lance Taylor  wrote:
> On Sun, Jun 26, 2016 at 10:55 PM, Dan Kortschak
>  wrote:
>> On Mon, 2016-06-27 at 07:49 +0200, Martin Geisler wrote:
>>> BTW, I was about to say that you could simplify the line one step
>>> further with
>>>
>>>   b := append(a[::len(a)], 3, 4)
>>>
>>> but that gives a compilation error:
>>>
>>>   prog.go:11: middle index required in 3-index slice
>>>
>>> I wonder what the rationale is for this? It seems inconsistent to me
>>> since the second (middle) index has a useful default (len(a)) that is
>>> used when there are only two indexes used.
>>
>> As I remember it, during the design discussions the possibility of using
>> the shortened syntax you show above was considered, but rejected as an
>> opening to bug entry (too much semantic weight on a single repeated
>> character).
>
> Yes.  And, also, the default for the middle index is not wholly
> obvious.  Should it be len(a) or (new) cap(a)?  In your example those
> happen to have the same value, but of course in general they do not.

Hmm, that's a good point that I hadn't considered :-) I figured it
would be len(a) so that

  a[x::z] = a[x:len(a):z]

That keeps the defaults intact from normal 2-index slicing.

For the indices to be in range, you must have z >= y where y = len(a).
So maybe one could argue that the middle index y could be clamped at
z, that is, the middle index y could be set to min(z, len(a)). That
way you can have a slice with length 10 and still write

  a[2::4] = a[2:min(4, 10):4] = a[2:4:4]

where there indices are all in range.

I see how this becomes more complicated than I initially thought... is
that the kind of mess you were thinking of? :-)

-- 
Martin Geisler

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Relaxing rules on slice comparison: would it make sense?

2016-07-01 Thread Martin Geisler
On Fri, Jul 1, 2016 at 3:15 AM, Chad  wrote:
> No, it's actually fine. You are comparing values.
>
> A slice being a struct under the hood, for slices you would compare the
> structs (slice headers)

Yes, when you remember that a slice is a just a small struct with a
pointer and some bookkeeping information (length, capacity), then you
can compare two slices easily. So with

  a := []int{10, 20, 30}
  b := a[:]

then a == b would be fast: simply compare the pointers and the
bookkeeping information. Direct value equality between the structs
gives you the expected and correct answer.

But what about

  []int{10, 20} == []int{10, 20}

where the two slices refer to different underlying arrays? I think you
argue that this comparison should be false?

I would hope that slices from different underlying arrays could be
compared for equality based on their values, just like strings can.
Two strings (that are not slices from the same original string) can be
compared for equality just fine. I hope Go takes the shortcut when the
strings refer to the same memory and otherwise does the slower
per-byte comparison. The same could perhaps apply to slices in
general.

-- 
Martin Geisler

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Relaxing rules on slice comparison: would it make sense?

2016-07-01 Thread Martin Geisler
On Fri, Jul 1, 2016 at 12:48 PM, Chad  wrote:
> On Friday, July 1, 2016 at 12:11:43 PM UTC+2, Martin Geisler wrote:
>>
>> On Fri, Jul 1, 2016 at 3:15 AM, Chad  wrote:
>> > No, it's actually fine. You are comparing values.
>> >
>> > A slice being a struct under the hood, for slices you would compare the
>> > structs (slice headers)
>>
>> Yes, when you remember that a slice is a just a small struct with a
>> pointer and some bookkeeping information (length, capacity), then you
>> can compare two slices easily. So with
>>
>>   a := []int{10, 20, 30}
>>   b := a[:]
>>
>> then a == b would be fast: simply compare the pointers and the
>> bookkeeping information. Direct value equality between the structs
>> gives you the expected and correct answer.
>>
>> But what about
>>
>>   []int{10, 20} == []int{10, 20}
>>
>> where the two slices refer to different underlying arrays? I think you
>> argue that this comparison should be false?
>
>
> Yes. And it is. A slice is not an array. Or an open-ended array.

Right, a slice is just view into an array :-)

I was hinting at the (lack of) symmetry with how strings work.

Two strings that share no underlying memory can compare equal, so I
think it would be reasonable if equality between slices followed the
same principle. Put differently, strings are "magic" and don't follow
normal rules for comparison, in particular, they don't use direct
value comparison. Here I'm assuming that

  https://golang.org/pkg/reflect/#StringHeader

shows us how strings are implemented: a small struct with a pointer
and a length. If string comparison were to use value semantics, a and
b could not compare equal in this little example

  a := "hello world"
  b := make([]byte, len(a))
  os.Stdin.Read(b)

since the pointer in a would differ from the pointer in b. Yet a == b
is true when you enter "hello world" :-) So we see the magic slip
through the cracks...

Given that, one could argue that it would be consistent to have
[]int{1} == []int{1} be true -- it's just yet another exception to the
rule that things are compared by value. It's not super pretty, though,
but I my opinion the illusion of prettyness has already been broken
with how some builtin types get special treatment here and there.

-- 
Martin Geisler

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Relaxing rules on slice comparison: would it make sense?

2016-07-01 Thread Martin Geisler
On Fri, Jul 1, 2016 at 12:52 PM, Chad  wrote:
> However, that it's a valid point you raise (re strings)
> But that's exactly the reason for which, someone would probably ask whether
> a string is a reference type or a value type.
>
> This could probably made clearer in the documentation.

I keep seeing references (hah!) to this concept of a "reference type"
:-) However, I just tried searching the language spec and Effective Go
and there doesn't seem to be such a concept defined in those
documents. Effective Go talks about slices and maps having
"references" to some underlying data, but I don't think it says that
maps and slices themselves are "reference types".

So my understanding is that there is no such concept in Go. Instead
there are structs and pointers -- maps and slices are builtin types,
implemented as small structs that points to larger pieces of data.
When you pass either to a function, you end up copying the struct --
the normal value semantic we all know so well. Copying the struct is
fine since they're small: a slice is a pointer and two ints, I'm
unsure how a map looks like but I hope it's similarly sized.

I'm very new to Go, so please let me know if I'm missing anything?

-- 
Martin Geisler

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Relaxing rules on slice comparison: would it make sense?

2016-07-02 Thread Martin Geisler
On Fri, Jul 1, 2016 at 4:01 PM, Chad  wrote:
>
>
> On Friday, July 1, 2016 at 3:44:10 PM UTC+2, Martin Geisler wrote:
>>
>> On Fri, Jul 1, 2016 at 12:52 PM, Chad  wrote:
>> > However, that it's a valid point you raise (re strings)
>> > But that's exactly the reason for which, someone would probably ask
>> > whether
>> > a string is a reference type or a value type.
>> >
>> > This could probably made clearer in the documentation.
>>
>> I keep seeing references (hah!) to this concept of a "reference type"
>> :-) However, I just tried searching the language spec and Effective Go
>> and there doesn't seem to be such a concept defined in those
>> documents.
>
>
> I think it should. It is mentioned here however
> https://blog.golang.org/go-maps-in-action

You're right, that article calls maps, slices and pointers "reference types".

I feel that is a little unfortunate since it muddles the picture and
makes the implementation more obscure. I would have been happy to have
been told right from the start that a slice is a small struct, small
enough that you can pass it by value instead of with a pointer. That
allows me to build a mental model in terms of other Go constructs.

It might very well be that a slice isn't implemented *exactly* like a
struct, but if the mental picture of a struct explains the behavior
and performance characteristics, then it doesn't matter if the
compiler somehow cheats here and there when implementing the type.

> Without that, one of the first instinct of beginning programmers is often to
> create pointers to slices.
> I feel that, more clarifications about this area of the language would help
> a lot instead.
>
> This is also a terminology of PLT that exists in other languages but as
> usual, one has to be careful about the implementation false friends.

I agree, "reference type" is a widely used term. I think I prefer to
use it only for pointer types such as *int, *byte and so on.
Everything else would be value types, including string, map[int]int,
[]float and other special builtin types.

When talking about equality, the language defines some of these types
as comparable, with per-type rules for how == is implemented. Relaxing
the rules to allow comparing slices (by pair-wise comparison of the
values in the slices) seems like a natural thing to do for me. It
would make slice comparison work like string comparison works
currently. So the rule for comparison would not even be new or strange
-- just a natural extension of what is already there.

You could probably also make slices (and arrays) ordered, provides the
elements themselves are ordered. That would work the same way strings
work today: lexicographic ordering based on the elements.

-- 
Martin Geisler

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Relaxing rules on slice comparison: would it make sense?

2016-07-02 Thread Martin Geisler
On Sat, Jul 2, 2016 at 6:19 AM, Matt Harden  wrote:
> Conceptually, the value of a string is the sequence of bytes it contains,
> just like an array of bytes. It doesn't matter that the implementation of
> strings looks more like a slice internally. On the other hand the value of a
> slice is a reference to (part of) an underlying array, together with a
> length. In all cases == should compare values. I agree that it would be
> confusing to make == work for slices, because many people, myself included
> would intuitively want that to compare the contents of the slice (values
> from the underlying array) rather than the value of the slice itself which
> is essentially 3 pointers.

But what if you define slice comparison to be by value of the underlying array?

That would make []int{1} == []int{1} be true, despite the slices
pointing to different arrays.

It would probably also mean that

  a := make([]int, 0, 5)
  b := make([]int, 0, 7)

are equal since the two slices have equal elements, despite having
different capacities.

Defining slice comparison to be comparison on the values would mean
that you cannot tell if the slices refer to different underlying
arrays. Maybe you can use the reflect package to get hold of it
somehow and compare the pointers yourself.

Speaking of reflect, I just realized that what I'm proposing is to
define == as reflect.DeepEqual for slices. It seems to do everything
I'm talking about: slices from different arrays can compare equal, it
short-circuits in clever ways by looking at the length and noticing
when the slices refer to the same point in the same array.

> One nice feature of the current gc compiler AIUI is that it will avoid a
> copy in some circumstances when you convert a byte slice to a string and
> immediately use it as a map key. This helps with using []byte values to
> index into maps, but doesn't help when the []byte is part of a larger
> structure you want to use as a key.

Yes, I read about this optimization. In my opinion that is a great
optimization -- and the kind of optimization the compiler can do when
it knows the implementation of map and string. However, it shouldn't
be part of the language specification.

-- 
Martin Geisler

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Relaxing rules on slice comparison: would it make sense?

2016-07-03 Thread Martin Geisler
Hi Chad,

On Sat, Jul 2, 2016 at 10:43 AM, Chad  wrote:
>
> On Saturday, July 2, 2016 at 10:23:04 AM UTC+2, Martin Geisler wrote:
>>
>> On Fri, Jul 1, 2016 at 4:01 PM, Chad  wrote:
>>>
>>> On Friday, July 1, 2016 at 3:44:10 PM UTC+2, Martin Geisler wrote:
>>>> I keep seeing references (hah!) to this concept of a "reference type"
>>>> :-) However, I just tried searching the language spec and Effective Go
>>>> and there doesn't seem to be such a concept defined in those
>>>> documents.
>>>
>>> I think it should. It is mentioned here however
>>> https://blog.golang.org/go-maps-in-action
>>
>> You're right, that article calls maps, slices and pointers "reference
>> types".
>>
>> I feel that is a little unfortunate since it muddles the picture and
>> makes the implementation more obscure. I would have been happy to have
>> been told right from the start that a slice is a small struct, small
>> enough that you can pass it by value instead of with a pointer. That
>> allows me to build a mental model in terms of other Go constructs.
>
>
> A struct is considered a reference type if at least one of the field
> *points* to another object. (i.e. holds a reference to another object).
> https://en.wikipedia.org/wiki/Reference_type

That is not how I've seen the word "reference type" used and I don't
think that's what the Wikipedia article tries to say. As I read it, it
says that a language like C++ has some types that are value types
(int, bool, structs, classes) and some types that are reference types
(&int, &bool).

As far as I know, reference types only show up in function and method
signatures in C++. It specifies that the argument should be passed by
reference instead of being copied like normal -- the compiler will
typically handle this by changing the &int parameter to a *int (int
pointer) parameter, insert & at the call site and * inside the
function. So the reference type gives you almost the same as a
pointer, but without the explicit dereferencing.

Other languages like Java and Python have reference types too: in
Java, all object instances are reference types. So when you pass an
object to a method, you pass a reference and modifications done in the
method are visible after the call.

I believe C# allows you to specify if you want a class to be a
reference type or a value type. The Wikipedia article says you use
"struct" for value types and "class" for reference types. This matches
how "struct" gives you a value type in Go.

The mail from as.utf8 points to this discussion (thanks!):

  https://groups.google.com/forum/m/#!topic/golang-dev/926npffb6lA

which points to this issue:

  https://github.com/golang/go/issues/5083

They make it pretty clear that people have been trying to remove the
use of "reference type".

> It's clearer. "small struct" would not be explicit enough nor true.
> I think that slices require typically more documentation effort to clarify
> what they are. Then, the issue of comparability will be obvious.
>
> There are user-defined reference types too.
>
> type Foo struct{
>name string
>data *[192]byte
> }
>
> That would be a reference type. This one is comparable.

I don't think that's a reference type in the usual sense of the word.
The basic test for me is what happens when you pass a Foo to a
function:

  func ChangeTheFoo(f Foo) {
  f.name = "changed"
  }

if the name field is changed after the call, then Foo is indeed a
reference type. However, it won't be changed in Go since the Foo
struct is copied when the function is called and this is why I say
that Foo is not a reference type. That is true of all structs in Go.

-- 
Martin Geisler

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Append to slice... what happens?

2016-07-03 Thread Martin Geisler
Hi Rogue,

On Sun, Jul 3, 2016 at 5:13 PM,   wrote:
> It seems i can't edit my original post so:

While it may not look like it from if you use the Google Groups
interface, emails are being sent out in the background when you post
to golang-nuts. So there's no way to edit anything, you can only send
follow up messages.

> There should be "So pointer from slice b is pointing to new array"  instead
> of "So pointer from slice b is pointing to new slice"

Yes, that is correct.

> W dniu niedziela, 3 lipca 2016 17:05:06 UTC+2 użytkownik rog...@gmail.com
> napisał:
>>
>> Thx Ian,
>>
>> So basically it's because we allocate new array in version without cap,
>> right?  Because it outgrows current cap. So pointer from slice b is pointing
>> to new slice (i've checked they have different addresses for first element)
>> different from a.
>> And in version with cap=10 we still append to the same array as there is
>> no relocation, that's why we have same elements in both slices (they point
>> to the same array). Right?

You got it!

The capacity of the slice tells you how much more room there is beyond
the length. If you set the capacity to the length, the next call to
append will conclude that there's no space in the underlying array and
proceed to allocate a new array, copy the data from the slide to the
new array, and return a slice into this new array. This breaks the
"link" between the old and new slices since they now refer to
different arrays.

-- 
Martin Geisler

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Error vs. Panic: Should functions like strings.Repeat return an error value?

2016-07-07 Thread Martin Geisler
Hi Dave

On Thu, Jul 7, 2016 at 2:08 AM, Dave Cheney  wrote:
> If this function panic'd then people who raise issues to make it not panic,
> or they would work around it with recover(), both of which would be in less
> tested code paths.

As a newcomer to Go, it's fun to me that you call using recover a
"work around". Throwing and catching an exception is the bread and
butter of handling errors in all other languages I know :-)

Having to test for a variable being non-nil and manually returning it
up the call chain is very very clunky and yet it's seen as the
ideomatic and good way in Go. That's very strange to me, and from
reading about Go around the net, strange to a lot of people.


-- 
Martin Geisler

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Error vs. Panic: Should functions like strings.Repeat return an error value?

2016-07-07 Thread Martin Geisler
On Thu, Jul 7, 2016 at 9:44 AM, Dave Cheney  wrote:
> Hi Martin,
>
> Go doesn't have exceptions, it really doesn't. Some people like to pretend
> that panic/recover are exceptions, but really they are not [1].

Yes, sure, they're called something else :-) But they behavior matches
what you get with exceptions in other langauges: stack-unwinding until
you find a handler that deals with the error. True, in Go you need to
manually check (with a type switch, maybe) that you can handle the
error after you call recover() -- that's normally part of the syntax
in other languages.

> 1. https://golang.org/doc/faq#exceptions

-- 
Martin Geisler

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] parse.ParseExpr("var a = 9") returns error "expected operand, found 'var'"

2016-08-11 Thread Martin Schnabel
On Do, 2016-08-11 at 03:55 -0700, Jason E. Aten wrote:
> I'm trying to use parser.ParseExpr. I'm thinking "var a = 9" is a
> valid expression, but ParseExpr returns an error:
> 
hi jason, 
a variable declaration is a statement and not an expression.

when in question on this matters take a look at the spec.it is very
well written and readable as far as language specs go.

https://golang.org/ref/spec
i hope this helps

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] parse.ParseExpr("var a = 9") returns error "expected operand, found 'var'"

2016-08-11 Thread Martin Schnabel

> Pedantically, perhaps this is a statement rather than an expression.
> That begs the question, is there anyway to parse single statements
> (using go/parse)?
> 
sorry haven't read the whole email.
just write your own. use a simple package file skeleton and use
ParseFile.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] runtime: split stack overflow

2016-08-18 Thread martin . strenge
Hi,

i'm trying to replace a Go signal handler by a C signal handler and try to 
call the stored Go handler inside that C handler. It works well on Linux, 
but on Darwin I receive a "runtime: split stack overflow" exception. Is 
that supposed to work on OSX?

Thanks!
Martin

Example program:

package main


/*

#define _XOPEN_SOURCE 700

#include 

#include 

#include 

#include 


static struct sigaction go_handler;


static void signal_handler(int sig, siginfo_t* info, void* ctx) {

printf("called %d\n", sig);

if (go_handler.sa_flags & SA_SIGINFO) {

go_handler.sa_sigaction(sig, info, ctx);

} else {

go_handler.sa_handler(sig);

}

}


void install_signal_handler() {

struct sigaction action;

memset(&action, 0, sizeof(action));

action.sa_sigaction = signal_handler;

action.sa_flags = SA_SIGINFO | SA_RESTART |SA_ONSTACK;

sigemptyset(&action.sa_mask);

sigaction(SIGSEGV, &action, &go_handler);

}

*/

import "C"


func init() {

C.install_signal_handler()

}


func main() {

var x *int

*x = 0

}

Output on OSX:

called 11

runtime: newstack sp=0xc420009a40 stack=[0xc42004c000, 0xc42004dfc0]

morebuf={pc:0x7fff8ef2c52a sp:0xc420009a50 lr:0x0}

sched={pc:0x40340e0 sp:0xc420009a48 lr:0x0 ctxt:0x0}

runtime: gp=0xc421a0, gp->status=0x2

 runtime: split stack overflow: 0xc420009a40 < 0xc42004c000

fatal error: runtime: split stack overflow


runtime stack:

runtime.throw(0x406bdf3, 0x1d)

/usr/local/go/src/runtime/panic.go:566 +0x95

runtime.newstack()

/usr/local/go/src/runtime/stack.go:1004 +0x5f4

runtime.morestack()

/usr/local/go/src/runtime/asm_amd64.s:366 +0x7f


goroutine 1 [running]:

runtime.sighandler(0xc42004df90, 0x0, 0x0, 0x0)

/usr/local/go/src/runtime/signal_amd64x.go:44 fp=0xc420009a50 
sp=0xc420009a48


goroutine 17 [syscall, locked to thread]:

runtime.goexit()

/usr/local/go/src/runtime/asm_amd64.s:2086 +0x1


-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] runtime: split stack overflow

2016-08-19 Thread martin . strenge

>
> It appears as though the signal handler is somehow not running on the 
> alternate signal stack. I don't know why that would be, though. I 
> have no other explanation. You'll have to debug it. 
>
> I can see by the stack pointers, that the alt stack is used on both, Linux 
and Darwin. But I'm not familiar enough with the internals to debug why it 
calls morestack/newstack.
 

> What you are doing seems rather dubious but I can't think of any 
> reason why it shouldn't work. 

Maybe you can shortly explain, why you think its dubious. I am calling a 
shared C lib from Go, that spawns its own threads, and also calls back into 
Go. According to the signal package documentation, registering a C signal 
handler seems to be the only way to handle crashes in foreign threads. As I 
want all non-Go threads to be dumped as well in case of a signal raised in 
Go, I register the C handlers after the Go handlers. And instead of raising 
the signal again, I call the Go handler directly to keep the original 
mcontext. Do you think there's a better way to do it?

Thanks!
Martin

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Practical Golang: Building a simple, distributed one-value database with Hashicorp Serf

2017-01-30 Thread Jacob Martin
A tutorial to build a simple distributed one-value database (as the title 
sais): 
https://jacobmartins.com/2017/01/29/practical-golang-building-a-simple-distributed-one-value-database-with-hashicorp-serf/
Please comment with feedback!

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Wrestling with Mingw64 on Windows

2017-01-30 Thread Jacob Martin
I'd advice you to use bash on Ubuntu on windows to compile cgo programs on 
windows. It's easy to use and works.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Appending a path to an URL

2017-01-31 Thread Martin Gallagher
Is this what you want: https://play.golang.org/p/BW96Bk_sqJ

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Appending a path to an URL

2017-01-31 Thread Martin Gallagher
Is this what you want: https://play.golang.org/p/BW96Bk_sqJ

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Why does my program hang?

2017-02-26 Thread Martin Schnabel

> i--

by decrementing i in the case of i > 0 and a non graphic rune you run 
the loop possibly indefinitely


--
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Why does my program hang?

2017-02-26 Thread Martin Schnabel



big.NewInt(int64(unsafe.Sizeof(char
also this line will will define the maximum of the random number which 
is 4. so all the random runes are 0 <= r <= 4 which are all not graphic.


is this more what you expect https://play.golang.org/p/61hzuNj1nF

it uses append instead of the decrementing i and math/rand instead of 
crypto/rand


--
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Gracefully Shutdown File Server

2017-03-14 Thread Martin Schnabel
i looked into the issue and it seems the problem is the early exit from 
the program. this should work https://play.golang.org/p/LdXUYyzDxY


On 14.03.2017 06:30, amk...@gmail.com wrote:

Maybe this is a bug or need clear documentation about this.

I've filed a bug report here: https://github.com/golang/go/issues/19541

Andrew

--
You received this message because you are subscribed to the Google
Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to golang-nuts+unsubscr...@googlegroups.com
.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Issue building binaries using cgo on macOS Sierra 10.12.4

2017-03-28 Thread martin . ostrovsky
Hello,

Upgraded my mac to 10.12.4 yesterday, tried to run a binary built using 
go1.8. I immediately get Killed: 9 as output.

The binary includes many C/C++ libraries via cgo but everything was fine 
under 10.12.3

I then built the binary using -ldflags -s and that was OK. 

I saw a similar issue on github  
a while back but that had to do with codesign, this doesn't. 

Let me know what other info I can provide to help track down the issue or 
if I should open an issue on github?

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] How to point to pointer struct

2017-05-23 Thread alex martin
Hi 
I have this structure in C created by rsl libray 

typedef struct {
  Radar_header 
 h;
  Volume  
**v;   
} Radar;


Using cgo i read the structure with 


Radar *readRad(char *fname) {
  return RSL_anyformat_to_radar(fname, NULL);
}


and call this function in go 

RPointer := C.readRad(C.CString(os.Args[1]))


and i see the structure

with fmt.Printf("%T",RPointer)=>  *main._Ctype_struct___0

with fmt.Printf("%+v",RPointer)   =>  &{h:{} _:[0 0 0 0] *v:0xe59b60*}


The field is a **C.Volume pointer.

The question is: it's  possible with Golang list all C.Volume's struct pointed ?


like this   


for i := 0; i < int(RPointer.h.nvolumes); i++ {

pv := *RPointer.v[i]
fmt.Printf("\nVOLUME Sweep %+v\n", *pv.sweep)
}


the exit is type **C.struct___2 does not support indexing


I tried with unsafe.Pointer using 



*puint1 := unsafe.Pointer(RPointer.v)*


*sizep := unsafe.Sizeof(RPointer.v)fmt.Printf("\npuint [%+v] -> + sizeoff 
[%+v]\n", puint1, unsafe.Pointer(uintptr(puint1)+sizep))*


and printf is puint [0xe59b60] -> + sizeoff [0xe59b68]


there is a casting like this 


volume2 := (*C.Volume)(*unsafe.Pointer(uintptr(puint1) + sizep))


Thanks

Alex




-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: How to point to pointer struct

2017-05-23 Thread alex martin
Thank you
problem solved with your suggestion.

var PSlv (**C.Volume) = RPointer.v
lenght := int(RPointer.h.nvolumes)
sliceV := (*[1 << 30](*C.Volume))(unsafe.Pointer(PSlv))[:lenght:lenght]

the result is  []*C.Volume correct, where the pointer is null the slice 
value is nil

Alex

On Tuesday, May 23, 2017 at 3:42:26 PM UTC+2, Pablo Rozas Larraondo wrote:
>
> I'm thinking about the possibility of having something like [][]Volume in 
> Go. Do you know the size or number of Volumes in your struct?
>
> There's an example of converting **char into []string that might be useful:
> https://stackoverflow.com/questions/36188649/cgo-char-to-slice-string
>
>
>
> On Tuesday, May 23, 2017 at 8:39:12 PM UTC+10, alex martin wrote:
>>
>> Hi 
>> I have this structure in C created by rsl libray 
>>
>> typedef struct {
>>   Radar_header h;
>>   Volume **v;   
>> } Radar;
>>
>>
>> Using cgo i read the structure with 
>>
>>
>> Radar *readRad(char *fname) {
>>   return RSL_anyformat_to_radar(fname, NULL);
>> }
>>
>>
>> and call this function in go 
>>
>> RPointer := C.readRad(C.CString(os.Args[1]))
>>
>>
>> and i see the structure
>>
>> with fmt.Printf("%T",RPointer)=>  *main._Ctype_struct___0
>>
>> with fmt.Printf("%+v",RPointer)   =>  &{h:{} _:[0 0 0 0] *v:0xe59b60*}
>>
>>
>> The field is a **C.Volume pointer.
>>
>> The question is: it's  possible with Golang list all C.Volume's struct 
>> pointed ?
>>
>>
>> like this   
>>
>>
>> for i := 0; i < int(RPointer.h.nvolumes); i++ {
>>
>>  pv := *RPointer.v[i]
>>  fmt.Printf("\nVOLUME Sweep %+v\n", *pv.sweep)
>>  }
>>
>>
>> the exit is type **C.struct___2 does not support indexing
>>
>>
>> I tried with unsafe.Pointer using 
>>
>>
>>
>> *puint1 := unsafe.Pointer(RPointer.v)*
>>
>>
>> *sizep := unsafe.Sizeof(RPointer.v)fmt.Printf("\npuint [%+v] -> + sizeoff 
>> [%+v]\n", puint1, unsafe.Pointer(uintptr(puint1)+sizep))*
>>
>>
>> and printf is puint [0xe59b60] -> + sizeoff [0xe59b68]
>>
>>
>> there is a casting like this 
>>
>>
>> volume2 := (*C.Volume)(*unsafe.Pointer(uintptr(puint1) + sizep))
>>
>>
>> Thanks
>>
>> Alex
>>
>>
>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Installing a package

2017-07-02 Thread Martin Spasov
Does that mean that it is not possible to chose where you want to 
install the pkg ?
On Mon, Jul 3, 2017 at 12:00 AM, Matt Harden  
wrote:

I believe it's the first folder in GOPATH, not the last.

On Sun, Jul 2, 2017 at 1:21 PM  wrote:
From what I found here when you install packages with go get, they 
get installed in the last folder of your GOPATH env variable. Mine 
is ''/home/Documents/GoProjects'' but the installed packages end up 
in ''/home''. It is probably a stupid question, but I honestly do 
not know what is wrong here.

--
You received this message because you are subscribed to the Google 
Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, 
send an email to golang-nuts+unsubscr...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.




--
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Installing a package

2017-07-02 Thread Martin Spasov
hey, my src, pkg and bin directories are in the GoProjects folder which 
is the last one in the path
On Mon, Jul 3, 2017 at 12:17 AM, Justin Israel  
wrote:

I think two different things are being described here.

GOPATH=/path/to/src:/path/to/src2

The first path should be the one that gets the pkg install location.


On Mon, Jul 3, 2017, 9:02 AM Martin Spasov  
wrote:
Does that mean that it is not possible to chose where you want to 
install the pkg ?
On Mon, Jul 3, 2017 at 12:00 AM, Matt Harden  
wrote:

I believe it's the first folder in GOPATH, not the last.

On Sun, Jul 2, 2017 at 1:21 PM  wrote:
From what I found here when you install packages with go get, they 
get installed in the last folder of your GOPATH env variable. Mine 
is ''/home/Documents/GoProjects'' but the installed packages end 
up in ''/home''. It is probably a stupid question, but I honestly 
do not know what is wrong here.

--
You received this message because you are subscribed to the Google 
Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, 
send an email to golang-nuts+unsubscr...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
You received this message because you are subscribed to the Google 
Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, 
send an email to golang-nuts+unsubscr...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.




--
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go install recreates .a files that are already present in the pkg directory

2017-07-14 Thread Martin Spasov
I am getting *build ID mismatch* and here 
 I see that it means that 
something has changed in the package, but I have not modified it in any 
way. Below is the whole application :

package main

import (
   "os"

"github.com/gotk3/gotk3/gtk"
)

func main() {
   gtk.Init(&os.Args)
   //Main Window Configuration
   window, err := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
   if err != nil {
   panic(err)
   }
   window.SetTitle("Notes")
   window.SetSizeRequest(1000, 800)
   window.Connect("destroy", gtk.MainQuit)

window.ShowAll()
   gtk.Main()
}



On Friday, July 14, 2017 at 4:55:18 PM UTC+3, Ian Lance Taylor wrote:
>
> On Fri, Jul 14, 2017 at 6:27 AM,  > 
> wrote: 
> > Hey, 
> > 
> > I formatted my OS and now i am having a problem that was not present 
> before. 
> > I am trying to use gotk3 and when i try to install it i run 
> > 
> > go install -v -tags gtk_3_18 
> > 
> > It used to only rebuild (correct me if im using a wrong verb here) the 
> > main.go file as it was the only one modified, but now it rebuilds the 
> gtk 
> > and gdk packages every time. I checked and the .a files are present in 
> the 
> > package dir. Does anyone have any idea why this is happening ? 
>
> Try `go list -f '{{ .StaleReason }}' PKG` to see why it is rebuilding a 
> package. 
>
> Ian 
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go install recreates .a files that are already present in the pkg directory

2017-07-14 Thread Martin Spasov
I am getting *build ID mismatch* and here 
 I see that it means that 
something has changed in the package, but I have not modified it in any 
way. Below is the whole application :

package main

import (
   "os"

"github.com/gotk3/gotk3/gtk"
)

func main() {
   gtk.Init(&os.Args)
   //Main Window Configuration
   window, err := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
   if err != nil {
   panic(err)
   }
   window.SetTitle("Notes")
   window.SetSizeRequest(1000, 800)
   window.Connect("destroy", gtk.MainQuit)

window.ShowAll()
   gtk.Main()
}

On Friday, July 14, 2017 at 4:55:18 PM UTC+3, Ian Lance Taylor wrote:
>
> On Fri, Jul 14, 2017 at 6:27 AM,  > 
> wrote: 
> > Hey, 
> > 
> > I formatted my OS and now i am having a problem that was not present 
> before. 
> > I am trying to use gotk3 and when i try to install it i run 
> > 
> > go install -v -tags gtk_3_18 
> > 
> > It used to only rebuild (correct me if im using a wrong verb here) the 
> > main.go file as it was the only one modified, but now it rebuilds the 
> gtk 
> > and gdk packages every time. I checked and the .a files are present in 
> the 
> > package dir. Does anyone have any idea why this is happening ? 
>
> Try `go list -f '{{ .StaleReason }}' PKG` to see why it is rebuilding a 
> package. 
>
> Ian 
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Weird benchmark results for seemingly identical functions

2020-06-22 Thread Martin Schnabel
Let me quickly point out that your logic is inverted in the second code 
snippet because you break on the condition. That is most likely the 
reason for the difference. I guess the second example exits on the first 
iteration.


for pos := 0; true; pos++ {
   if pos < suffixLen && pos < previousSuffixLen {
 continue
   }
   break
}

On 22.06.20 14:15, Yonatan Ben-Nes wrote:

Hi,

I'm encountering a weird issue which I fail to explain. It boils down to 
2 almost identical functions which give wildly different benchmark results.


The difference between the functions is that at the slow func there is a 
for loop like this:

for pos := 0; pos < suffixLen && pos < previousSuffixLen; pos++ {
}

While at the fast func the loop is like this:
for pos := 0; true; pos++ {
if pos < suffixLen && pos < previousSuffixLen {
break
}
}
* do note that the check at both versions is the same.

Other than that the functions are identical but when I benchmark them I get:
$ go test -bench=Weird .
goos: linux
goarch: amd64
BenchmarkWeirdFast-4 280394 3602 ns/op
BenchmarkWeirdSlow-4 1866 618953 ns/op

It's extra weird since getting the condition check into the loop should 
be the slower form, or at least that what I intuitively thought.


Also, the extra time cost is divided between the loop section and an 
append function call which run immediately at the start of the function 
and is not connected in any way to the for loop.
And it's extra weird as the append cost also get smaller if instead of 
reading the test text from a file I just declare a string variable with 
the same text for the benchmark (mind you that I b.ResetTimer() after 
doing either of those options).


I attached the files to this message as they will make everything more 
clear and I also added comments describing what happen at the right points.


I'm using Ubuntu 18.04 and go is version 1.14.2, and I also checked it 
on a GCP compute engine and got the same results.


Any thoughts will be much appreciated as I'm totally confused here! :)

--
You received this message because you are subscribed to the Google 
Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to golang-nuts+unsubscr...@googlegroups.com 
.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/3cf40b00-96ec-42a6-8093-7f1c27bfd93fn%40googlegroups.com 
.


--
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/d661fbea-ca23-dd55-0f45-b3c10cefd9aa%40mb0.org.


[go-nuts] [generics] Trying to use generics as enums

2020-07-05 Thread Martin Tournoij
Hi there,

I played around a bit with the go2go playground today; I was wondering
how useful it would be to implement enums.

Whether using generics like this is a good idea or not is a different
discussion, it's just an interesting thing to experiment with and see
how far I could get.

I thought it might be useful to share my experience; I ran in to several
errors I couldn't really make sense of. This is probably a failure of
understanding on my part 😅 But I did spend quite some time in front of
the draft specification trying to figure this out.

All code was run on the "go2go" playground today.

Note I am not usually subscribed to the golang-nuts mailing list, and
have not read all of the discussions (using Google groups to browse
archives is a but of a pain), so apologies if this duplicates any
previous feedback.

Hope it helps.

Cheerio,
Martin

---

First, let's define my types:

type (
Banana  struct{ banana struct{} }
Coconut struct{ coconut struct{} }

Fruit interface {
type Banana, Coconut
}
)

And then adds a function which only accepts a "Fruit" enum value:

func show(type enum Fruit)(fruit enum) {
switch (interface{})(fruit).(type) {
case Banana:
fmt.Println("That's just bananas!")
case Coconut:
fmt.Println("I've got a lovely bunch of coconuts!")
default:
fmt.Println("Yeah nah")
}
}

func main() {
show(Banana{})
show(Coconut{})
}

The type switch is somewhat ugly and has limitations, as mentioned in
the design document, but it works for this case.

Moving on, I wanted to add a function which accepts multiple fruits,
which gives an error:

// type Coconut of (Coconut literal) does not match inferred type 
Banana for enum
func showAll(type enum Fruit)(fruits ...enum) {
for _, f := range fruits {
show(f)
}
}

In the spec it actually mentioned that:

> No variadic type parameters. There is no support for variadic type
> parameters, which would permit writing a single generic function that
> takes different numbers of both type parameters and regular
> parameters.

So looks like that's not supported, fait enough, but the error message
is a bit confusing. Second try:

func showAll(type enum Fruit)(fruits []enum) {
for _, f := range fruits {
show(f)
}
}

func main() {
// Fruit does not satisfy Fruit (interface{type Banana, 
Coconut} not found in Banana, Coconut)
showAll([]Fruit{Banana{}})
}

I'm not entirely sure what to make of that error 🤔

Adding a function which returns a Fruit also proved difficult:

// cannot use (Banana literal) (value of type Banana) as enum value in 
return statement
func getBanana(type enum Fruit)() enum {
return Banana{}
}

// cannot convert (Banana literal) (value of type Banana) to enum
func getBanana(type enum Fruit)() enum {
return enum(Banana{})
}

I'm not entirely sure why this doesn't work 🤔 It does work when you're
doing something like:

// getBanana(Banana{})
func getBanana(type enum Fruit)(v enum) enum {
return v
}

But this is a fairly useless function :-)

I also wasn't able to create a list of all Fruit types:

// undefined: Fruit
var FruitList = []Fruit{Banana{}, Coconut{}}

func FruitList(type enum Fruit)() enum {
// cannot use (Banana literal) (value of type Banana) as enum 
value in array or slice literal
return []enum{Banana{}, Coconut{}}
}

// function type must have no type parameters
var FruitList = func(type enum Fruit)() []enum {
return []enum{}
}

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/f7c19f07-809c-4cb2-9815-6d9a1b88d5f9%40www.fastmail.com.


Re: [go-nuts] Busy synchronization wait seems to behave differently on 1.13 and 1.14

2020-07-25 Thread Martin Schnabel
I am not certain but the reason probably is the change to go-routine 
preemption in 1.14. From https://golang.org/doc/go1.14#runtime


…
Goroutines are now asynchronously preemptible. As a result, loops 
without function calls no longer potentially deadlock the scheduler or 
significantly delay garbage collection. This is supported on all 
platforms except windows/arm, darwin/arm, js/wasm, and plan9/*.

…

Before that busy loops in go routines needed a function call to be 
preemptible.


Hope that helps!

On 25.07.20 09:38, Groups Discussion wrote:

Hi all,

writing a stress test case for one of my apps I noticed a very strange 
thing: my test case works well on go 1.14 but it doesn't work on go 1.13.


I wrote a minimal reproducer

https://play.golang.org/p/uHkKMINncUB

to make it work on go 1.13 I have to add the sleep at line 41. In Go 
playground it timeouts, without sleeping, even on 1.14.6, on real hw I 
tried it 1000 times, without sleeping, with no issues on go 1.14 while 
it fails every time on go 1.13 (tested 1.13.12 and 1.13.14)


I'm just curious to understand if there is something wrong with my code, 
even if it is not idiomatic, and if a such busy synchronization wait is 
expected to work in 1.14 only


thanks

--
You received this message because you are subscribed to the Google 
Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to golang-nuts+unsubscr...@googlegroups.com 
.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/0dbc0ba3-0b4d-42bd-8edf-076e92507251o%40googlegroups.com 
.


--
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/caaa6f5f-033e-2cea-7615-7c2072c2129a%40mb0.org.


  1   2   >