[go-nuts] minimum linux kernel version that can run latest golang

2020-07-24 Thread xie cui
what is the minimum version of linux kernel that can run golang?

-- 
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/b1d7add2-91ab-4a17-af19-d08cba6f0e3an%40googlegroups.com.


[go-nuts] my package not include in go modules

2020-07-24 Thread Ali Hassan
I want to import libraries in module file but modules add all other 
libraries except those packages which I had created, DB is one of them. How 
to import? 
Error , please help me 
to resolve 

-- 
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/66979dfc-a575-4001-ad48-902e9c8d3832o%40googlegroups.com.


Re: [go-nuts] When set time.Location, will be detected Data Race

2020-07-24 Thread Mike Cohen
Thanks Robert, this is what I ended up doing. I wouldnt say it was
trivial though :-)
https://github.com/Velocidex/json
Thanks and sorry for hijacking this thread. Maybe a suggestion - if
users are not expected to change time.Local maybe it should be made
private or at least wording in the module should not say that clients
are allowed to change it. Having a public variable invites users to
expect that changing it is acceptable and only after getting hit by the
race detector and spending a huge amount of time figuring out the
details it becomes apparent that it should not be changed
ThanksMike
On Fri, 2020-07-24 at 11:51 -0500, Robert Engels wrote:
> Yea, it is strange the the Json encoder api doesn’t allow the caller
> to provide a mashaller for any type. It would be trivial to change
> the code to do so. 
> That being said I’m sure you can find custom json libs on the web
> that will do this. Or fork it yourself - it is not a lot of code. 
> > On Jul 24, 2020, at 11:15 AM, Mike Cohen 
> > wrote:
> > 
> > To be clear, the time.MarshalJSON() function produces valid RFC
> > 3339 timestamps which allow arbitrary timezones. This means that
> > local time offset is used in the string representation. Although
> > all representations are technically equivalent their string form is
> > not so we need to do special parsing to compare them (and users get
> > really confused as well).
> > Here is an example - https://play.golang.org/p/hELVEI1tGJd
> > when I run it I get {"A":6,"B":"2009-11-11T10:00:00+11:00"}  for
> > Australia time, but {"A":6,"B":"2009-11-10T18:00:00-05:00"} for
> > America/New_York.
> > I am aware I can use the .In() method to cast the time.Time object
> > into different timezone but this is the whole issue - I need to
> > search through all the struct fields, expand slices, recurse
> > through maps etc just to find any time.Time objects and change them
> > **before** I call json.Marshal().
> > I usually get the times from a struct in another library so I have
> > no control over how these times are made for example consider this
> > https://play.golang.org/p/HmGREBF2Hbd
> > where I call an out of tree library to build a struct then just
> > want to dump it - I have no control over the encoding.
> > I think this is a actually a limitation in the json strategy of
> > encoding based only on types and not on context. The TZ issue is
> > just a manifestation of that - even if there was a safe way to set
> > TZ in a running program, in a multithreaded program all json
> > encoders would be forced to use the same local TZ because encoding
> > goes with type and not with context.
> > Thanks.Mike
> > 
> > On Thu, 2020-07-23 at 20:02 -0700, Ian Lance Taylor wrote:
> > > On Thu, Jul 23, 2020 at 5:13 PM Michael Cohen  > > > wrote:
> > > > Thanks Ian, this does not work as I mentioned because there is
> > > > no way to guarantee that my init function will run before any
> > > > of my libraries creating a time object (which many do as they
> > > > start various background tasks).
> > > > Doing what you say is fragile because even if it appears to
> > > > work, one day I might link a library and it will mysteriously
> > > > break randomly (this happened to us previously).
> > > > Is this a bug in the time package? Or simply a bug or design
> > > > shortfall in the json package? One way I thought to fix this
> > > > issue is to simply fork the json encoder and handle time.Time
> > > > structs specifically, but this obviously does not scale to eg
> > > > yaml encoders etc.
> > > 
> > > I don't think it's a shortfall in the encoding/json package as
> > > such,as that package knows nothing about times.  It's the time
> > > package thatimplements an UnmarshalJSON.  Looking at that method,
> > > I'm a littlesurprised at what you describe, since it just uses
> > > the timezone in theJSON string.  It doesn't use the local
> > > timezone as far as I can see.Can you show a small program that
> > > demonstrates the problem?
> > > Ian
> > -- 
> > Mike Cohen
> > Digital Paleontologist
> > 
> > Velocidex Enterprises
> > https://www.velocidex.com
> > 
> > +61.470238491
> > 
> > 
> > 
> > 
> > 
> > 
-- 
Mike Cohen
Digital Paleontologist

Velocidex Enterprises
https://www.velocidex.com

+61.470238491



-- 
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/308f0ff2cfa5b32bd52809a454060eb3d160d00c.camel%40velocidex.com.


Re: [go-nuts] Does method with pointer receiver keeps track of the receiver instance

