Re: [go-nuts] Where are the dependencies saved when we use go mod

2018-10-08 Thread Wagner Riffel
> Where is the dependent github.com/stretchr/testify/assert downloaded - I dont 
> see it downloaded any where.
it still download physically, it's under $GOPATH/pkg/mod
On Mon, Oct 8, 2018 at 5:55 PM pprasanthi via golang-nuts
 wrote:
>
> I followed below steps to run tests in go mod. In this process I had few 
> questions that needs clarification.
>
> cd /tmp/gomodtry/tests/src/hello/hello_test.go
> package tests
>
> import (
> “github.com/stretchr/testify/assert”
> “os”
> “testing”
> )
>
> func GetEnv(key string, fallback string) string {
> envVariable := os.Getenv(key)
> if envVariable == “” {
> return fallback
> }
> return envVariable
> }
>
> func TestHello(t *testing.T) {
> val := GetEnv(“check”, “ok”)
> assert.Equal(t, “ok”, val, “val is not equal to ok”)
> }
>
> func TestHello1(t *testing.T) {
> val := GetEnv(“check”, “ok”)
> assert.Equal(t, “ok”, val, “val is not equal to ok”)
> }
>
> export GO111MODULE=on
>
> go test ./…
> This created go.mod and go.sum files in cd /tmp/gomodtry/ location
> When I executed go test ./… -v again , it executed the tests successfully.
>
> QUESTION:
>
> Where is the dependent github.com/stretchr/testify/assert downloaded - I dont 
> see it downloaded any where.
> Before go mod concept when we set GOPATH and then go get dependency, it used 
> to download physically.
> Can you please explain how the test is resolving dependency without the 
> physical presence of dependent library.
>
> In previous version, when we go get dependencies, some times we used to get 
> 500 error because the host where dependency exists will be down temporarily.
> Do we still face this kind of issues with go mod concepts? How is it handled? 
> [we did not like vendoring of dependencies, so we end up doing go get for 
> every test run, which made of tests runs unstable when the host went 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.

-- 
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] Unable to view go-review.googlesource.com on Firefox 60.x

2018-11-16 Thread Wagner Riffel
I'm either on 60.3 under linux and it's working fine.
On Fri, Nov 16, 2018 at 1:25 PM Sam Whited  wrote:
>
> FWIW, I'm on 65 nightly and haven't noticed any problems (including back when 
> 63 was the nightly release).
>
> —Sam
>
> On Fri, Nov 16, 2018, at 09:22, Ian Davis wrote:
> > Hi all,
> >
> > Since upgrading to Firefox 60.3 on Linux I am unable to view any pages
> > on https://go-review.googlesource.com/ and I wondered if anyone else was
> > seeing this problem or if it's an issue with my setup?
> >
> > Chromium renders the pages fine. When I view source with Firefox I see
> > the following:  which might be a clue to someone.
> >
> > 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.
>
>
> --
> Sam Whited
> s...@samwhited.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.
> 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] How to add a new operator

2018-12-09 Thread Wagner Riffel
define operator.
-wgr

On Sun, Dec 9, 2018, 10:27 AM Claygod  wrote:

> Hello,
>
> I want to try adding a new operator. Tell me, in which packages you need
> to edit the code?
> Maybe once a similar question was discussed, then please give a link
>
> --
> 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] Forking/transfering a repository and import paths

2018-12-12 Thread Wagner Riffel
Go has nothing to do with github, you can have any import path and how many
repos you like as long as it exists on your file system inside $GOPATH/src
-wgr

On Wed, Dec 12, 2018, 10:13 AM Sotirios Mantziaris 
wrote:

> Hi,
>
> i want to move a repo from my github account to another one. Goal is to
> have a new import path for the new forked repository.
> There are 2 ways of achieving the move:
>
>- Forking
>- Transfer repository
>
> Is it possible to fork a repo and change the import path of the repository?
>
> If the transfer option is chosen we just have to change all imports in the
> code, which severs the ties for the originating project.
>
> Is it possible to have:
>
>- both repos
>- every repo with it's own import path
>- code exchange between them
>
> What are the options?
>
> --
> 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] Trouble with exiting a for loop that contains bufio.NewScanner.Scan()

2018-12-30 Thread Wagner Riffel
Scan() returns false when it reaches EOF or an error, so with what you
provided i assume you're missing to check that.
for ns.Scan() {
...
}

or

for {
if !ns.Scan() {
break
}

-wgr

On Sun, Dec 30, 2018 at 10:36 PM Trig  wrote:
>
> I'm currently utilizing the bufio.NewScanner to read ASCII data from a serial 
> port.  I have the following simple code:
>
> ns := bufio.NewScanner(sPort)
>
> for {
>ns.Scan()
>if ns.Text() != "" { // ignore blank lines
>   // handle content here
>}
> }
>
> The problem is ns.Scan() blocks the loop from continuing if there isn't any 
> data.  This leaves me unable to break out of the loop with a for condition or 
> a select statement also within the loop which is looking for a close command 
> from a channel before or after it, etc.  Am I doing something wrong, or is 
> there a proper way to handle 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.

-- 
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] Can I say that a pointer is a reference or memory address to a value?

2019-01-09 Thread Wagner Riffel
i think the term reference is misleading, pointers holds a memory
address, but they are variables, have their own space in memory.
var i int
var p1, p2 = &i, &i
fmt.Printf("%p, %p, %p", &i, &p1, &p2) // 0x1000, 0x1004, 0x1008

while in c++ references variables for example, address are shared for
referenced and reference.
int i;
int &p1=i, &p2=i;
printf("%p, %p, %p", &i, &p1, &p2); // 0x1000, 0x1000, 0x1000

probably "memory address to a value" fits better for pointers.

On Wed, Jan 9, 2019 at 12:44 PM Ian Lance Taylor  wrote:
>
> On Tue, Jan 8, 2019 at 9:46 PM 伊藤和也  wrote:
> >
> > Can I say that a pointer is a reference or memory address to a value?
>
> Sure.
>
> 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.

-- 
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: Is it possible to export a variable from main package? If impossible, why?

2019-01-23 Thread Wagner Riffel
packages have nothing to do with files, if you are on some directory you
don't need to import any package, just use Number on other files