2020-07-24 Thread Ian Lance Taylor
On Fri, Jul 24, 2020 at 4:25 PM burak serdar  wrote:
>
> On Fri, Jul 24, 2020 at 5:21 PM Ian Lance Taylor  wrote:
> >
> > On Fri, Jul 24, 2020 at 4:07 PM Tony Yang  wrote:
> > >
> > > Hi Go community,
> > >
> > > I am wondering if a method with the pointer receiver keeps the receiver 
> > > instance from garbage collected.
> > >
> > > To put the idea into a code example
> > >
> > > ```
> > > type counter struct {
> > > c int
> > > }
> > >
> > > func (c *counter) next() int {
> > > c.c = c.c + 1
> > > return c.c
> > > }
> > >
> > > func getNextFunc() func () int {
> > > // Question: will c be garbage collected after the function retruns?
> > > c := &counter{}
> > > return c.next
> > > }
> >
> > The mere existence of a pointer receiver does not prevent a value from
> > being garbage collected.  In your example, if the counter value is
> > allocated on the heap in getNextFunc, that heap allocation can be
> > collected after getNextFunc returns (in practice in this example c
> > would be allocated on the stack, not the heap, anyhow).
>
>
> What is returned from the function is a method, though. Isn't that
> essentially a closure keeping a reference to c, and thus, c has to be
> allocated on the heap, and cannot be garbage collected until the
> returned function leaves the scope?

My apologies, I completely missed that you returned a method rather
than calling the method.

Yes, doing this will prevent c from garbage collected.  Otherwise it
would be impossible to call the returned function safely.

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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcUDKr4BvRWdbtQKYqf8FZjcE4w5DBbDp-5DJcNG_apaiQ%40mail.gmail.com.


Re: [go-nuts] Does method with pointer receiver keeps track of the receiver instance

2020-07-24 Thread Tony Yang
I have tried the following example: https://play.golang.org/p/OfeWQH5S-Ju

```
func main() {
nextFunc := getNextFunc()
fmt.Println(nextFunc()) // prints 1
fmt.Println(nextFunc()) // prints 2
runtime.GC()
fmt.Println(nextFunc()) // prints 3
fmt.Println(nextFunc()) // prints 4
}
```

It appears that the receiver c is not GCed, or maybe it is GCed but the 
corresponding memory hasn't been clean up yet.

If it wasn't GCed, I am wondering how does Go bookkeep c.

Tony
On Friday, July 24, 2020 at 4:26:15 PM UTC-7 bbse...@gmail.com wrote:

> On Fri, Jul 24, 2020 at 5:21 PM Ian Lance Taylor  wrote:
> >
> > On Fri, Jul 24, 2020 at 4:07 PM Tony Yang  wrote:
> > >
> > > Hi Go community,
> > >
> > > I am wondering if a method with the pointer receiver keeps the 
> receiver instance from garbage collected.
> > >
> > > To put the idea into a code example
> > >
> > > ```
> > > type counter struct {
> > > c int
> > > }
> > >
> > > func (c *counter) next() int {
> > > c.c = c.c + 1
> > > return c.c
> > > }
> > >
> > > func getNextFunc() func () int {
> > > // Question: will c be garbage collected after the function retruns?
> > > c := &counter{}
> > > return c.next
> > > }
> >
> > The mere existence of a pointer receiver does not prevent a value from
> > being garbage collected. In your example, if the counter value is
> > allocated on the heap in getNextFunc, that heap allocation can be
> > collected after getNextFunc returns (in practice in this example c
> > would be allocated on the stack, not the heap, anyhow).
>
>
> What is returned from the function is a method, though. Isn't that
> essentially a closure keeping a reference to c, and thus, c has to be
> allocated on the heap, and cannot be garbage collected until the
> returned function leaves the scope?
>
> >
> > 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...@googlegroups.com.
> > To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/CAOyqgcWtFocDKraHsR-fqadrKgYxc%2B5K9e9u1rM7K%3DRj3oLXMw%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/a7bc5a7c-7cc2-4031-a654-0738d0e82f0bn%40googlegroups.com.


Re: [go-nuts] Does method with pointer receiver keeps track of the receiver instance