On Thu, Jan 24, 2019, 3:36 AM 伊藤和也  wrote:

> I couldn't import "main" package to other packages to use the variable
> "Number" and  I try to use "Number" in main package of different .go file
> in the same directory but I couldn't.
>
> 2019年1月24日木曜日 11時27分57秒 UTC+9 伊藤和也:
>>
>> package main
>>
>> var Number int = 100
>>
>> func main() {
>>
>> }
>>
>> --
> 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] Regarding Invalid UTF-8 characters

2019-01-25 Thread Wagner Riffel
there is nothing to do with special characters in the example you
shown, your xml data is just invalid xml, you're missing root element,
just add it and it should work:
CPUêÿ
btw here is a short version of your program on playground,
https://play.golang.org/p/PhKgVXIcWZl

On Fri, Jan 25, 2019 at 6:25 AM  wrote:
>
> Hi,
> How can I handle special characters while using unmarshalling. I am getting 
> some special charactes in my xml data (like this eg êÿÿ ) and golang throwing 
> xml syntax error invalid UTF-8. Any please suggest how to handle this case.
> I tried to handle this xml decoder like this:
>
>
> // Decoder_p.go
>
> package main
>
>
>
> import (
>
> "fmt"
>
> "encoding/xml"
>
> "io"
>
> "strings"
>
> )
>
> type Message struct {
>
> Mon string `xml:"monitor"`
>
> Data string `xml:"data"`
>
> }
>
> func main() {
>
> fmt.Println("Hello World!")
>
>
>
> xml_data := "CPUêÿ"
>
> var reader io.Reader
>
> reader=strings.NewReader(xml_data)
>
> val:=*strings.NewReader(xml_data)
>
> fmt.Println(reader,val)
>
> //read,_ := reader.Read([]byte(xml_data))
>
> //result,err := io_reader.Read([]byte(xml_data))
>
> //if err == nil {
>
>
>
> decoder := xml.NewDecoder(reader)
>
> //decoder.CharsetReader = func(data string,io io.Reader)(io.Reader,err)
>
> //decoder.RawToken()
>
> out := Message{}
>
> err := decoder.Decode(&out)
>
> fmt.Println(out)
>
> fmt.Printf(out.Data,out.Mon)
>
> fmt.Println(err)
>
> //}
>
>
>
> }
>
>
> but I am getting empty structure.
>
>
> output:
>
> Hello World!
>
> &{CPUêÿ 0 -1} 
> {CPUêÿ 0 -1}
>
> { }
>
> %!(EXTRA 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.
> 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] Producer-Consumer with Goroutines

2019-01-25 Thread Wagner Riffel
maybe it's the way you approached the problem, here is a perhaps cleaner
way to achieve desired output, https://play.golang.org/p/3a4lxbjdQAr

BR.

On Thu, Jan 24, 2019 at 7:12 PM diego patricio  wrote:

> Hi all, i'am just learning Go and goroutines, I have three goroutines
> (main, producer, consumer) and I dont know how synchronize producer and
> consumer for print one value at time, the output that I want is
>
> Producer 0
> Consumer 0
> Producer 1
> Consumer 1
> ..
> but the output of my program it's diferent.
>
> the program:
>
> [image: image.png]
>
> The output:
>
> [image: image.png]
>
> Sorry about my english
>
> Regards
>
> --
> 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] Re: why map the key type must not be a function, map, or slice

2019-01-25 Thread Wagner Riffel
you can "employ" any custom type as key but the ones that doesn't
defines equality operations, see
https://golang.org/ref/spec#Comparison_operators
as Ian already pointed out, you just can't build your custom type on
top of func, map or slice to be a valid key, anything else you can.

On Fri, Jan 25, 2019 at 12:47 PM Victor Giordano  wrote:
>
> Just wanna say : It would be nice to employ a custom type as a valid key for 
> a map!!! :D
>
>
> El jueves, 24 de enero de 2019, 0:47:32 (UTC-3), mount...@gmail.com escribió:
>>
>> thanks lan.
>>
>> 在 2019年1月23日星期三 UTC+8下午11:26:57,Ian Lance Taylor写道:
>>>
>>> On Tue, Jan 22, 2019 at 11:47 PM  wrote:
>>> >
>>> > i got :
>>> >   # command-line-arguments
>>> > ./key.go:6:18: invalid operation: F() == F() (func can only be compared 
>>> > to nil)
>>>
>>> Yes, that is what the language spec says and it is what I said: in Go,
>>> function values are not comparable.
>>>
>>> I wrote that code as an example to help explain why function values
>>> are not comparable.
>>>
>>> Ian
>>>
>>> > 在 2019年1月23日星期三 UTC+8上午11:59:07,mount...@gmail.com写道:
>>> >>
>>> >>  When i use the func, map slice as the key of map, it isn't work!
>>> >>  So  I lookup source  why, i find
>>> >>
>>> >> // spec: "The comparison operators == and != must be fully defined
>>> >> // for operands of the key type; thus the key type must not be a
>>> >> // function, map, or slice."
>>> >> //
>>> >> // Delay this check because it requires fully setup types;
>>> >> // it is safe to continue in any case (was issue 6667).
>>> >> check.later(func() {
>>> >> if !Comparable(typ.key) {
>>> >> check.errorf(e.Key.Pos(), "invalid map key type %s", 
>>> >> typ.key)
>>> >> }
>>> >> })
>>> >> // Comparable reports whether values of type T are comparable.
>>> >> func Comparable(T Type) bool {
>>> >> switch t := T.Underlying().(type) {
>>> >> case *Basic:
>>> >> // assume invalid types to be comparable
>>> >> // to avoid follow-up errors
>>> >> return t.kind != UntypedNil
>>> >> case *Pointer, *Interface, *Chan:
>>> >> return true
>>> >> case *Struct:
>>> >> for _, f := range t.fields {
>>> >> if !Comparable(f.typ) {
>>> >> return false
>>> >> }
>>> >> }
>>> >> return true
>>> >> case *Array:
>>> >> return Comparable(t.elem)
>>> >> }
>>> >> return false
>>> >> }
>>> >
>>> > --
>>> > 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.

-- 
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] Producer-Consumer with Goroutines

2019-01-25 Thread Wagner Riffel
sorry, i can't see how the order could matter here, in any case if
it's a problem just send on wait before fmt.Printf.
https://play.golang.org/p/iDsszgEHpQo