2020-07-24 Thread burak serdar
On Fri, Jul 24, 2020 at 5:21 PM Ian Lance Taylor  wrote:
>
> On Fri, Jul 24, 2020 at 4:07 PM Tony Yang  wrote:
> >
> > Hi Go community,
> >
> > I am wondering if a method with the pointer receiver keeps the receiver 
> > instance from garbage collected.
> >
> > To put the idea into a code example
> >
> > ```
> > type counter struct {
> > c int
> > }
> >
> > func (c *counter) next() int {
> > c.c = c.c + 1
> > return c.c
> > }
> >
> > func getNextFunc() func () int {
> > // Question: will c be garbage collected after the function retruns?
> > c := &counter{}
> > return c.next
> > }
>
> The mere existence of a pointer receiver does not prevent a value from
> being garbage collected.  In your example, if the counter value is
> allocated on the heap in getNextFunc, that heap allocation can be
> collected after getNextFunc returns (in practice in this example c
> would be allocated on the stack, not the heap, anyhow).


What is returned from the function is a method, though. Isn't that
essentially a closure keeping a reference to c, and thus, c has to be
allocated on the heap, and cannot be garbage collected until the
returned function leaves the scope?

>
> 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.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/CAOyqgcWtFocDKraHsR-fqadrKgYxc%2B5K9e9u1rM7K%3DRj3oLXMw%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/CAMV2RqrVhCWyKrDxH_vC_CmeQ4OLh0jZh4SHnr6Di-BvWPp4%2Bg%40mail.gmail.com.


Re: [go-nuts] Does method with pointer receiver keeps track of the receiver instance

2020-07-24 Thread Ian Lance Taylor
On Fri, Jul 24, 2020 at 4:07 PM Tony Yang  wrote:
>
> Hi Go community,
>
> I am wondering if a method with the pointer receiver keeps the receiver 
> instance from garbage collected.
>
> To put the idea into a code example
>
> ```
> type counter struct {
> c int
> }
>
> func (c *counter) next() int {
> c.c = c.c + 1
> return c.c
> }
>
> func getNextFunc() func () int {
> // Question: will c be garbage collected after the function retruns?
> c := &counter{}
> return c.next
> }

The mere existence of a pointer receiver does not prevent a value from
being garbage collected.  In your example, if the counter value is
allocated on the heap in getNextFunc, that heap allocation can be
collected after getNextFunc returns (in practice in this example c
would be allocated on the stack, not the heap, anyhow).

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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcWtFocDKraHsR-fqadrKgYxc%2B5K9e9u1rM7K%3DRj3oLXMw%40mail.gmail.com.


[go-nuts] Does method with pointer receiver keeps track of the receiver instance

2020-07-24 Thread Tony Yang
Hi Go community,

I am wondering if a method with the pointer receiver keeps the receiver 
instance from garbage collected.

To put the idea into a code example

```
type counter struct {
c int
}

func (c *counter) next() int {
c.c = c.c + 1
return c.c
}

func getNextFunc() func () int {
// Question: will c be garbage collected after the function retruns?
c := &counter{}
return c.next
}
```


-- 
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/434878c2-6ffe-4cc9-a0d4-3de8581b7138n%40googlegroups.com.


Re: [go-nuts] Generic symbol metaproposal

2020-07-24 Thread David Riley
On Jul 24, 2020, at 5:50 PM, Ian Lance Taylor  wrote:
> 
> On Fri, Jul 24, 2020 at 2:22 PM  wrote:
> >
> > On 7/23/20, Michael Jones  wrote:
> > ...
> > > Another delight is the uppercase signal for external.
> > >
> > > Maybe the “how to signal it” aspect of type instantiation could look to
> > > these approaches as well—make the automatic understanding so magical that
> > > the complete specification is unnecessary in most all cases, or the
> > > signaling so intrinsic to the variables that no identification Symbol or
> > > BracketedPair is necessary.
> >
> > Maybe braille?
> > ⠓⠑⠇⠇⠕⠺⠕⠗⠇⠙
> > https://www.royalblind.org/sites/www.royalblind.org/files/alphavet.PNG
> >
> > ⠊⠞ ⠊⠎ ⠑⠁⠎⠽
> 
> I've always felt that color is underused in modern programming languages.
> 
> func Max(T)(s []T) T

Perhaps there could be some cross-pollination with ColorForth, wherein color 
actually is semantically meaningful.

https://colorforth.github.io


- Dave

-- 
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/5C8F0D0D-0D9D-45E4-8B68-E78C59505550%40gmail.com.


Re: [go-nuts] Generic symbol metaproposal

2020-07-24 Thread fgergo
On Fri, Jul 24, 2020, 23:50 Ian Lance Taylor  wrote:

> On Fri, Jul 24, 2020 at 2:22 PM  wrote:
> >
> > On 7/23/20, Michael Jones  wrote:
> > ...
> > > Another delight is the uppercase signal for external.
> > >
> > > Maybe the “how to signal it” aspect of type instantiation could look to
> > > these approaches as well—make the automatic understanding so magical
> that
> > > the complete specification is unnecessary in most all cases, or the
> > > signaling so intrinsic to the variables that no identification Symbol
> or
> > > BracketedPair is necessary.
> >
> > Maybe braille?
> > ⠓⠑⠇⠇⠕⠺⠕⠗⠇⠙
> > https://www.royalblind.org/sites/www.royalblind.org/files/alphavet.PNG
> >
> > ⠊⠞ ⠊⠎ ⠑⠁⠎⠽
>
> I've always felt that color is underused in modern programming languages.
>
> func Max(T)(s []T) T
>
> Ian
>

Who came up with the idea of "begin with Lu for exported symbols"? Maybe
there are other better ideas where that came from.

-- 
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%2BctqrqO%2ByYsW%3D%3D%3DQk87_%3D0qPiVmFTDyBgA4xyBdw6a95EpHYw%40mail.gmail.com.


Re: [go-nuts] Generic symbol metaproposal