BR.

On Fri, Jan 25, 2019 at 2:32 PM Skip Tavakkolian
 wrote:
>
> if the intent is to "print" the producer's output before the consumer's, then 
> this example still can't guarantee it; for example:
> https://play.golang.org/p/2sb67Qf5IPd
>
> the only synchronization guarantee is the moment of exchange on the channel.
>
> On Fri, Jan 25, 2019 at 3:27 AM Wagner Riffel  wrote:
>>
>> maybe it's the way you approached the problem, here is a perhaps cleaner way 
>> to achieve desired output, https://play.golang.org/p/3a4lxbjdQAr
>>
>> BR.
>>
>> On Thu, Jan 24, 2019 at 7:12 PM diego patricio  wrote:
>>>
>>> Hi all, i'am just learning Go and goroutines, I have three goroutines 
>>> (main, producer, consumer) and I dont know how synchronize producer and 
>>> consumer for print one value at time, the output that I want is
>>>
>>> Producer 0
>>> Consumer 0
>>> Producer 1
>>> Consumer 1
>>> ..
>>> but the output of my program it's diferent.
>>>
>>> the program:
>>>
>>>
>>> The output:
>>>
>>>
>>> Sorry about my english
>>>
>>> Regards
>>>
>>> --
>>> 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] Re: why map the key type must not be a function, map, or slice

2019-01-26 Thread Wagner Riffel
i don't quite understand why you're using enums as keys, you can use a
anything but what already was pointed out, following your person example:
https://play.golang.org/p/cuMlPeqR7Qb


On Sat, Jan 26, 2019, 3:26 PM Victor Giordano  wrote:

> Yup! That's right! At the end of the day i used the enums idioms
> <https://stackoverflow.com/questions/14426366/what-is-an-idiomatic-way-of-representing-enums-in-go>,
> employing integer type (the value that supports the "enum" )
>
> (TL;DR;) Ancient History :
>
> The problem arises as i get used to use maps in Java where you can use as
> a key a class definition (that is custom data type in Java, like the same
> way an "struct" in Golang is a custom data type). So i get use to work with
> types as keys, that way i could associate logic and data with an
> asbtraction (recall that logic and data does not intrinsically belong to
> that abstraction, so it would be wrong to place all in there).
>
> I wake-up in golang without that capability: i mean how i may refer to a
> group of well know struct definitions in a generic way, i mean for example
> this:
>
> type Person struct {
> }
>
> var SpanishTermByStruct map[struct]string = map[struct]string{
> Person: "person",
> }
>
> ? and in that moment the wondering about using "type" for key (or value)
> comes to my mind... i then i get that is not allowed.
>
>
> El sáb., 26 ene. 2019 a las 10:57,  escribió:
>
>> I looked at your program example, mainly using the reflection type to
>> design the mapped key, perhaps the reflected key is a comparable type, but
>> I mainly propose specific types, such as func, slice, map can not be used
>> as a key use
>>
>> 在 2019年1月25日星期五 UTC+8下午11:31:57,Victor Giordano写道:
>>>
>>> Yeah, i got the idea. I had already researched about it and what you
>>> can do about it.
>>> <https://stackoverflow.com/questions/50730331/mapping-concrete-types>
>>> I was only repeating what i want as a dev in this community!
>>>
>>> El viernes, 25 de enero de 2019, 12:04:38 (UTC-3), Wagner Riffel
>>> escribió:
>>>>
>>>> you can "employ" any custom type as key but the ones that doesn't
>>>> defines equality operations, see
>>>> https://golang.org/ref/spec#Comparison_operators
>>>> as Ian already pointed out, you just can't build your custom type on
>>>> top of func, map or slice to be a valid key, anything else you can.
>>>>
>>>> On Fri, Jan 25, 2019 at 12:47 PM Victor Giordano 
>>>> wrote:
>>>> >
>>>> > Just wanna say : It would be nice to employ a custom type as a valid
>>>> key for a map!!! :D
>>>> >
>>>> >
>>>> > El jueves, 24 de enero de 2019, 0:47:32 (UTC-3), mount...@gmail.com
>>>> escribió:
>>>> >>
>>>> >> thanks lan.
>>>> >>
>>>> >> 在 2019年1月23日星期三 UTC+8下午11:26:57,Ian Lance Taylor写道:
>>>> >>>
>>>> >>> On Tue, Jan 22, 2019 at 11:47 PM  wrote:
>>>> >>> >
>>>> >>> > i got :
>>>> >>> >   # command-line-arguments
>>>> >>> > ./key.go:6:18: invalid operation: F() == F() (func can only be
>>>> compared to nil)
>>>> >>>
>>>> >>> Yes, that is what the language spec says and it is what I said: in
>>>> Go,
>>>> >>> function values are not comparable.
>>>> >>>
>>>> >>> I wrote that code as an example to help explain why function values
>>>> >>> are not comparable.
>>>> >>>
>>>> >>> Ian
>>>> >>>
>>>> >>> > 在 2019年1月23日星期三 UTC+8上午11:59:07,mount...@gmail.com写道:
>>>> >>> >>
>>>> >>> >>  When i use the func, map slice as the key of map, it isn't
>>>> work!
>>>> >>> >>  So  I lookup source  why, i find
>>>> >>> >>
>>>> >>> >> // spec: "The comparison operators == and != must be fully
>>>> defined
>>>> >>> >> // for operands of the key type; thus the key type must
>>>> not be a
>>>> >>> >> // function, map, or slice."
>>>> >>> >> //
>>>> >>> >> // Delay this check becaus

Re: [go-nuts] When would you use single quotes?

2019-02-06 Thread Wagner Riffel
'⌘' is of type rune (aka int32), "⌘" and `⌘` are of type string, both
takes more than 3 bytes.

-- 
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] What happens to global vars when main() ends ?

2019-05-03 Thread Wagner Riffel
> Does Go GC  destroy all global vars prior to the end of main() ?
What do you expected to happen? it makes no sense GC do any work, at
moment a process exits it's OS's job to unmmap allocated pages.

FWIW if race detector is enabled runtime does one thing before exit
syscall is invoked: if provided exit code is 0 it overwrites the code
to one defined by GORACE environment variable, defaulting to 66.
BR.

-- 
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] What happens to global vars when main() ends ?

2019-05-03 Thread Wagner Riffel
Last "kkk" print It's not a compiler error due GC, it's just a scoping
rule.
You shouldn't rely on any GC behaviour, GC is not even definied in Go
language spec and its behaviour changes almost every release.
BR.

-- 
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] Is this a bug?

2019-05-24 Thread Wagner Riffel
It's not a bug, FormatterA and FormatterB method has different
signatures, they are not identical, one wants Format(StringerA) other
Format(StringerB), thus your Format type only implements FormatterA
but Print wants a FormatterB.

-- 
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/CAFEfeLx%3DLWw5oioneg%3DSFDABJTuM0z4F7fHygh5WFsxHkWgf5g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Failed to install golang.org/x/tools

2021-02-05 Thread Wagner Riffel
On Mon, Feb 1, 2021 at 11:36 PM eric...@arm.com  wrote:
>
> Os: ubuntu 18.04
> Arch: arm64 linux
> go version: go1.15.7
> What did I do:
>  $ go get -u golang.org/x/tools/...
> package mvdan.cc/gofumpt/format: unrecognized import path 
> "mvdan.cc/gofumpt/format": reading https://mvdan.cc/gofumpt/format?go-get=1: 
> 404 Not Found
> But with the tip version of Go, I can download and install x/tools 
> successfully. Am I missing any configurations ?
>

I bet it's due go1.15 module-mode be enabled only if you're inside a
go module, and on 1.16 it has changed to be on regardless. see issue
http://golang.org/issues/40276

Perhaps you can get it working on 1.15 with the following: (I didn't
tested, just shooting)
$ cd $(mktemp -d)
$ go mod init tmp
$ GO111MODULE=on go get golang.org/x/tools/...

The temporary module to download is also required on 1.15, but should
not be on tip, I think the issue for that is http://golang.org/issues/40276


BR.

-w

-- 
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/CAFEfeLwkPJz5HcUU1T5TRvfKpyBcooxsgkwH00naUxBn%2BAcZEg%40mail.gmail.com.


Re: [go-nuts] prevent unnecessary escape to heap

2021-02-05 Thread Wagner Riffel
On Thu, Feb 4, 2021 at 10:32 PM Steve Roth  wrote:
>
> How can I implement a writeByte function, against an unknown io.Writer 
> implementation, that doesn't allocate heap memory?
>

The only way I'm aware of achieving this is proving to the compiler that
buf is safe to be kept by w by moving buf to the package block.

var buf [1]byte
func writeByte(b byte) {
buf[0] = b
_, err = w.Write(buf[:])
}

-- 
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/CAFEfeLzBaQSyQBpSqGa4YE8n8T_VPooRyz5KBLV%2B4jWitRqR%3Dg%40mail.gmail.com.


Re: [go-nuts] What is the output of objdump?

2020-02-27 Thread wagner riffel
On Thu, 27 Feb 2020 19:03:02 -0800 (PST)
bucha...@gmail.com wrote:

> Can someone please explain the columns printed by "go tool objdump"?
> instruction. I'm not sure what columns 2, 3, and 5 are.

Column $2 is the memory address offset, $3 is the entire instruction
encoded in hexadecimal, $5 is a continuation of $4, a disassembled
version of $3

> what the "TEXT %22%22.main(SB)
> gofile../Users/abuchanan/projects/gobuild/simple/ main.go" line is.

TEXT is a pseudo-operation to the "entry point" to the function,
%22%22.main(SB) is the function label itself.

You can find reference only here:
https://golang.org/doc/asm
https://9p.io/sys/doc/asm.html

—wagner

-- 
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/20200228021236.2cc4e759%40pampas.


Re: [go-nuts] Why can't I send byte array to golang TCP server using java netty client?

2020-03-11 Thread wagner riffel
I think that your problem is here: buffer := make([]byte, 6), conn.Read
reads up to len(bufer) before unblocking, and apparently you're trying
to decode an int32, which is 4 bytes long, so your Read call is waiting
for those 2 bytes from your java client to continue.

—wagner

-- 
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/20200311142230.71755059%40pampas.


Re: [go-nuts] libgo is more fast that grouting.

2020-03-16 Thread wagner riffel
On Mon, 16 Mar 2020 20:13:10 +0800
"'Benjamin' via golang-nuts"  wrote:

> How do you all think about it?
> 
IMO there's no such thing as "Go-style concurrency" if you don't have
`select`, which doesn't looks like this library provides (as many
others).

—wagner

-- 
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/20200317012317.0485b4a6%40pampas.


Re: [go-nuts] Packet parsing in Go

2020-04-22 Thread wagner riffel
On Tue, 21 Apr 2020 02:22:37 -0700 (PDT)
Rakesh K R  wrote:

> In C, we used to typecast this array of uint8_t to predefined
> structure.
> 

This is very bad even for a C program, as soon as you dereference
pointer to such structure it's an undefined behavior, and not portable
even on LE architectures, definitely such dereference would lead to a
runtime crash on arm cpus, ubuntu or docker wouldn't change anything,
also, the c compiler might add padding to your structure, which can
make such parser give the wrong answer even on architectures that allows
unaligned addressing. (unless you're non-standard compiler extensions
to avoid that)

Thus, even on C, the correct and portable way to parse an uint8_t array
is also going bytes one by one, i recommend you stick with the
"encoding/binary" package, it will do the right thing.

BR.

—wagner

-- 
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/20200422050932.7733e469%40pampas.


Re: [go-nuts] How to confirm a function is NOT compiled into a go binary

2019-06-08 Thread Wagner Riffel
This is totally possible, you can either use 'go tool nm' as suggest,
or 'go tool objdump', both tools can answer this question.
go tool objdump -s 'pkgname/internal' a.out
go tool nm a.out | grep 'pkgname/internal'
Be aware that testing against the shown examples, neither A() will be
present, by default go compiler will do inlining, you might want to
use //go:noinline directive.

BR.

-- 
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/CAFEfeLw2imLsAbyXs1zDccsHERSksdxnomBiiVwS0%3DdV8hSYRA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: cannot find package "text/template"