2020-07-24 Thread Ian Lance Taylor
On Fri, Jul 24, 2020 at 2:22 PM  wrote:
>
> On 7/23/20, Michael Jones  wrote:
> ...
> > Another delight is the uppercase signal for external.
> >
> > Maybe the “how to signal it” aspect of type instantiation could look to
> > these approaches as well—make the automatic understanding so magical
that
> > the complete specification is unnecessary in most all cases, or the
> > signaling so intrinsic to the variables that no identification Symbol or
> > BracketedPair is necessary.
>
> Maybe braille?
> ⠓⠑⠇⠇⠕⠺⠕⠗⠇⠙
> https://www.royalblind.org/sites/www.royalblind.org/files/alphavet.PNG
>
> ⠊⠞ ⠊⠎ ⠑⠁⠎⠽

I've always felt that color is underused in modern programming languages.

func Max(T)(s []T) T

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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcUmcQy0h_sYYfmYny2n-5nDJR4qakFN4MGZX0VX0yLmAw%40mail.gmail.com.


[go-nuts] How to get the methods list for each struct in golang.org/x/tools/go/ssa?

2020-07-24 Thread Xudong SUN
Hello everyone,

I am trying to use golang.org/x/tools/go/ssa to get the methods list of 
each struct type when doing static analysis on Kubernetes.
This is the code I wrote to print out the method sets for each struct or 
interface type.

cfg := packages.Config{Mode: packages.LoadAllSyntax}
initial, err := packages.Load(&cfg, pattern)
if err != nil {
   log.Fatal(err)
}
prog, _ := ssautil.AllPackages(initial, 0)
prog.Build()

for _, pkg := range prog.AllPackages() {
   if pkg.Pkg.Path() == pattern {
  for _, member := range pkg.Members {
 fmt.Println(member)
 if m, ok := member.(*ssa.Type); ok {
fmt.Println(prog.MethodSets.MethodSet(m.Type()))
 }
  }
   }
}



I checked everything printed by fmt.Println(member) but it only contains 
the pkg-level functions instead of struct methods.
I also checked everything printed by fmt.Println(prog.MethodSets.MethodSet(m
.Type())) and the method set for each struct/interface only contains the 
abstract methods and their implementations. Many other methods (which are 
not the implementation of some abstract methods) are missing here.

*In one word, I am able to get all the pkg-level functions in the program 
but I am NOT able the get the complete method list of any struct type in 
the program.*

*Here is what I want:*
I want to get the complete method list (a list of *ssa.Function pointing to 
the method) by calling some API with the struct type (or name)

I googled around and read the related documents here: 
https://pkg.go.dev/golang.org/x/tools/go/ssa?tab=doc but didn't find any 
clue to solve the problem.
I also read the golang.org/x/tools/go/ssa code but failed to find any API 
to do so.

Could anyone help to let me know how to do solve it in 
golang.org/x/tools/go/ssa?
Thank you so much!








-- 
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/ab709f17-a359-40f9-851a-8c369793c28bo%40googlegroups.com.


Re: [go-nuts] Generic symbol metaproposal

2020-07-24 Thread fgergo
On 7/23/20, Michael Jones  wrote:
...
> Another delight is the uppercase signal for external.
>
> Maybe the “how to signal it” aspect of type instantiation could look to
> these approaches as well—make the automatic understanding so magical that
> the complete specification is unnecessary in most all cases, or the
> signaling so intrinsic to the variables that no identification Symbol or
> BracketedPair is necessary.

Maybe braille?
⠓⠑⠇⠇⠕⠺⠕⠗⠇⠙
https://www.royalblind.org/sites/www.royalblind.org/files/alphavet.PNG

⠊⠞ ⠊⠎ ⠑⠁⠎⠽

-- 
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%2BctqroajJ_JzGs5sAcmVOAjAPaaucRZsZ_XGqE%3DJV%2BbuuRTbw%40mail.gmail.com.


[go-nuts] Send a mail with a service account using Gmail API

2020-07-24 Thread Vincent Jouglard
Hi John,

Thanks for your message.
The main difference with my implementation is that I use a service account 
which is authorized to send messages on my behalf...and I think that this is 
where lies the problem.

As i understand OAuth and the implementation from your exemple, a token is 
generated and could (will) need to be refreshed, requiring a human interaction  
(copy past a token from a UrL). Using a service account allows a full 
server-to-server flow.
Please correct me if I am mistaken!

-- 
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/000aabd3-fb2c-420b-9293-1683ea3e312bo%40googlegroups.com.


[go-nuts] Go 1.15 Release Candidate 1 is released

2020-07-24 Thread Alexander Rakoczy
Hello gophers,

We have just released go1.15rc1, a release candidate version of Go 1.15.
It is cut from release-branch.go1.15 at the revision tagged go1.15rc1.

Please try your production load tests and unit tests with the new version.
Your help testing these pre-release versions is invaluable.

Report any problems using the issue tracker:
https://golang.org/issue/new

If you have Go installed already, the easiest way to try go1.15rc1
is by using the go command:
$ go get golang.org/dl/go1.15rc1
$ go1.15rc1 download

You can download binary and source distributions from the usual place:
https://golang.org/dl/#go1.15rc1