2019-06-13 Thread Wagner Riffel
Hi Tenney, clearly something went wrong with /src directory, you
reported your compiler to be go1.12, so it'd be a better idea to
download the go tree from go1.12 release branch instead of tip,
https://github.com/golang/go/tree/release-branch.go1.12

-- 
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/CAFEfeLwUfQXZX4wxEFPZO39w5XKhMYkveDYUNxx1teB_0G%2BhBg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] In module mode, where does "go install" install executables

2019-06-25 Thread Wagner Riffel
>
> I'd bet the default GOPATH, that is $HOME/go

BR.

-- 
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/CAFEfeLyJE4ZZg1d%2B%2BMkUqv8OOw8tHwsHhJtFEAG-Tw%3DZxzOVig%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Get tmp stuff in $GOTMPDIR instead of /tmp?

2019-08-22 Thread Wagner Riffel
On Thu, Aug 22, 2019 at 11:54 AM  wrote:
>
> Am I using things wrong?

go build uses GOCACHE, not GOTMPDIR. See go help environment.

- wgr

-- 
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/CAFEfeLwPqEqgTeWqX48GOdgaBXcqOMWdHK07Zyy6wM9TztEZHA%40mail.gmail.com.


Re: [go-nuts] Get tmp stuff in $GOTMPDIR instead of /tmp?

2019-08-22 Thread Wagner Riffel
On Thu, Aug 22, 2019 at 12:33 PM Wagner Riffel  wrote:
> go build uses GOCACHE, not GOTMPDIR. See go help environment.

Sorry, i was wrong, those are supposed to be temporary files, and they
are going correctly to GOTMPDIR for me, not sure what your problem is.

- wgr

-- 
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/CAFEfeLwA_C9YXopiNdo_B9czj5x5SBEv%2BbA0G5yap2McoZ_9jA%40mail.gmail.com.


Re: [go-nuts] manifest file of releases

2019-12-06 Thread Wagner Riffel
On Thu Dec 5, 2019 at 8:27 AM  wrote:
> I would hope there would be a JSON file from which I could use to monitor 
> releases and obtain download URLs. Something similar to what CoreOS does:
> https://coreos.com/releases/releases.json

GET https://golang.org/dl/?mode=json, then your download link would be
https://storage.googleapis.com/golang/ + "filename" field in the json.

- wgr

-- 
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/BYYYF11U1DN7.3AKDHU881DXM9%40pampas.


Re: [go-nuts] Why no signed conversions in binary.ByteOrder?

2024-07-27 Thread &#x27;wagner riffel' via golang-nuts
a2800276  wrote:
> Just out of curiosity, does anyone have a good rationale as to why there 
> are only unsigned conversions available `binary.ByteOrder`? It would seem 
> that this functionality is there to avoid dumb careless errors doing byte 
> order conversions, but this design forces me to have to think about whether 
> I can cast uint64 to int64 without loss of precision ...

I don't understand how an Int64() method can do any better than int64(x)
conversion, neither how there's loss of precision if both are the same size, and
on any computer I'm aware of both types uses the same bit pattern. So maybe
that's the rationale, use regular uint64 -> int64 langauge conversion.

BR.

-w

-- 
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/2PIXEYGFTJ957.2RF2M88CQ0B44%40104d.net.


Re: [go-nuts] Why no signed conversions in binary.ByteOrder?

2024-07-28 Thread &#x27;wagner riffel' via golang-nuts
a2800276  wrote:
> I agree it has no technical merit. It can't do better, but it avoid having 
> to think about the type mismatch. The functionality provided by ByteOrder 
> is fairly simple to begin with, I assume its whole purpose is to reduce 
> cognitive load/avoid dumb mistakes. My assumption is that it's probably not 
> immediately obvious to everyone whether `a := int64(unsigned_value)` never 
> loses precision or never reinterprets/reorders the physical value of the 
> bytes. At least I had to stop and think about it and the benefit of a 
> things like ByteOrder would be not having to think :) Then again, I'm not 
> particularly bright.
> 

This binary package provides Varint (see go doc) encoded integer which detects
overflows. This may help with dumb mistakes if it's easy to switch to its
encoding format.

BR.

-w

-- 
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/2V3MSWQ2PN88O.3EBUXVQXTJI41%40104d.net.


Re: [go-nuts] Running only one sub-benchmark

2024-08-06 Thread &#x27;wagner riffel' via golang-nuts
Jochen Voss  wrote:
> Now I just want to run one of these sub-benchmarks.  I tried -bench
> '^BenchmarkTextLayout/CFFSimple1$' but this runs two of the benchmarks:
> 
> > go test -run=^$ -bench '^BenchmarkTextLayout/CFFSimple1$'
> goos: darwin
> goarch: arm64
> pkg: seehuhn.de/go/pdf/graphics
> BenchmarkTextLayout/CFFSimple1-8   49   24198452 ns/op
> BenchmarkTextLayout/OpenTypeCFFSimple1-8   48   24209569 ns/op
> PASS
> ok   seehuhn.de/go/pdf/graphics 3.804s
> 
> How do I just run "BenchmarkTextLayout/CFFSimple1"?
> 

The regexp matches against the benchmark name, not the "full name". Slashes are
interpreted as a separator for names to be matched against, thus your regexp
first matches "^BenchmarkTextLayout" against all top-level benchmarks, then
matches "CFFSimple1$" against all sub-benchmarks names found in
"BenchmarkTextLayout" which indeed "CFFSimple1" and "OpenTypeCFFSimple1" are
matches of.

So the following regexp should only match "BenchmarkTextLayout/CFFSimple1".

$ go test -bench='^BenchmarkTextLayout/^CFFSimple1$'

Note the '^' before CFF.

BR.

-w

-- 
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/3LG0U1KAOYT9L.3Q5IDPUXR8DP8%40104d.net.


Re: [go-nuts] string matching

2021-04-02 Thread &#x27;wagner riffel' via golang-nuts
On Thu Apr 1, 2021 at 4:45 PM -03, Sharan Guhan wrote:
> r := regexp.MustCompile(`Core Count: [0-9]+`)
> match := r.FindAllStringSubmatch(cmd_output, -1)

As of the "efficiently" part, you should compile the regexp once
instead of each call to ParseFillCpuInfo, a common practice is to use
a package-level scoped variable but even better (for efficiency) would
be keep it with strings.Index approach, as such:

count := -1
const substr = "Core Count: "
if i := strings.Index(input, substr); i >= 0 {
countStart := i + len(substr)

const digits = "0123456789"
j := 0
for strings.ContainsRune(digits, rune(input[countStart+j])) {
j++
}
count, err := strconv.Atoi(input[countStart : countStart+j])
// handle err
}

You can benchmark both approaches using testing.B, have fun.

https://golang.org/pkg/testing/#B

-- 
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/CACXYA0GSJR6.UVYEID10NHU0%40pampas.


Re: [go-nuts] package is not in GOROOT

2021-04-07 Thread &#x27;wagner riffel' via golang-nuts
On Tue, 6 Apr 2021 19:39:00 -0400
rob  wrote:

>  > This example is on Win10 using go 1.16.3
> 
> Now I've created a directory tree outside of ~/go/src.  I'm using ~
> to mean %userprofile%, as this is win10
> 
> ~/gcode/rpng/rpng.go
> 
> ~/gcode/tokenize/tokenize.go
> 
> ~/gcode/hpcalc2/hpcalc2.go
> 
> And I updated my import statement to be "gcode/hpcalc2", etc.
> 
> Now I can use
> 
>   go run gcode/rpng/rpng.go
> 
> And I set GOBIN=c:\Users\rob\gcode
> 
>      go install gcode/rpng/rpng.go
> 
> and it installs to GOBIN.
> 
> At least it's working for me mostly the way it was before.  I just
> had to abandon my ~/go directory
> 
> Thanks for answering
> 
> Rob
> 

Hi Rob, it's good that you got it working, but I feel you're struggling
with modules inferred from your past emails due a confusion between a
module namespace and the file system, your package import paths and go
commands are relative to a *module* and not a directory, your current
module namespace is detected similarly as a git repository is, that is,
traverse current working directory up until a go.mod is found (or .git
for git), and then if a module is found, you import packages or use the
go commands in the format of *module_name*/folder/..., not file system
paths, what go cares as a namespace is the module name, not
absolute/relative file system paths.

For example, suppose our current working directory is "~/gcode/" and it
has a go.mod named¹ "foo", note that the folder is named gcode but the
module is "foo", you would install the "rpng" package inside this
module namespace "foo" with:
$ go install foo/rpng

you can refer file path relatives alike as well:
$ go install ./rpng # OK
$ go install rpng # invalid, would fail with the same not found message

you can think as dot expanding to "foo", not the file system gcode
folder, to make clear that it's not about file system paths, changing
our current working directory to "tokenize", we still can mention "rpng"
relative to the module, not the file system:
$ cd ~/gcode/tokenize
$ go install foo/rpng
$ go install ../rpng # valid as well

I'm not sure if this helps you or causes even more confusions, if so
sorry.

BR.

--wagner

[1] the module name is usually a domain, but not necessarily, refer to
https://pkg.go.dev/golang.org/x/mod/module#CheckPath for detailed
description.

-- 
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/20210407112419.1e5e0132%40pampas.


Re: [go-nuts] package is not in GOROOT

2021-04-09 Thread &#x27;wagner riffel' via golang-nuts
On Wed, 7 Apr 2021 20:11:22 -0400
rob  wrote:

> Would it be a bad idea to use my ~go/src as a module?
> 

I don't think so, I do have one global module like this for my own toys
and throwaways programs. Yes, it would need to adjust your import paths
according to the module, when I migrated to module it was easier
because everything was inside the same global folder, so I just needed
to init a module with that name.

>    go mod tidy --> do I need this?
> 

go mod tidy adds missing modules in go.mod/go.sum that you're importing
from go sources, and removes dangling ones (not found in your go
sources but in your go.mod/go.sum), it's wise to run it if you're
initializing a module from an existing code base.

--wagner

-- 
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/20210409120133.3a413a09%40pampas.


Re: [go-nuts] Re: Give us const arrays please :)

2021-04-12 Thread &#x27;wagner riffel' via golang-nuts
On Mon Apr 12, 2021 at 5:04 AM -03, Henry wrote:
> The example you gave is actually a map[rune]bool in Go, and not an
> array. I

It's a Go array in form of a composite literal, see
https://golang.org/ref/spec#Composite_literals

-- 
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/CALQL1TE71G0.1BJM6NT7DTW7W%40pampas.


Re: [go-nuts] how to pass analyzer's flag with 'go vet -vettool'

2021-04-12 Thread &#x27;wagner riffel' via golang-nuts
On Mon Apr 12, 2021 at 10:23 AM -03, Xiangdong Ji wrote:
> Hi,
>
> I'm trying to run "go vet -vettool=$(which fieldalignment) ./..." for a
> large project, and wish to turn its '-fix' option on, wondering how to
> pass
> that option?

Hi Xiangdong, I found that surprising that even docs didn't mention
this anywhere, I also got confused by how go vet -vettool works but I
think I understood after reading the source code, after a -vettool is
specified, all flags that are not build flags should be sent to the
vettool, apparently those old tools like fieldalignemnt are broken
with the new "vet command line protocol" mentioned in the source code,
even some flags for those tools is broken, it's clear to me that
there's a bug going on here. Please also consider that possible that I
just think I understood the problem. :)

BR.

--wagner

-- 
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/CAM7VOPMQSL3.12A9D1RI2IO7S%40pampas.


Re: [go-nuts] Why does Go ignore HTTP_PROXY and HTTPS_PROXY if the proxy address is localhost

2021-04-13 Thread &#x27;wagner riffel' via golang-nuts
On Tue Apr 13, 2021 at 2:14 PM -03, Orson Cart wrote:
> Can anyone explain the reasoning behind this? It rather interferes with
> debugging traffic using a local proxy like Fiddler.
>

My guess here it's for preventing the remote from tricking the proxy to
make request to internal services that couldn't be reached otherwise.

> I've seen suggestions to define an alternative hostname in /etc/hosts
> but as far as I can tell this doesn't work either.
>

The code you linked doesn't seen to try that hard to block loopback
requests, I do think that an /etc/hosts entry to 127.0.0.1 should
bypass the proxy, if not I don't see any other way around other than
implementing the RoundTripper yourself, which shouldn't be hard for
such simple use.

--wagner