To find out what has changed in Go 1.15, read the draft release notes:
https://tip.golang.org/doc/go1.15

Cheers,
The Go Team

-- 
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/CAFtHmMi5DuGL-5C%2BDTxDhgO3JCqEU4MRpxBfmfZLV-6wvFnOuA%40mail.gmail.com.


Re: [go-nuts] [Generics] function aliasing via variables broken for generic functions.

2020-07-24 Thread Ian Lance Taylor
On Fri, Jul 24, 2020 at 9:15 AM binary cat  wrote:
>
> Doing `var F = Foo` (where `Foo` is a generic function) fails with an error 
> like this: `prog.go2:21:9: cannot use generic function Foo (value of type 
> func(type T1, T2)(fst T1, snd T2) Bar(T1, T2)) without instantiation in 
> variable declaration`. Trying `var F = Foo[int,int]` fails with an error like 
> `prog.go2:21:9: expected expression`.
>
> Personally, I think both of these should work (with the second being a 
> version of `Foo` that only accepts two ints), but the first one definitely 
> seems like an implementation error, as the first snippet works fine if `Foo` 
> is a non-generic function.

A statement like "var F = Foo" can't work if Foo is a generic
function.  What would be the type of F?  All generic functions and
types must be fully instantiated at compile time.

"var F = Foo[int, int]" does work on the head of the dev.go2go branch.

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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcUGUzYFR%3DNeS33_VBYKAXhZ2N4VkKknfnwPHqXUP0V14w%40mail.gmail.com.


[go-nuts] Re: Writing bitmap data to a canvas with WebAssembly

2020-07-24 Thread Mark Farnan
Little old, but this might also help. 

 A while back I built a helper package to deal with these issues for canvas 
rendering from Go.  

https://github.com/markfarnan/go-canvas  

I'm currently working on it to add  WebGL support & get it working in 
TinyGo (some issues still).

Regards

Mark.



On Sunday, 22 March 2020 at 09:08:40 UTC+1 Scott Pakin wrote:

> I figure I ought to follow up with some results.  First, I got the 
> suggested approach of local render + js.CopyBytesToJS 
>  + update canvas from 
> image to work, so thanks, Agniva and Howard!  Second, for the benefit of 
> future readers of this thread, one thing that wasn't obvious to me is that 
> one needs to render the image data in a browser-recognizable image format—I 
> used PNG —*not* 
> raw {red, green, blue, alpha} bytes as is needed when writing directly to a 
> canvas 's image data.  
> Third, I used JavaScript code like the following to update an invisible 
> img  then copy the image data 
> from there to a visible canvas:
>
> function copyBytesToCanvas(data) {
> let blob = new Blob([data], {"type": "image/png"});
> let img = document.getElementById("myImage");
> img.onload = function() {
> let canvas = document.getElementById("myCanvas");
> let ctx = canvas.getContext("2d");
> ctx.drawImage(this, 0, 0);
> };
> img.src = URL.createObjectURL(blob);
> }
>
> Fourth, the performance is indeed substantially faster than my previous 
> approach based on using SetIndex 
>  to write directly to 
> the canvas, even though the new approach requires the extra steps of 
> encoding the image in PNG format and copying the image data from an img 
> to a canvas.  The following performance data, measured with Go 1.14 and 
> Chromium 80.0.3987.132 on an Ubuntu Linux system, is averaged over 10 
> runs:
>
> *Old*: 686.9 ± 7.6 ms
> *New*: 290.4 ± 4.1 ms (284.3 ± 4.2 on the WebAssembly side plus 6.0 ± 2.3 
> on the JavaScript side)
>
> This is the time to render a simple 800×800 gradient pattern.
>
> I hope others find this useful.
>
> — Scott
>

-- 
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/c5e6ec50-c391-427b-8c00-01cf175e24d1n%40googlegroups.com.


Re: [go-nuts] When set time.Location, will be detected Data Race

2020-07-24 Thread Steven Hartland

Always serialise t.UTC()?

On 24/07/2020 04:26, Mike Cohen wrote:
To be clear, the time.MarshalJSON() function produces valid RFC 3339 
timestamps which allow arbitrary timezones. This means that local time 
offset is used in the string representation. Although all 
representations are technically equivalent their string form is not so 
we need to do special parsing to compare them (and users get really 
confused as well).


Here is an example -
https://play.golang.org/p/hELVEI1tGJd

when I run it I get {"A":6,"B":"2009-11-11T10:00:00+11:00"}  for 
Australia time, but

 {"A":6,"B":"2009-11-10T18:00:00-05:00"} for America/New_York.

I am aware I can use the .In() method to cast the time.Time object 
into different timezone but this is the whole issue - I need to search 
through all the struct fields, expand slices, recurse through maps etc 
just to find any time.Time objects and change them **before** I call 
json.Marshal().


I usually get the times from a struct in another library so I have no 
control over how these times are made for example consider this

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

where I call an out of tree library to build a struct then just want 
to dump it - I have no control over the encoding.


I think this is a actually a limitation in the json strategy of 
encoding based only on types and not on context. The TZ issue is just 
a manifestation of that - even if there was a safe way to set TZ in a 
running program, in a multithreaded program all json encoders would be 
forced to use the same local TZ because encoding goes with type and 
not with context.


Thanks.
Mike


On Thu, 2020-07-23 at 20:02 -0700, Ian Lance Taylor wrote:

On Thu, Jul 23, 2020 at 5:13 PM Michael Cohen <
scude...@gmail.com

> wrote:

Thanks Ian, this does not work as I mentioned because there is no way to 
guarantee that my init function will run before any of my libraries creating a 
time object (which many do as they start various background tasks).
Doing what you say is fragile because even if it appears to work, one day I 
might link a library and it will mysteriously break randomly (this happened to 
us previously).
Is this a bug in the time package? Or simply a bug or design shortfall in the 
json package? One way I thought to fix this issue is to simply fork the json 
encoder and handle time.Time structs specifically, but this obviously does not 
scale to eg yaml encoders etc.

I don't think it's a shortfall in the encoding/json package as such,
as that package knows nothing about times.  It's the time package that
implements an UnmarshalJSON.  Looking at that method, I'm a little
surprised at what you describe, since it just uses the timezone in the
JSON string.  It doesn't use the local timezone as far as I can see.
Can you show a small program that demonstrates the problem?
Ian

--

*Mike Cohen*
/Digital Paleontologist/

Velocidex Enterprises
https://www.velocidex.com

+61.470238491


--
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/55b1098d4ff2518143b249b4587b36b527797896.camel%40velocidex.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/d1075c07-991e-2506-29a1-7847df4cda66%40multiplay.co.uk.


[go-nuts] go module @latest found but does not contain package

2020-07-24 Thread Tong Sun
Hi, 

How to get around the following, go module @latest found but does not 
contain package? 

$ cd /tmp/015-file

$ GO111MODULE=on

$ go mod init github.com/mkideal/cli/015-file
go: creating new go.mod: module github.com/mkideal/cli/015-file

$ cat go.mod module github.com/mkideal/cli/015-file

go 1.14

$ go build
go: finding module for package github.com/mkideal/cli
go: finding module for package github.com/mkideal/cli/ext
main.go:6:2: module github.com/mkideal/cli@latest found (v0.2.2), but does not 
contain package github.com/mkideal/cli
main.go:7:2: module github.com/mkideal/cli@latest found (v0.2.2), but does not 
contain package github.com/mkideal/cli/ext

$ go get -v github.com/mkideal/cli
go: github.com/mkideal/cli upgrade => v0.2.2

$ go get -v ./...
go: finding module for package github.com/mkideal/cli
go: finding module for package github.com/mkideal/cli/ext
go: finding module for package github.com/mkideal/cli
go: finding module for package github.com/mkideal/cli/ext
main.go:6:2: module github.com/mkideal/cli@latest found (v0.2.2), but does not 
contain package github.com/mkideal/cli
main.go:7:2: module github.com/mkideal/cli@latest found (v0.2.2), but does not 
contain package github.com/mkideal/cli/ext

$ go version
go version go1.14.1 linux/amd64


This is under Ubuntu 20.04.

-- 
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/335986d7-9e28-43ca-9489-35e776e5576fo%40googlegroups.com.


Re: [go-nuts] When set time.Location, will be detected Data Race

2020-07-24 Thread Robert Engels
Yea, it is strange the the Json encoder api doesn’t allow the caller to provide 
a mashaller for any type. It would be trivial to change the code to do so. 

That being said I’m sure you can find custom json libs on the web that will do 
this. Or fork it yourself - it is not a lot of code. 