-- 
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/CAMSV7PV770P.3NLGXICF3GS3S%40pampas.


Re: [go-nuts] Why does Go ignore HTTP_PROXY and HTTPS_PROXY if the proxy address is localhost

2021-04-13 Thread &#x27;wagner riffel' via golang-nuts
On Tue Apr 13, 2021 at 7:07 PM UTC, Orson Cart wrote:
> I'm perplexed :(
>

Did you tried the /etc/hosts? I think that would do it, if not,
something like this may do the trick:

if debug {
t := http.DefaultTransport.(*http.Transport)
t.Proxy = func(r *http.Request) (*url.URL, error) {
return url.Parse("http://localhost:";)
}
}

note: i did not tested, just shooting.

--wagner

-- 
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/CAMVU7SLM2E5.16SWWYLIRF8HD%40pampas.


Re: [go-nuts] how to pass analyzer's flag with 'go vet -vettool'

2021-04-14 Thread &#x27;wagner riffel' via golang-nuts
On Wed Apr 14, 2021 at 12:25 AM -03, Xiangdong Ji wrote:
> I tried to modify fieldalignment to turn its '-fix' option on by
> default, change worked as expected if running fieldalignment as a
> standalone utility, but no rewriting is applied when running it as a
> tool of 'go vet', could any expert here shed a light? Thanks.
>

In the last time I check this, I remember I saw that `go vet` calls
`vettol` with -flags argument and then tries to match with the command
line passed, but fieldalignment doesn't list -fix, that's why I said it
was broken. Hope this might help you:
https://github.com/golang/go/blob/e22478/src/cmd/go/internal/vet/vetflag.go#L67

-- 
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/CANHTHBOHYT7.2C1Y5NKICHA8%40pampas.


Re: [go-nuts] Why fmt.Println(math.Sqrt2) gives ...0951 not ...0950?

2021-05-01 Thread &#x27;wagner riffel' via golang-nuts
On Sat May 1, 2021 at 11:12 AM -03, Kamil Ziemian wrote:
> Can you guide me to some materials about const in Go? Or maybe I should
> finally read Go spec, which I avoid for a long time?
>

You shouldn't avoid to read the spec, it's not as complicated as others
languages, and it's a great source of answers to such questions, i think
this is a great material on Go constatns:
https://blog.golang.org/constants

-- 
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/CB244ROIRVC2.PS34B65JEIQ9%40pampas.


Re: [go-nuts] x/tools error while trying to install