> On Jul 24, 2020, at 11:15 AM, Mike Cohen  wrote:
> 
> 
> To be clear, the time.MarshalJSON() function produces valid RFC 3339 
> timestamps which allow arbitrary timezones. This means that local time offset 
> is used in the string representation. Although all representations are 
> technically equivalent their string form is not so we need to do special 
> parsing to compare them (and users get really confused as well).
> 
> Here is an example - 
> https://play.golang.org/p/hELVEI1tGJd
> 
> when I run it I get {"A":6,"B":"2009-11-11T10:00:00+11:00"}  for Australia 
> time, but
>  {"A":6,"B":"2009-11-10T18:00:00-05:00"} for America/New_York.
> 
> I am aware I can use the .In() method to cast the time.Time object into 
> different timezone but this is the whole issue - I need to search through all 
> the struct fields, expand slices, recurse through maps etc just to find any 
> time.Time objects and change them **before** I call json.Marshal().
> 
> I usually get the times from a struct in another library so I have no control 
> over how these times are made for example consider this
> https://play.golang.org/p/HmGREBF2Hbd
> 
> where I call an out of tree library to build a struct then just want to dump 
> it - I have no control over the encoding.
> 
> I think this is a actually a limitation in the json strategy of encoding 
> based only on types and not on context. The TZ issue is just a manifestation 
> of that - even if there was a safe way to set TZ in a running program, in a 
> multithreaded program all json encoders would be forced to use the same local 
> TZ because encoding goes with type and not with context.
> 
> Thanks.
> Mike
> 
> 
>> On Thu, 2020-07-23 at 20:02 -0700, Ian Lance Taylor wrote:
>> On Thu, Jul 23, 2020 at 5:13 PM Michael Cohen <
>> scude...@gmail.com
>> > wrote:
>>> 
>>> Thanks Ian, this does not work as I mentioned because there is no way to 
>>> guarantee that my init function will run before any of my libraries 
>>> creating a time object (which many do as they start various background 
>>> tasks).
>>> 
>>> Doing what you say is fragile because even if it appears to work, one day I 
>>> might link a library and it will mysteriously break randomly (this happened 
>>> to us previously).
>>> 
>>> Is this a bug in the time package? Or simply a bug or design shortfall in 
>>> the json package? One way I thought to fix this issue is to simply fork the 
>>> json encoder and handle time.Time structs specifically, but this obviously 
>>> does not scale to eg yaml encoders etc.
>> 
>> I don't think it's a shortfall in the encoding/json package as such,
>> as that package knows nothing about times.  It's the time package that
>> implements an UnmarshalJSON.  Looking at that method, I'm a little
>> surprised at what you describe, since it just uses the timezone in the
>> JSON string.  It doesn't use the local timezone as far as I can see.
>> Can you show a small program that demonstrates the problem?
>> 
>> Ian
> -- 
> 
> Mike Cohen
> Digital Paleontologist
> 
> Velocidex Enterprises
> https://www.velocidex.com
> 
> +61.470238491
> 
> 
> -- 
> 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/55b1098d4ff2518143b249b4587b36b527797896.camel%40velocidex.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/A922E625-0344-4ADF-A8C0-17F79AE5809B%40ix.netcom.com.


[go-nuts] [Generics] function aliasing via variables broken for generic functions.

2020-07-24 Thread binary cat
Doing `var F = Foo` (where `Foo` is a generic function) fails with an error
like this: `prog.go2:21:9: cannot use generic function Foo (value of type
func(type T1, T2)(fst T1, snd T2) Bar(T1, T2)) without instantiation in
variable declaration`. Trying `var F = Foo[int,int]` fails with an error
like `prog.go2:21:9: expected expression`.

Personally, I think both of these should work (with the second being a
version of `Foo` that only accepts two ints), but the first one
definitely seems like an implementation error, as the first snippet works
fine if `Foo` is a non-generic function.

-- 
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/CAHtSCHLDZi7nTx_NtWHfOCGges0Y%3DQWTiCzdKWp4vpbVtmvAwQ%40mail.gmail.com.


[go-nuts] Re: [ANN] Gio: portable immediate mode GUI programs in Go for iOS/tvOS, Android, macOS, Linux, Windows

2020-07-24 Thread ososeodijie

>
> Hello, I do not want to drag us back but i really dont understand the way 
> to install gio everywhere i look the mwthod is not straightforward and i 
> dont ubderstand it can i know if there is a better way to install it
>
Thanks from Africa!

-- 
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/95331270-7039-4a1f-890e-89b0c4a767d5o%40googlegroups.com.


Re: [go-nuts] When set time.Location, will be detected Data Race

2020-07-24 Thread Mike Cohen
To be clear, the time.MarshalJSON() function produces valid RFC 3339
timestamps which allow arbitrary timezones. This means that local time
offset is used in the string representation. Although all
representations are technically equivalent their string form is not so
we need to do special parsing to compare them (and users get really
confused as well).
Here is an example - https://play.golang.org/p/hELVEI1tGJd
when I run it I get {"A":6,"B":"2009-11-11T10:00:00+11:00"}  for
Australia time, but {"A":6,"B":"2009-11-10T18:00:00-05:00"} for
America/New_York.
I am aware I can use the .In() method to cast the time.Time object into
different timezone but this is the whole issue - I need to search
through all the struct fields, expand slices, recurse through maps etc
just to find any time.Time objects and change them **before** I call
json.Marshal().
I usually get the times from a struct in another library so I have no
control over how these times are made for example consider this
https://play.golang.org/p/HmGREBF2Hbd
where I call an out of tree library to build a struct then just want to
dump it - I have no control over the encoding.
I think this is a actually a limitation in the json strategy of
encoding based only on types and not on context. The TZ issue is just a
manifestation of that - even if there was a safe way to set TZ in a
running program, in a multithreaded program all json encoders would be
forced to use the same local TZ because encoding goes with type and not
with context.
Thanks.Mike