2021-05-07 Thread &#x27;wagner riffel' via golang-nuts
On Fri May 7, 2021 at 11:10 AM -03, Eric Garcia wrote:
> Was trying to install all the tools, and hit the following errors.
>
> go version 1.16.3
>
> ```
> go get -u golang.org/x/tools/...
>

I think with go1.16 and later the correct way of installing programs
is with go install, it builds clean for me.
$ go install golang.org/x/tools/cmd/...@latest

-wagner

-- 
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/CB79QAS9VCSF.3L7J5LRYUD4R8%40pampas.


Re: [go-nuts] Read N bytes from a TLS stream and block the caller while still respecting the deadline

2021-11-30 Thread &#x27;wagner riffel' via golang-nuts
On Tue Nov 30, 2021 at 11:20 PM CET, LastName Almaember wrote:
> It's meant to first read a nine-byte header (8 bits of a type field
> followed by a 64 bit length). In theory, it should work fine, but it
> always immediately returns InputTooShort (right at the first check).

io.Readers returns up to len(p), not exactly len(p), you have to loop
over calling read until you have enough input, there's io.ReadAtLeast
and io.ReadFull helpers that does that for you.

> A bufio *might* work for this, however, I'm not confident that it will
> respect the deadline set on the connection.
>

bufio will respect your deadline, it doesn't skip errors from the
underlying reader, just returns them up. I suspect that it doesn't solve
the issue mentioned above tho.

BR.
-w

-- 
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/CG3S8W6WU9LX.1XINQC5EZN91Q%40pampas.


Re: [go-nuts] Pointer to a pointer

2022-03-10 Thread &#x27;wagner riffel' via golang-nuts
On Thu Mar 10, 2022 at 12:41 PM CET, Manlio Perillo wrote:
> Interesting example, thanks.
>
> But how does `type self *self` works?  If I remember correctly, it is not
> discussed in the Language Specification and in The Go Programming Language
> book.
>

I don't think it's mentioned in the specification, my bet is that
unless your type requires inifnity amout of memory (eg: `type t struct
{t}`) or the type is an interface and break its rules, (eg: `type
iface interface{ iface }`) you can use self-reference.

> By the way, in C `typedef self *self` is invalid (assuming my code is
> written correctly).

You're correct, C doesn't allow self reference in type decl, more
interesting types beside pointers:
  `type fn func() fn`
  `type s []s`
  `type ch chan ch`
  `type m map[*m]m`

-w

-- 
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/CIG6Z0BDF5P1.1O1MIIQNEHEZY%40pampas.


Re: [go-nuts] float exactness

2022-04-10 Thread &#x27;wagner riffel' via golang-nuts
On Sat Apr 9, 2022 at 3:56 PM CEST, 'Jack Li' via golang-nuts wrote:
> Why literal operation is exact, variable is not?
>
> fmt.Println(0.1 + 0.2) // 0.3 exactly
> fmt.Println(x + y) // 0.30004
>

Both aren't exact because floats can't represent 0.3 exactly, they
differ because literals and constants expressions have arbitrary
precision (http://golang.org/ref/spec/#Constants), so "0.1" and "0.2"
in "0.1 + 0.2" are exact, then when the exact "0.3" result is
converted to a float64 it becomes the closest possible, You can check
this if you ask to print with more precision

x, y := 0.1, 0.2
fmt.Printf("%.17f...\n", 0.1+0.2) // 0.2...
fmt.Printf("%.17f...\n", x+y) // 0.30004...

https://go.dev/play/p/2qSfoCZGaD6

-w

-- 
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/CJ6VDO2DK4XB.3VDUG02EUZ58S%40pampas.


Re: [go-nuts] Packages for Accessing .a Archives?

2022-04-10 Thread &#x27;wagner riffel' via golang-nuts
On Sun Apr 10, 2022 at 4:23 AM CEST, jlfo...@berkeley.edu wrote:
> Other than what's in the Go distribution, I haven't been able to find any
> packages for accessing .a archives. Is there anything else out there?
> Google wasn't helpful.
>
> Cordially,
> Jon Forrest
>

I found these using https://pkg.go.dev/search?q=ar

https://pkg.go.dev/github.com/mkrautz/goar
https://pkg.go.dev/github.com/blakesmith/ar
https://pkg.go.dev/github.com/laher/argo/ar

-w

-- 
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/CJ6WFYGNL9OV.1A2BXUCN1KFUJ%40pampas.


Re: [go-nuts] Executing a tar command from within a Go program

2022-04-20 Thread &#x27;wagner riffel' via golang-nuts
On Wed Apr 20, 2022 at 6:16 PM CEST, Dean Schulze wrote:
> I need to execute this tar command
>
> *tar xzf dir1/dir2/somefile.tgz --directory=dir1/dir2/*
>

Did you considered using the packages "archive/tar" and
"compress/gzip" to achive this?

> *argStr := "xzf dir1/dir2/somefile.tgz --directory=dir1/dir2/"output, err
> := exec.Command("tar", argStr).Output()*
>

exec.Command arguments are variadic, each argument is one argv, thus I
think you meant exec.Command("tar", "xzf", "dir1/dir2/somefile.tgz",
"--directory=dir1/dir2/")

-w

-- 
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/CJF7II5MD0Y9.2Y2HYXCZ4QDSC%40pampas.


Re: [go-nuts] Executing a tar command from within a Go program

2022-04-20 Thread &#x27;wagner riffel' via golang-nuts
Also, the Output method only returns what was wrote to stdout, tar
argument parsing errors are probably in stderr, using CombinedOutput()
has better effect to debug.

-- 
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/CJF7P5OFW5I8.2YK5VGDWTSBVV%40pampas.


Re: [go-nuts] For range loop variable passing by reference to go routine causes memory leak

2022-10-08 Thread &#x27;wagner riffel' via golang-nuts

On 08/10/2022 22:56, davy zhang wrote:

Original post on stackoverflow:

https://stackoverflow.com/questions/73985794/for-range-loop-variable-passing-by-reference-to-go-routine-causes-memory-leak


Code for reproducing the problem:

https://go.dev/play/p/7Xzx1Aauzhh

go version go1.19 darwin/amd64

go tool pprof http://localhost:6060/debug/pprof/heap

func1 is leaking

https://i.stack.imgur.com/LTXHn.png 

Is there any reason for this leaking?


Thank you for any input



I don't think it's related with for-range loops, both should "leak"
the same, I bet that's tMap, currently in Go maps do not shrink, even
if you delete keys. One way to reduce memory usage of a long-living
map is to at some threshold copy over all its elements into a new map,
and set the old to map to this copy, then the old map, if not
referenced elsewhere, will eventually be gc'ed and cleaned up.

-w

--
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/d227d9f0-90e1-fb62-2925-9a4729036708%40104d.net.


Re: [go-nuts] get function body comments using ast

2022-10-10 Thread &#x27;wagner riffel' via golang-nuts

On 10/9/22 11:09, Dmitry Belyaev wrote:

For a function like below I'd get only *example // doc comment*,

// doc comment
func example() {
   // body comment   < looking to extract this comment
}

but I am looking also to extract *// body comment*.

Please advise on how to extract function name, doc comment AND body 
comment altogether. Thank you!




I don't think go/parser adds comments to functions body []Stmt list, 
though if go through all comments in ast.File and filter by those that 
are in range with function's block statement, maybe that's enough.


https://go.dev/play/p/S4Iz504K8Gm

-w


--
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/3758c4a4-bff7-3c15-91ac-8b5cb3d550d3%40104d.net.


Re: [go-nuts] Newbie question

2023-01-10 Thread &#x27;wagner riffel' via golang-nuts

On 1/10/23 11:42, Daniel Jankins wrote:

Hi,

Why can you update a value in a map struct?



Sort answer, because m["foo"] is not addressable, but you can have the 
desired behavior using a temp variable:


func f() {
m := make(map[string]struct{ i int })
x := m["foo"]
x.i = 42
m["foo"] = x
}

BR.
-- w

--
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/dba18fd2-55cc-148b-48b2-6ae8ba90aa29%40104d.net.


Re: [go-nuts] shadowing of types by variables

2023-01-16 Thread &#x27;wagner riffel' via golang-nuts

On 1/13/23 07:20, Gorka Guardiola wrote:
According to the spec it seems like it is legal to shadow a type with a 
variable, even a builtin type.
Is there any specific rationale for this? I guess that it makes scoping 
checks easier and faster, but still.




I don't think there is any special rationale behind it, in Go builtin 
types are predefined identifiers, not keywords as usual in other 
languages, thus those follow rules of identifiers, not keywords. 
Although it feels astonishing that you can shadow even predefined 
constants like "true := false", in my experience this haven't shown to 
be an issue.


-w

--
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/ff5efae5-937e-32dd-608a-8d8ac8d0417b%40104d.net.


Re: [go-nuts] Re: Is it expected that signal.NotifyContext() changes the execution thread?

2023-10-03 Thread &#x27;wagner riffel' via golang-nuts

On Tue Oct 3, 2023 at 05:54 AM UTC, Kurtis Rader wrote:
> Thank you to Ian and TheDiveO. I don't understand why functions like
> gocv.io/x/gocv.NewWindow() have to run on the initial OS thread (at least
> on macOS).

It's common for C and C++ libraries to use TLS (thread local storage)
to attach data/state to each thread, one example is the global errno
variable used in C to signal errors, each thread read/write its own
variable even though in code they are wirting "the same" variable,
using libc from cgo and reading errno for failures would give wrong
results if the goroutine moved OS threads. It's unrelated which thread
it is and that's why it's not a default, you could start NewWindow at
some point that its goroutine is running in thread4, and if it's not
pinned to run in thread4 you have the same issue with the "initial
thread".

ps: Specific with graphics, I know OpenGL retains thread-local data,
which might explain why libraries that have this common ancestor needs
to LockOSThread, I'm not sure about Mac and Windows.

-w

--
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/dcbc6ba0-54c8-5942-eb4d-120ba8d65f03%40104d.net.