On Thu, 2020-07-23 at 20:02 -0700, Ian Lance Taylor wrote:
> On Thu, Jul 23, 2020 at 5:13 PM Michael Cohen 
> wrote:
> > Thanks Ian, this does not work as I mentioned because there is no
> > way to guarantee that my init function will run before any of my
> > libraries creating a time object (which many do as they start
> > various background tasks).
> > Doing what you say is fragile because even if it appears to work,
> > one day I might link a library and it will mysteriously break
> > randomly (this happened to us previously).
> > Is this a bug in the time package? Or simply a bug or design
> > shortfall in the json package? One way I thought to fix this issue
> > is to simply fork the json encoder and handle time.Time structs
> > specifically, but this obviously does not scale to eg yaml encoders
> > etc.
> 
> I don't think it's a shortfall in the encoding/json package as
> such,as that package knows nothing about times.  It's the time
> package thatimplements an UnmarshalJSON.  Looking at that method, I'm
> a littlesurprised at what you describe, since it just uses the
> timezone in theJSON string.  It doesn't use the local timezone as far
> as I can see.Can you show a small program that demonstrates the
> problem?
> Ian
-- 
Mike Cohen
Digital Paleontologist

Velocidex Enterprises
https://www.velocidex.com

+61.470238491



-- 
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/55b1098d4ff2518143b249b4587b36b527797896.camel%40velocidex.com.


[go-nuts] Send a mail with a service account using Gmail API

2020-07-24 Thread Vincent Jouglard
Hi there,

I have been trying for quite some time to get over an error while trying to 
send an email using a service account, via the Gmail API.
I get:

> googleapi: Error 400: Precondition check failed., failedPrecondition


Code is:
package gmailApi

import (
   "encoding/base64"
   "fmt"
   "net/mail"
   "strings"

"golang.org/x/net/context"
   "google.golang.org/api/gmail/v1"
   "google.golang.org/api/option"
)

func SendEmailVerification() {
   srv, err := gmail.NewService(context.Background(), option.
WithCredentialsFile("credentials.json"), option.WithScopes(
"https://mail.google.com/";, "https://www.googleapis.com/auth/gmail.modify";, 
"https://www.googleapis.com/auth/gmail.compose";, 
"https://www.googleapis.com/auth/gmail.send";))
   if err != nil {
   fmt.Println(err) // BUG(Vincent): TEST
   }

   // New message for our gmail service to send
   var message gmail.Message
   // Compose the message

// @ symbol modified for publishing on golang-nuts
   messageStr := []byte(
   "From: vincent[at]gamifly.gg\r\n" +
   "To: jouglardv[at]gmail.com\r\n" +
   "Subject: My first Gmail API message\r\n\r\n" +
   "Message body goes here!")

// Place messageStr into message.Raw in base64 encoded format
   message.Raw = base64.URLEncoding.EncodeToString(messageStr)

if rslt, err := srv.Users.GetProfile("me").Do(); err != nil {
   fmt.Println(err) // BUG(Vincent): TEST
   } else {
   fmt.Println("111", rslt)
   }

msg := ComposeMessage()
   _, err = srv.Users.Messages.Send("me", msg).Do()
   if err != nil {
   fmt.Println(err) // BUG(Vincent): TEST
   } else {
   fmt.Println("OKOKOK")
   }
}

func ComposeMessage() *gmail.Message {
   from := mail.Address{"Vincent", "vincent[at]gamifly.gg"} // @ symbol 
modified for publishing on golang-nuts
   to := mail.Address{"Vincent", "jouglardv[at]gmail.com"} // @ symbol 
modified for publishing on golang-nuts

header := make(map[string]string)
   header["From"] = from.String()
   header["To"] = to.String()
   header["Subject"] = encodeRFC2047("Hello, Gmail!")
   header["MIME-Version"] = "1.0"
   header["Content-Type"] = "text/plain; charset=\"utf-8\""
   header["Content-Transfer-Encoding"] = "base64"

var msg string
   for k, v := range header {
   msg += fmt.Sprintf("%s: %s\r\n", k, v)
   }
   msg += "\r\n" + "Message"

return &gmail.Message{
   Raw: base64.RawURLEncoding.EncodeToString([]byte(msg)),
   }
}

func encodeRFC2047(s string) string {
   // use mail's rfc2047 to encode any string
   addr := mail.Address{s, ""}
   return strings.Trim(addr.String(), " <>")
}


 
vincent[at]gamifly.gg is the GSuite user that is being impersonated.
jouglardv[at]gmail.com is a personnal address for testing purpose (plz 
don't spam <3 )

The service account has domain delegation activated, scopes that are passed 
are in API Controls > Domain-Wide Delegation: 

>
> https://www.googleapis.com/auth/gmail.send, https://mail.google.com/, 
> https://www.googleapis.com/auth/gmail.modify, 
> https://www.googleapis.com/auth/gmail.compose



Is there anything wrong that I may be doing ?
Thanks guys

-- 
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/91828beb-a29f-46e9-a30c-a35e2757b731o%40googlegroups.com.


[go-nuts] Re: golang in industrial projects

2020-07-24 Thread Erman Imer
Hello,

I completed device tests, fixed bugs and updated the repository.

Best regards...

On Tuesday, July 7, 2020 at 8:26:42 PM UTC+3, Erman Imer wrote:
>
> Hello,
>
> I am using these libraries to communicate with Siemens S7 and Modbus Tcp 
> devices in industrial projects.
>
> https://github.com/ermanimer/ict
>
> All comments are wellcome...
>

-- 
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/9e331e21-05da-4995-b0b7-40a59d0bb0a0o%40googlegroups.com.