Re: [go-nuts] Re: Where is the display profile from x/net/idna defined

2021-04-06 Thread Sam Whited
Yes sorry, I mean "where is it documented". The other profiles all list
the RFC from which the rules are taken, but this one does not.

—Sam

On Mon, Apr 5, 2021, at 11:58, jake...@gmail.com wrote:
> I'm guessing you want to know where the behavior is documented? That I
> do not know.

-- 
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/b3a0736c-3a26-4abb-a5e9-73f327365871%40www.fastmail.com.


Re: [go-nuts] Should reads from a net.Conn be made to respect a context deadline

2021-04-06 Thread Sam Whited
Thanks Ian,

On Sun, Apr 4, 2021, at 19:42, Ian Lance Taylor wrote:
> Speaking more broadly, while a context is often a deadline, it can
> also be cancelled for other reasons (via ctx.WithCancel).  Those other
> reasons can include things like "we no longer need this data."  So
> that is an argument for why the context should be honored even if
> there is a deadline.

I don't know that the deadline is necessarily the important part (since
the same applies to the conn itself which can be canceled by the user
with conn.SetDeadline(time.Unix(1,0) or something along those line). But
I take your point about the semantics of the context meaning "cancel
this action".

—Sam

-- 
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/8d88e430-7e3c-4894-8a04-ca21126d38a5%40www.fastmail.com.


Re: [go-nuts] Go code review site?

2021-04-04 Thread Sam Whited
It's not official or Go-specific, but you could try:

https://codereview.stackexchange.com/

—Sam

On Sun, Apr 4, 2021, at 09:20, Tong Sun wrote:
> I remember I've been to a page/site where people can ask for review for 
> their open source projects, commits, etc. 
> 
> Is there such site/service, or my memory has fainted (e.g., it's for go 
> core only etc)?

-- 
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/e5d6ecbe-f2b9-466f-8f44-06b583b8fe34%40www.fastmail.com.


[go-nuts] Should reads from a net.Conn be made to respect a context deadline

2021-04-04 Thread Sam Whited
In a library I have a `func(context.Context, net.Conn)' (more or less,
https://godoc.org/mellium.im/xmpp#NewSession). The context is used
throughout the function to eg. break out of loops, gets passed into
other functions, etc. and the conn is read from. If the user creates and
passes in a context with a deadline and also sets a deadline on the
conn, should I also cancel reads/writes from the conn when the context
is expired, or allow the user the maximum flexibility of setting their
own deadline on both?

I've asked this elsewhere (and am copying it here to reach a wider
audience) and the responses I've gotten seem to fall into:

- The user might have set a deadline on the conn already and overriding
  it defies user expectations, and
- The user expects that when the context is canceled the function stops
  blocking, so you have to cancel any reads/writes on the conn too
  otherwise the function could keep blocking, defying user expectation

I've gone back and forth a couple of times on how I'd expect this to
behave and I couldn't find any obvious examples in the standard
library that would suggest there's a convention so I'd love to get
other opinions.

—Sam

-- 
Sam Whited

-- 
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/beb46971-5c8c-43af-be78-b21a7529655a%40www.fastmail.com.


[go-nuts] Where is the display profile from x/net/idna defined

2021-04-04 Thread Sam Whited
Hi all,

Does anyone know where the Display profile from x/net/idna [1] is
defined?

I thought it corresponded to the rules defined in RFC 5895 [2], but it
also appears to apply the Bidi rule and some other things not defined
there. Unlike the other profiles the Display one has no comment saying
where it's defined.

Thanks for the help.

—Sam

[1]: https://pkg.go.dev/golang.org/x/net/idna#Display
[2]:https://tools.ietf.org/html/rfc5895

-- 
Sam Whited

-- 
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/03705e27-5434-4e47-8d53-17d636cf7a43%40www.fastmail.com.


Re: [go-nuts] using the xml package with data with complex name spacing

2020-12-14 Thread Sam Whited
In the example you provided it is working as expected. The element
you're unmarshaling is in the "
http://www.w3.org/1999/02/22-rdf-syntax-ns#; namespace (it has an "rdf"
prefix) but the thing you're unmarshaling it into expects
"http://purl.obolibrary.org/obo/go/subsets/goslim_yeast.owl#; because you
put that in the tag.

If you change the namespace in the struct to the correct one everything will 
work.

—Sam

On Sun, Dec 13, 2020, at 22:25, 'Dan Kortschak' via golang-nuts wrote:
> I'm needing to consume some XML which has a namespace
> identifier reused.

-- 
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/cefacd09-2b91-407e-939e-22b920969644%40www.fastmail.com.


Re: [go-nuts] draft design for // +build replacement

2020-06-30 Thread Sam Whited
I agree. I like the filename based constraints, but having both is
annoying and since the comment based constraints are more flexible I
think they'd have to be the ones to stay. I frequently find myself
looking for constraints by grepping for whatever it is I want, but if I
have filename based constraints I have to do a find as well. Having one
or another but not both would make my life easier in a small but
meaningful way.

—Sam

On Tue, Jun 30, 2020, at 18:56, roger peppe wrote:
> One thing I'd really like to see is the eventual deprecation of filename-
> based build constraints (e.g. file_linux.go). They make it hard for
> users (not everyone knows the name of all architectures), hard for
> tooling (tools need to maintain a list of current architectures) and
> potentially compatibility-breaking (adding a new architecture can
> change the meaning of existing files). Could we eventually mandate in-
> file build constraints instead?

-- 
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/09cfada5-0e6d-4e0b-9d63-6e5963530a42%40www.fastmail.com.


Re: [go-nuts] What is empty or nil interface (e.g. interface{})

2020-06-23 Thread Sam Whited
The Go tour has a section on this that might be helpful:
https://tour.golang.org/methods/14

It matches any type, and should be avoided at all costs unless you
really know what you're doing. It sounds great, but it will probably
hurt you unless you have a deeper understanding of writing good Go code.

—Sam

On Mon, Jun 22, 2020, at 22:05, netconnect.m...@gmail.com wrote:
> I see this occasionally used as an argument? What's the benefit?

-- 
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/7becf384-c8a7-4bc7-bc05-adcedba9dc1f%40www.fastmail.com.


Re: [go-nuts] Re: political fundraising on golang.org!

2020-06-18 Thread Sam Whited
I should rephrase that, "it's an important discussion *for this
community*" and I think it's as important to expose this community to it
as it is any other.

On Fri, Jun 19, 2020, at 00:20, Ian Lance Taylor wrote:
> On Thu, Jun 18, 2020 at 9:04 PM Sam Whited  wrote:
> >
> > On Thu, Jun 18, 2020, at 22:00, 人间不值得 wrote:
> > > I thought, Everyone live matters. not just only Black. (White,
> > > yellow..) Did their lives matter?
> >
> > Of course they do. You seem, deliberately or not, to be missing the
> > obvious but implicit ", also". No one goes up to someone at a breast
> > cancer awareness march and says "what's wrong with you, don't you
> > know that colon cancer is important too?" so ask yourself why you
> > and so many others insist on doing this to the black lives matter
> > movement.
> >
> >
> > On Thu, Jun 18, 2020, at 23:59, Ian Lance Taylor wrote:
> > > Please respect my request to let this thread drop.
> >
> > This is an important discussion to have, I don't think it's fair or
> > appropriate to ask people to just drop it.
>
>
> It's an important discussion, but having it on golang-nuts is not
> working.
>
> It can continue off-list.
>
> Thanks.
>
> 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/CAOyqgcXkA5OM%2BXcpMiJ6QNY48CE9ZUS6JophuSZ98Zs57n5-2g%40mail.gmail.com.
>

-- 
Sam Whited

-- 
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/cff66e28-ef98-48b7-ac19-694ad3a2a003%40www.fastmail.com.


Re: [go-nuts] Re: political fundraising on golang.org!

2020-06-16 Thread Sam Whited
So you're suggesting that because we can't help all people all of the
time we should help no one at any time? That is a logical fallacy. Right
now in this moment there are protests all over the world about a
specific issue, so yes, a specific cause is being supported because the
time is right, and that is perfectly okay.

—Sam

On Mon, Jun 15, 2020, at 21:53, sanye wrote:
> > Because there are hundreds or thousands of initiatives to support
> > suffering and dying people in African, Asian, Eastern European, and
> > what else countries that will never be supported by top banner at
> > golang.org.
>  That's right.

-- 
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/8191276c-7f8e-418b-b46f-0d1614a59885%40www.fastmail.com.


Re: [go-nuts] political fundraising on golang.org!

2020-06-15 Thread Sam Whited
I think long years of experience has shown that this is not the case.
This argument is made frequently and amounts to "let's just ignore the
issues and hope they go away because they only affect a minority among
us". This is one of the reasons for the lack of diversity in this
industry (at least within the United States, I certainly can't speak for
everywhere else).

—Sam

On Mon, Jun 15, 2020, at 10:05, Marvin Renich wrote:
> In what way does not having the banner affect how welcome people feel
> on the Go lists and websites?  As long as the discussions on these
> lists and websites remain technical, everyone should feel welcome.

-- 
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/62c0ed98-dc7b-4c96-8cbf-df3215dc5a3e%40www.fastmail.com.


Re: [go-nuts] political fundraising on golang.org!

2020-06-15 Thread Sam Whited
If the argument were what specific charity to put in the banner this
might be a discussion worth having, however I get the impression that
many of these people are arguing against including a banner at all.

On Mon, Jun 15, 2020, at 10:04, Robert Engels wrote:
> I think a more specific point to be made is that it is a few select
> people speaking for the community. In fact, the associating of BLM
> with the EJI is suspect. Neither org associates with the other and
> their platforms are in many ways Incompatible.
>
> As a 30+ year major inner city dweller I can testify the issues
> are complex and nuanced, and people should be really hesitant
> when speaking for others under the assumption they know what’s
> best for them.

-- 
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/46e17ada-2da5-4b55-9443-1eb40350255f%40www.fastmail.com.


Re: [go-nuts] political fundraising on golang.org!

2020-06-15 Thread Sam Whited
You're starting from the assumption that anything off-topic to the
language itself is bad. Why do you hold this position?

Even if we accept your position that anything slightly off topic is bad
(although I do not accept that position), this topic is relevant to
everyone trying to build a more diverse and equitable community, and Go
is as much a community of people as it is a language.

—Sam

On Mon, Jun 15, 2020, at 09:43, Marvin Renich wrote:
> My opinion, and the way I interpreted Peter's original post, is that
> this banner is extremely inappropriate, independent of its social or
> political views, because it is completely off-topic for the
> discussion of the Go language and introduces a highly controversial
> non-technical issue into places where people go to discuss a specific
> technical topic.

-- 
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/cb53462f-0833-4702-b2e2-01579136bfa3%40www.fastmail.com.


Re: [go-nuts] political fundraising on golang.org!

2020-06-15 Thread Sam Whited
This is an important issue about the Go Community and who feels welcomed
here, which is also covered by this mailing list.

On Mon, Jun 15, 2020, at 09:18, K Davidson wrote:
> Please keep posts limited to things about go.

-- 
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/0030c85d-7de5-4542-8f96-db3d0e7932cf%40www.fastmail.com.


Re: [go-nuts] Re: political fundraising on golang.org!

2020-06-15 Thread Sam Whited
Why is it disrespectful to the rest of the world? In what way does
supporting the Black Lives Matter movement and an important not-for-
profit diminish from other problems that also need solving?

One of my neighbors recently put it this way: would you walk up to
someone at a breast cancer awareness march and ask "what's wrong with
you, don't you know that all cancers matter?!". Of course you wouldn't.
So ask yourself why people are so willing to do that with this issue in
particular.

—Sam

On Mon, Jun 15, 2020, at 08:58, Space A. wrote:
> Agree with Peter. It's not the right place and time and disrespectful
> for the rest of the World. You don't even imagine what problems,
> social or political, people who live far away from US face each and
> every day.

-- 
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/ac546b4a-379a-4a5f-92dd-48936131aa45%40www.fastmail.com.


Re: [go-nuts] political fundraising on golang.org!

2020-06-14 Thread Sam Whited
What makes you think this is somehow politics and not simply supporting
an important not-for-profit at a time when it's particularly relevant
and important to do so? I don't see anything political about the topic
unless you count that some of the solutions are political (but this one,
donating to a respected non-profit, is not, so I still don't understand
your point).

—Sam

On Sun, Jun 14, 2020, at 16:44, Eric S. Raymond wrote:
> It is the injection of politics into a list where politics does
> not belong.

-- 
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/d7710db8-7e16-4e36-aa76-627de71cb7e9%40www.fastmail.com.


Re: [go-nuts] political fundraising on golang.org!

2020-06-14 Thread Sam Whited
They are directed to the Equal Justice Initiative which is a non-profit.
In the united states 501(c)3 not-for-profit organizations are barred
from certain kinds of political speech including endorsing individual
parties or candidates. The banner does not point to any particular
political party.

—Sam

On Sun, Jun 14, 2020, at 10:10, Robert Engels wrote:
> I agree it is an important social issue, but in this particular case I
> believe the funds are directed to specific political parties so the
> boundary between supporting social issues and political contributions
> is murky. I am not saying it shouldn’t be done but it should be more
> transparent.

-- 
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/73d53e75-cee0-44a7-8ce7-2ffb029b1b5b%40www.fastmail.com.


Re: [go-nuts] political fundraising on golang.org!

2020-06-14 Thread Sam Whited
This is not a simple political issue, it is a personal human issue. It
is a social issue. It is a justice issue. It seems quite obvious to me
that this is different than if they had put a fundraiser for a candidate
for office, for instance, in a banner.

It amazes me how often people come out of the wood work to criticize the
politicization of things as soon as anyone posts a black lives matter
banner, but would be perfectly happy with banners for another cause. Of
course, I don't know if that's you or not, so I'll leave you with some
questions: If you have a problem with this, consider whether you'd have
the same problem with a banner for a cancer research foundation during
the U.S.'s cancer awareness month, for example. If the answer is no,
consider why that might be and work on it. If the answer is yes consider
why a banner that doesn't hurt you but could help a lot of people
bothers you so much.

This *is* related to Go, because it's a community issue and Go is a
community as much as it's a language. Communities of privilege staying
silent on these matters and leaving it up to others, often to
communities that have expended many generations worth of emotional
capital on this already and who often are dismissed by the very people
who need to hear their message, is part of the problem. We don't want to
be part of the problem, so let's do our part, however small, with the
platforms we have.

—Sam

-- 
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/cdacd7f0-311a-4976-b2cb-c677e28c05fc%40www.fastmail.com.


Re: [go-nuts] Re: gzip.Reader.Read does not fill the given buffer

2020-06-09 Thread Sam Whited
Read lets you build pipelines, it involves fewer expensive allocations
(ie. you might not want to use ReadFull in the hot path of an important
project), you could use read to read into a slice at different points,
or not read the entirety of an expensive document into memory all at
once, you can implement buffering on top of it, etc.

It's probably pretty rare that you actually want to use ReadFull, or at
least, I don't find myself reaching for it very often.

—Sam


On Tue, Jun 9, 2020, at 12:51, Amit Lavon wrote:
> Thank you!! io.ReadFull is just what I needed (and what I actually
> expected from Reader.Read). Why would I ever use Reader.Read rather
> than ReadFull?
>
> On Tue, Jun 9, 2020 at 6:11 PM Brian Candler
>  wrote:
> > There is io.ReadFull <https://golang.org/pkg/io/#ReadFull> if you
> > want to read as much as it can into the preallocated buffer; you'll
> > get io.ErrUnexpectedEOF if it's less than this.
> > https://play.golang.org/p/gIAX046vNvW
> >
> > There is ioutil.ReadAll <https://golang.org/pkg/io/ioutil/#ReadAll>
> > if you want to allocate memory to read the entire stream into a
> > single buffer (assuming you have enough RAM)
> > https://play.golang.org/p/Pg17S6A74SN
>
> >  --
> >  You received this message because you are subscribed to a topic in
> >  the Google Groups "golang-nuts" group. To unsubscribe from this
> >  topic, visit
> >  https://groups.google.com/d/topic/golang-nuts/u-wNH3NyMHo/unsubscribe.
> >  To unsubscribe from this group and all its topics, 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/8ff054df-218c-4d52-8984-83b1ced9o%40googlegroups.com
> >  
> > <https://groups.google.com/d/msgid/golang-nuts/8ff054df-218c-4d52-8984-83b1ced9o%40googlegroups.com?utm_medium=email_source=footer>
> >  .
>
>  --
>  You received this message because you are subscribed to the Google
>  Groups "golang-nuts" group. To unsubscribe from this group and stop
>  receiving emails from it, send an email to golang-
>  nuts+unsubscr...@googlegroups.com. To view this discussion on the web
>  visit
>  
> https://groups.google.com/d/msgid/golang-nuts/CAPTkDQVudE24DF6tWBO6yFTyF4TgZOopEfjnqZXLhVphp8SBwQ%40mail.gmail.com
>  
> <https://groups.google.com/d/msgid/golang-nuts/CAPTkDQVudE24DF6tWBO6yFTyF4TgZOopEfjnqZXLhVphp8SBwQ%40mail.gmail.com?utm_medium=email_source=footer>
>  .

-- 
Sam Whited

-- 
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/b203a7e4-0275-46c5-9b1e-05ed7a140e8e%40www.fastmail.com.


Re: [go-nuts] compress/bzip2:Why is there only a decompression function, no compression function.

2020-06-08 Thread Sam Whited
See: https://github.com/golang/go/issues/4828

On Mon, Jun 8, 2020, at 05:09, lziqia...@gmail.com wrote:
> Why is there no bzip2 compression algorithm, what is the reason? Do you 
> need to add it?

—Sam

-- 
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/4e2007ea-0215-41d3-afdc-1f77330dbdbd%40www.fastmail.com.


Re: [go-nuts] Is there a way to create a global variable inside go routine stack? so that i can access any time, without passing around between methods/functions. Crazy thought !!!..

2020-05-23 Thread Sam Whited
You are describing a thread-local variable (or a goroutine local
variable, I suppose). The Go authors didn't feel this was an appropriate
feature for Go and it is not supported.

You may find some third party libraries that do this by parsing stack
traces and using them to index into maps or similar techniques, but
these could break at any moment and you should avoid them at all costs.

—Sam

On Sat, May 23, 2020, at 15:34, adithyasasha...@gmail.com wrote:
> Is there a way to create a global variable inside go routine stack? so
> that i can access any time, without passing around between
> methods/functions. Crazy thought !!!..


-- 
Sam Whited

-- 
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/b4ed0a33-b538-499a-8753-13388b9a58f6%40www.fastmail.com.


Re: [go-nuts] Benchmarking code that mutates its input data

2020-03-18 Thread Sam Whited
I'd like to quickly suggest that the "filtering without allocating"
technique from this page is probably what you want and you may want to
consider if/why you even need to benchmark this:
https://github.com/golang/go/wiki/SliceTricks

However, if you do need to benchmark it:

On Wed, Mar 18, 2020, at 11:46, Orson Cart wrote:
> - if the profiler were to call the function 1000 times, only the first
> call will have done any actual work. To make the benchmarked function
> do the same work each time we'd have to set up fresh data for each
> call to the function. We can do that but we don't want that setup to
> show in the timing for the benchmark.
>
> Does anyone know of a solution to this?

Just call b.ResetTimer() after setting up your data: 
https://godoc.org/testing#B.ResetTimer

—Sam

-- 
Sam Whited

-- 
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/6b8fcaa6-0c14-4e9c-8a22-71b9154dac7a%40www.fastmail.com.


Re: [go-nuts] Re: RFC Package structuring

2020-03-03 Thread Sam Whited
On Tue, Mar 3, 2020, at 10:09, Rizwan Iqbal wrote:
> I would avoid multiple go.mod files in one repository as well. I
> generally follow the rule of thumb, one module per repository.

I generally follow this advice too, however, I make an exception for
modules that don't need to be versioned. For example, I keep a separate
module for "example" or "demo" directories so that their dependencies
don't wind up in my libraries go.mod file. This isn't a problem though
because I'll never tag or version the demos, they're just there to give
you an example of how to use the library.

—Sam

-- 
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/abd7f470-4a7d-46da-8c59-0f73bd983581%40www.fastmail.com.


Re: [go-nuts] Question about the zero-value design: Why pointers zero value is not the zero value of what they points to?

2020-02-17 Thread Sam Whited
I think you need to run your example; the behavior is the same: trying
to make an assignment to the non-nested map will panic contrary to what
your comment says.

> panic: assignment to entry in nil map

—Sam

On Mon, Feb 17, 2020, at 10:35, Michel Levieux wrote:
> Hi Kloster08,
>
> In addition to what others have already pointed out, I'd like to bring
> you another case that seems problematic to me concerning the
> construction of a "usable nil value" for maps, in the sense that a zero-
> value map could be written and read right away without any
> initialization.
>
> Here is the example: https://play.golang.org/p/t5RsM1JY3eQ
>
> Notice in this example that a nested map would not have the same
> behaviour as a non-nested one if they can't be allocated properly,
> which adds complexity to the language. Also, how would the compiler
> know if the value retrieved is going to be read-only (I have a huge
> number of examples coming to mind where this would be the case), in
> which case one *does not* want the map to be allocated (the current
> behaviour is perfect for the use), or if it will be written at some
> point in the future.
>
> Some workarounds might exist, but I think it'd either be irrelevant a
> win (if a win it is) and a tremendous amount of work in comparison.
> Let aside all code that relies on the current behaviour of nil maps,
> be it a "good" or "bad" practice, and that would break because of this
> kind of change in the language.
>
> Hope this helps,
>
> M.Levieux
>
> Le lun. 17 févr. 2020 à 15:06, 'Axel Wagner' via golang-nuts  n...@googlegroups.com> a écrit :
> > On Mon, Feb 17, 2020 at 11:18 AM  wrote:
> >> Out of curiosity: Could you please tell when calling methods on nil
> >> pointers is useful?
> >
> > In general, linked datastructures - like linked lists or trees. As a
> > somewhat trivial example, consider this:
> > https://play.golang.org/p/Y-4aSVLzEFO Interpreting a nil-pointer as
> > "an empty tree" makes a lot of the traversal-algorithms easier to
> > express. I also have an internal package that wraps the
> > openat/mkdirat/linkat/… class of syscalls, to make it possible to
> > still read/write a directory that has been bind-mounted over. It
> > uses a struct to encapsulate the file-descriptor of that directory,
> > which is used as a pointer to keep track of whether it has been
> > closed and such. It also interprets a nil-pointer as "relative to
> > the current directory" (it uses AT_FDCWD). I could, of course, also
> > use the zero-value of that struct for that (in fact, I do as well),
> > but as there is a meaningful way to interpret a nil-pointer, there's
> > no harm in doing so as well.
> >
> > In general, it's of course never *necessary* to interpret a nil-
> > pointer a specific way. But it does sometimes make things easier to
> > express or nicer to use.
> >
> > BTW, as far as slices are concerned: They behave strikingly similar
> > to maps, as far as the zero-value is concerned - in that all read-
> > operations work just fine on both a nil-map and a nil-slice, it's
> > just that write-operations panic (and again, in both cases). The
> > main difference between them is that *non*-nil maps behave very
> > differently. We don't tend to notice the "uselessness" of nil-slices
> > in general, though, because we tend to either assume a certain size
> > for them (in which case they can't be nil) or we check the length
> > beforehand (just like checking if a map is nil) when writing to
> > them. i.e. the read-operations are far more common with slices and
> > we find the idea of "checking" their nil-ness via ranging over them
> > or explicitly checking their len somewhat more natural.
>
> >  --
> >  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/CAEkBMfHAfA97soJy1iXea1H7Bkv_VO%3D43cLY96zi%2BZ7R0a%3DbTQ%40mail.gmail.com
> >  
> > <https://groups.google.com/d/msgid/golang-nuts/CAEkBMfHAfA97soJy1iXea1H7Bkv_VO%3D43cLY96zi%2BZ7R0a%3DbTQ%40mail.gmail.com?utm_medium=email_source=footer>
> >  .
>
>  --
>  You received this message because you are subscribed to the Google
>  Groups "golang-nuts" group. To unsubscribe from this group and stop
>  receiving emails from it, send an email to golang-
>  nuts+unsubsc

Re: [go-nuts] Question about the zero-value design: Why pointers zero value is not the zero value of what they points to?

2020-02-14 Thread Sam Whited
On Fri, Feb 14, 2020, at 09:16, kloste...@gmail.com wrote:
> *Could you please let me know the reasons why the zero value of a
> pointer is `nil` instead of a pointer to the zero value of what it
> points to?*
>
> Is it because of performance/memory? Simplicity in the runtime?

The zero value is a zeroed chunk of memory with the given type. If
the zero value of the pointer were a pointer to something else, that
something else would have to be allocated and pointed too and the
pointer itself would lose the nice property of being a zeroed chunk
of memory (it wouldn't be a zero value).

—Sam

-- 
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/a34818b1-0e3f-4712-ade4-d5e4f921279b%40www.fastmail.com.


Re: [go-nuts] Requesting help with the code

2020-01-27 Thread Sam Whited
On Mon, Jan 27, 2020, at 02:41, Kareem Shaikh wrote:
> Can anyone please tell me what should I change in order to get the right 
> output?
> 
> For example:
> 
> I want to change 10 degrees to Fahrenheit.
> I want to print "10 degrees to Fahrenheit is = 50"

You want to use one of the formatting functions, for example:

fmt.Printf("%f Degrees to Fahrenheit is = %f\n", Degrees, fahrenheit)

For more information, see the fmt documentation: https://godoc.org/fmt

—Sam

-- 
Sam Whited

-- 
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/794b0ae1-dcd7-41d0-aada-d5093307997f%40www.fastmail.com.


Re: [go-nuts] Is it possible to get code coverage information in a way that does not assume you can see color?

2020-01-09 Thread Sam Whited
On Thu, Jan 9, 2020, at 08:50, jared.stoff...@gmail.com wrote:
> I'm a totally blind developer who is trying to learn go. When running
>
> go tool cover -html=cover.out -o cover.html
>
> It appears the HTML generated uses color to show the lines of code
> that are not covered without any other way of identifying
> uncovered lines.

The title text of lines that are covered is "1" and the title text of
lines that are not covered is "0". This isn't ideal, but maybe you could
feed the HTML through a program that would rewrite this to something
visible to your screen reader or other device?

—Sam

-- 
Sam Whited

-- 
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/042444de-8275-47ae-ab64-990c76f22fc9%40www.fastmail.com.


Re: [go-nuts] module declares its path as: golang.org/x/lint but was required as: github.com/golang/lint

2019-11-21 Thread Sam Whited
Hi,

Thanks for posting to the list. A few quick points of order:

On Thu, Nov 21, 2019, at 12:48, Sying wrote:
> Is there anyone how to solve this problem?

Please don't use unnecessary formatting, the large bold text is a bit
off putting. You can speak normally and everyone will hear you, shouting
is not required :)

> https://github.com/micro/micro/issues/431 I have try server way, and
> it still occure the same error.

This does not appear to be the same issue as you mentioned in the
subject, maybe you're replying to an old thread that I no longer have?
If so, please post questions as new threads with a subject that
describes what you're asking. It helps sometimes if you describe your
issue in the message body too instead of just linking to another site
(this encourages people to answer your question inline).

Thanks again, and good luck!

—Sam

-- 
Sam Whited

-- 
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/b1bd3247-43ca-4ccc-bc17-fa84a7b947d3%40www.fastmail.com.


Re: [go-nuts] [ANN] go-resty v2.1.0 released - Simple HTTP and REST client library

2019-10-11 Thread Sam Whited
On Fri, Oct 11, 2019, at 21:24, Dimas Prawira wrote:
> Just test using got get

You appear to be using an old version of Go that doesn't support modules
or have it turned off or set to auto using the GO111MODULE environment
variable. If you upgrade to Go 1.13 and make sure GO111MODULE isn't set,
it should default to being on.

https://github.com/go-resty/resty/blob/v2.0.0/go.mod

—Sam

-- 
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/0cab0ea1-d1d1-4121-ac8e-cecb104fd573%40www.fastmail.com.


Re: [go-nuts] [ANN] go-resty v2.1.0 released - Simple HTTP and REST client library

2019-10-11 Thread Sam Whited



On Fri, Oct 11, 2019, at 20:55, Dimas Prawira wrote:
> Stable Version : github.com/go-resty/resty/v2
>
> got 404 (not found)

That is a Go import line with a module major version suffix, not a
GitHub URL. The fact that they look the same instead of using some other
syntax is extremely annoying, but we're stuck with it, unfortunately.

—Sam

-- 
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/c11eb80d-b2df-4793-804f-3017a2e81dca%40www.fastmail.com.


Re: [go-nuts] Golang library for - ORM & Schema Migration

2019-10-01 Thread Sam Whited
On Mon, Sep 30, 2019, at 21:05, bram wrote:
> Thank you all. For schema migration i am looking for similar tool
> like flyway.

I'm not sure if it's like flyway, but I use a library that I wrote,
code.soquee.net/migration [1]. The idea is that it gives you the tools
you need to write a migration command instead of being a separate
migration tool, this way your application can handle its own migrations
(this makes it really easy to distribute your application to customers
if you have an on-premis version that their ops people will need to run
migrations on). It is designed to run migrations from a folder or
embedded filesystem (eg. using statik [2] or pkgzip [3]). Currently it
is compatible with Diesel and supports PostgreSQL, but it could likely
be made to support whatever you're using easily enough.

—Sam

[1]: https://godoc.org/code.soquee.net/migration
[2]: https://godoc.org/github.com/rakyll/statik
[3]: https://godoc.org/code.soquee.net/pkgzip

-- 
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/ee783450-0354-41d7-8d7f-67c0498cf9c1%40www.fastmail.com.


Re: [go-nuts] How to mock functions in Go ?

2019-09-20 Thread Sam Whited
On Thu, Aug 1, 2019, at 12:09, Nitish Saboo wrote:
> How can we mock a function in Go like os.Hostname() or os.Getwd()
> ? Any framework or Library that we can use for mocking the
> function calls ?

I don't like to think about "mocking" in Go, but I can't provide an
alternative term so maybe this is overly pedantic (or maybe one
isn't needed).

For something like this, I prefer to avoid global state like others have
suggested: eventually, you'll run a test in parallel, try to reuse that
state, etc and it will lead to race conditions. You may think you won't
now, but it's not a problem until it's a problem so you might as well
avoid it. Instead, I'd just pass in a hostname to use. If this isn't
something that makes sense in the public API, put it in an internal
function and test that:

  // Foo is a public API that needs a hostname.
  func Foo() {
hostname, err := os.Hostname()
// error handling
  
foo(hostname)
  }

  // test this
  func foo(hostname string) {
// …
  }

I also prefer to only test published methods using a _testing package,
and this flies in the face of that advice a bit but in a situation like
this I think it's by far the simplest solution that won't lead to
headaches later.

—Sam

-- 
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/4430f2a5-e3ff-497a-a3cd-0f0233778e6c%40www.fastmail.com.


Re: [go-nuts] Re: go mod dependency hell is real

2019-09-10 Thread Sam Whited
Note that replace directives are not transitive, so every single user of
your library will need to do this. You can put it into your go.mod file
to get your library building and get tests passing, but your users will
still have to do this work as well so you'll probably want to document
that they now have to jump through hoops to use your library.

—Sam

On Tue, Sep 10, 2019, at 13:10, Darko Luketic wrote:
> The answer is apparently
> https://github.com/gin-gonic/gin/issues/2039#issuecomment-527997733
>
> > Add this to your go.mod file: `replace github.com/ugorji/go v1.1.4
> > => github.com/ugorji/go v0.0.0-20190204201341-e444a5086c43`
> On Tuesday, September 10, 2019 at 2:48:25 PM UTC+2, Darko
> Luketic wrote:
> > What used to work pre go 1.13 now doesn't work anymore

-- 
Sam Whited

-- 
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/e0919343-21e4-4703-8790-d7ff8be857ef%40www.fastmail.com.


Re: [go-nuts] Go string and UTF-8

2019-08-20 Thread Sam Whited



On August 20, 2019 11:50:54 AM UTC, Rob Pike  wrote:
>Printf can print hexadecimal just fine. Never understood the point of
>encoding/hex.

I always thought that the C style format strings were unreadable and the hex 
package methods were much clearer, personally.

—Sam

-- 
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/4D22ED0E-1F1F-420B-8C26-3EF35F04EDCA%40samwhited.com.


Re: [go-nuts] Go string and UTF-8

2019-08-20 Thread Sam Whited
I personally wouldn't do this. If you're going to incur the overhead of a heap 
allocation, might as well incur a bit more and encode the hash, eg. using 
hex.EncodeToString [1], just so that you don't forget and try to print or 
decode the string as utf8 later.

—Sam

[1]: https://godoc.org/encoding/hex#EncodeToString

On August 20, 2019 8:12:20 AM UTC, Pierre Durand  wrote:
>I know that by convention Go string contain UTF-8 encoded text.
>
>Is it recommended/a good practice to store invalid bytes in a string ?
>
>The use case:
>- compute a hash => get a []byte
>- convert the []byte to string (this string is not UTF-8 valid)
>- use the string as a map key
>
>In my case, the hash algorithm is md5.

-- 
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/42989202-2854-479E-A536-13664BE41946%40samwhited.com.


Re: [go-nuts] Re: golang with XSLT

2019-08-19 Thread Sam Whited
On Mon, Aug 19, 2019, at 20:31, 'Eric Johnson' via golang-nuts wrote:
> Tips:
>  * When ever you're wondering about a good library for , two good 
> places to start are https://go-search.org , and 
> https://github.com/avelino/awesome-go.

Also try searching on https://godoc.org/

—Sam

-- 
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/1ab80c87-589b-4504-a00d-14e2413c758c%40www.fastmail.com.


Re: [go-nuts] About the Google logo on the new Go website

2019-07-15 Thread Sam Whited
On Mon, Jul 15, 2019, at 16:54, Wojciech S. Czarnecki wrote:
> Neither go-nuts list is a proper venue for the Big Enders and Little
> Enders fight. Please keep this mailing list clean.

This is the place for Go discussion. Not everyone in the community has
an account on Reddit, or even GitHub, but they likely have an email.
This is probably the best place to push back against Google slowly
reeling in Go and trying to more tightly couple it with the corporation.

—Sam

-- 
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/3c3f6669-46c1-464f-ae00-a0f375655a77%40www.fastmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] About the Google logo on the new Go website

2019-07-15 Thread Sam Whited
On Mon, Jul 15, 2019, at 15:40, Michal Strba wrote:
> What do you think? For example, Rust has no Mozilla logo on its page
> despite being largely funded by it.

Google funds a great deal of Go development, but it seems extremely
narcissistic of them to put their corporate logo on something that a lot
of other people who aren't a part of Google, and don't get a paycheck
from Google have also put their time into. As you said, other
corporations don't feel the need to stick their logo all over
everything.

Go belongs to more than just Google. The copyright statement says "The
Go Contributors". Google (and the core Go team that works for them) are
just one of those Contributors. Should we put every company that's ever
signed the CLA on the website too?

—Sam

-- 
Sam Whited

-- 
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/403d0cd5-0fa4-4f32-88dc-6f0c3bb2236e%40www.fastmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] The "leave "if err != nil" alone?" anti-proposal

2019-07-14 Thread Sam Whited
On Sun, Jul 14, 2019, at 06:53, roger peppe wrote:
> As far as I can tell, that's almost identical to the scheme that I
> suggested here:
> https://github.com/golang/go/issues/19412#issuecomment-288485048

I hadn't seen that issue, I'll have to read through it. Thanks
for the link!

—Sam

-- 
Sam Whited

-- 
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/20f8852e-50b6-4b80-83e3-7b6de3cbc919%40www.fastmail.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Simple web components and other libraries

2019-07-12 Thread Sam Whited
Hi all,

I've been working on a side project for the last few months that
involved building a simple web app. As part of that, I ended up looking
for lots of libraries to do things like internationalization on server
rendered templates, generate one time passwords with TOTP, run
migrations, etc. and on occasion I ended up building my own when
existing libraries didn't feel very Go like, or had too many
dependencies. Now that I'm winding down, I've open sourced many of the
alternatives I've written.

At current count there are 11 small libraries that I've split out of my
application. These include:

- HOTP and TOTP one time password generation
- template rendering with i18n support and live reloading in dev mode
- generating unique image-hash avatars
- populating the environment from a file or other reader
- running and creating migrations for PostgreSQL in a way that's
  compatible with the Diesel tool
- an HTTP multiplexer that provides typed route parameters
- a tool for zipping static resources and including them in Go source
  files (this is a fork of JDB's statik that does not rely on import
  side effects)
- an error implementation similar to the errors defined in RFC7807
- a parser for the simple query language my project used for searching
  (probably not useful to anyone else, but you never know)
- a relative time implementation (eg. 10:00 AM to "one hour ago")
- a package for logging to test output (so that calls to logging while
  running tests only show up if the test failed and aggregated under the
  test that generated them).

More will likely come as I decide what to do with the project now
that it's winding down. I hope some of these are useful to others
here who may be dissatisfied with the larger web frameworks that have
become popular.

They can all be found here:

https://code.soquee.net/

—Sam

-- 
Sam Whited

-- 
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/fbfd9a13-f50b-4384-a5a2-ccf73e2bf8dc%40www.fastmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] The "leave "if err != nil" alone?" anti-proposal

2019-07-12 Thread Sam Whited
On Fri, Jul 12, 2019, at 06:31, Andrey Tcherepanov wrote:
> I haven't seen your proposal before, but it looks interesting - you
> seem to have put quite a thought into it already.

To be clear, this isn't actually a proposal. I was just toying with the
idea and there's really not much thought put into it; an actual
proposal would need a lot more work than what I've done here to make
sure it's complete and integrates well with the rest of the language.

—Sam

-- 
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/41890755-c472-4563-8935-3337a6e0ca2b%40www.fastmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] The "leave "if err != nil" alone?" anti-proposal

2019-07-12 Thread Sam Whited



On July 12, 2019 4:35:54 AM UTC, Andrey Tcherepanov 
 wrote:
>What these guys are proposing in that paper would be closer to
>(Go-style)
>func f() (v value | e error) { ... }
>
>(where "|" could be read as "or" or "union")
>

I've thought a tiny bit about how union or sum types would work in Go using a 
similar syntax. My initial thoughts are here in case this is of interest to 
anyone else:

https://blog.samwhited.com/2019/06/go-and-sum-types/

—Sam

-- 
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/2858C8AA-F25B-4415-A8D4-753DA679EC27%40samwhited.com.
For more options, visit https://groups.google.com/d/optout.


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

2019-05-29 Thread Sam Whited
On Thu, May 23, 2019, at 17:59, Ian Lance Taylor wrote:
> But (and here you'll just have to trust me) those executives, and
> upper management in general, have never made any attempt to affect how
> the Go language and tools and standard library are developed.  Of
> course, there's no reason for them to.  Go is doing fine, so why
> should they interfere?  And what could they gain if they did
> interfere?  So they leave us alone.

I wanted to further comment on this particular point, since I keep
seeing it brought up and have had it mentioned to me several times OOB
in the context of "why would you care if the Go team can push through
proposals and immediately merge implementations with limited community
input or without the opportunity for alternatives,?Google execs aren't
making these decisions, the Go team is!"

I believe you when you say that upper management has never interfered
with the direction of Go, but the point is that they could in the
future. Not having a community check on the Go core team means there is
no community check on the future Go core team, or higher up execs that
decide they want a finger in the pie. We don't know who will be in
charge of the Go team in 10 or 20 years, and they may be less principled
than the current team. We also don't know how Google will have changed,
or what kinds of pressures might be put on the Go team from a future over-
zealous Google executive who wants a hand in the proposal process pie.

—Sam

-- 
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/1358d19f-b7a6-46db-b970-35c0f7c640d7%40www.fastmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Any alternative to go-bindata that supports dynamic assets?

2019-05-26 Thread Sam Whited
On Sun, May 26, 2019, at 13:44, Mark Bauermeister wrote:
> Is there any alternative that would allow loading the files
> dynamically during development and baking them into the source upon
> release? Or am I better off just writing some custom logic that simply
> tries to load the file from the file system and, upon failing, reverts
> to the baked data?

In my own projects I use a fork of JDB's "statik" [1] that I called
"pkgzip" [2]. The main point of forking was to avoid import side
effects, but it can load things in "dev mode" which means that it
reloads them on every refresh from the filesystem, or in live mode where
it loads them from a virtual file system that is pre-compiled. It's not
exactly what you want right now, but it would require very little
tweaking to be useful for you.

I've quickly thrown the source up here [2] and published it as
"code.soquee.net/pkgzip" in case it's useful to you or anyone else here.
The repo will likely move once SourceHut supports separate
organizations, but the vanity import will remain the same.

—Sam

P.S. Note that this package was just thrown up and DNS may not have
 propagated everywhere yet. If you're getting TLS errors from
 Netlify or can't look up the domain at all, wait 24 hours or so for
 DNS to finish propagating and for the new certs to be deployed.

[1]: https://github.com/rakyll/statik
[2]: https://git.sr.ht/~samwhited/pkgzip

-- 
Sam Whited

-- 
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/233754d2-3069-4d00-8179-ac1f617fdb55%40www.fastmail.com.
For more options, visit https://groups.google.com/d/optout.


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

2019-05-23 Thread Sam Whited
On Thu, May 23, 2019, at 22:28, Anthony Martin wrote:
> How do you square this opinion with the fact that the Go team went out
> of their way to enable the use of third-party module proxies,
> something that is good for the community but would be of little
> practical use to Google?

I'm certainly glad they did this, but most people will never change the
default options (or won't even know to change the options since this
behavior is silent) and the main proxy and sum file service is owned by
Google.

—Sam

-- 
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/5f44b16e-d79a-446c-876c-9d4d222f595d%40www.fastmail.com.
For more options, visit https://groups.google.com/d/optout.


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

2019-05-23 Thread Sam Whited
I apologize for the rambling nature of this post; I somehow sent this
while working on a revision, I should really figure out what keyboard
shortcut I keep accidentally hitting to do that, especially when I
haven't toned down the language yet. Oh well, please pardon the lack
of polish.

—Sam

On Thu, May 23, 2019, at 19:22, Sam Whited wrote:
> Thank you for writing your reply Ian. Since it's a rather long post
> I don't want to go through it point by point, but suffice it to say
> that I agree with most of what you've written. However, I also
> agree that Go is Google's language, and that in its current form
> this is a problem. I'm going to talk about two related but distinct
> probles here:
>
> It's good to have strong central leadership, and I'm okay with that
> leadership being employed by Google. The problem is that the Go team
> doesn't always appear to be interested in listening to the rest of the
> community. We saw this when the modules proposal was created and
> rushed out without adequate community feedback; after the push back
> against that the Go team promised to do better, but they're still
> putting out proposals with little to no opportunity to make
> significant changes (eg. the package sum proposal which was put out,
> and then almost immediately merged, made into a release, and then made
> the default behavior).
>
> This is especially a problem when these proposals further tie Go to
> Google web services run by the Go team (though I'm veering off into a
> separate problem here). To me this feels like it's almost a type of
> vertical integration and it's an absolutely disgusting thing to do,
> and I don't use that word lightly. Not because I think the Go team is
> planning on doing anything bad with the information all Go users will
> now be sending to them, or because I think Google executives are
> putting down mandates and influencing Go, but because we don't know
> what future Go team members or Google execs will do. We don't know who
> will be running the Go project in 10 or 20 years, so the Go team now
> should be making sure they limit the potential for abuse, especially
> when they work for a company with a long history of anti- competitive
> behavior and abuse of its size and power.
>
> It's possible that my dissatisfaction with the proposal process is all
> merely confirmation bias due to my extreme negative reaction to Go
> communicating with Google-run web services that can't be used by large
> portions of the world due to U.S. export laws, but I hope the Go team
> will still take the feedback in the original link seriously and try to
> change the process.

-- 
Sam Whited

-- 
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/8e351aff-da3f-4db0-b9a0-7f54c1cf73c5%40www.fastmail.com.
For more options, visit https://groups.google.com/d/optout.


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

2019-05-23 Thread Sam Whited
Thank you for writing your reply Ian. Since it's a rather long post I
don't want to go through it point by point, but suffice it to say that I
agree with most of what you've written. However, I also agree that Go is
Google's language, and that in its current form this is a problem. I'm going to 
talk about two related but distinct probles here:

It's good to have strong central leadership, and I'm okay with that
leadership being employed by Google. The problem is that the Go team
doesn't always appear to be interested in listening to the rest of the
community. We saw this when the modules proposal was created and rushed
out without adequate community feedback; after the push back against
that the Go team promised to do better, but they're still putting out
proposals with little to no opportunity to make significant changes (eg.
the package sum proposal which was put out, and then almost immediately
merged, made into a release, and then made the default behavior).

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

It's possible that my dissatisfaction with the proposal process is all
merely confirmation bias due to my extreme negative reaction to Go
communicating with Google-run web services that can't be used by large
portions of the world due to U.S. export laws, but I hope the Go team
will still take the feedback in the original link seriously and try to
change the process.

-- 
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/3c68c1ce-53bd-4f17-be48-d8bd0f69%40www.fastmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-25 Thread Sam Whited
On Wed, Apr 24, 2019, at 14:08, Mark Volkmann wrote:
> Are there really developers that find this unreadable?
>
> color := temperature > 80 ? “red” : “green”

Yes.

What is "?"? If I've never seen that before I have no easy way to search
for that, and a random symbol me nothing about what it does. Go
specifically tries to stick to keywords because even if you've never
seen them before it's generally easier to figure out what they do (or to
search for them if you're not sure).

Not to mention that even if you do know what they do, that specific
statement isn't the problem. If you allow people to do that, they'll end
up trying to nest it 5 levels deep. Go tries not to give people the
tools to shoot themselves in the foot for some tiny perceived advantage.

—Sam

-- 
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: built-in alternative to bcrypt?

2019-04-22 Thread Sam Whited
On Mon, Apr 22, 2019, at 20:18, whitehexagon via golang-nuts wrote:
> Also good to know only what I'm using gets linked in, but then the
> size of 'hello world' is even more surprising.

That's because the runtime is being linked in. Go requires, among other
things, a garbage collector and goroutine scheduler. These things are
always linked in because you're always using them.

> The argon2 looks interesting, but it sounds like it could be very
> memory heavy. The code I'm porting is running on a PAAS/SAAS setup,
> and that might have cost implications exceeding the worth of my low
> value data. But I will also have a look then at the sha3 that was
> mentioned, now that I know the 'x' stuff is internally produced by the
> same team!

Being memory heavy is the point; you don't want a fast hash to protect
your users data or if the hashes ever get stolen it's much easier for an
attacker to brute force them. SHA3 is a great hash, but it is not
appropriate for password storage. Please don't put your users passwords
at risk just to lower your operating overhead.

> I get the impression from some of the info I'm going through, that
> since I'm running on hosted systems, which optionally also have
> encrypted file systems, that some of the brute force defense stuff
> might be less applicable?

This is not true. An encrypted filesystem only prevents your database
from being stolen by eg. someone coming into your datacenter and running
off with your hard disk. It is no substitute for storing passwords
correctly.

> ie unless the database is physically stolen from some nuclear bunker
> somewhere in the world, and decrypted, and my noddy system is deemed
> worth hacking, it's probably pretty safe already.

Please don't put your users passwords at risk because you think
something you've done is "good enough". Always follow password storage
best practices.

> So the main attack vector would be multiple login attempts, which I
> can detect fairly easily. for example, 5 failed logins and the account
> is locked...

That's one way, and you should be doing that. However, you are human and
will make mistakes so another attack vector is someone managing to dump
your database, or getting in some otherway and downloading it.

> I was also thinking in this case I could use a client side hash so
> that the backend system never see's a plain text password. I realise
> of course that the hash becomes the password, but at least the hosted
> environments would never see clear text before reaching my hosted hash
> stuff. ie clients that reuse 123456 for everything :)

This generally isn't necessary and probably doesn't add much since
you're not likely to have your passwords stolen out of memory. Just
follow industry standard best practices.

—Sam

-- 
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] built-in alternative to bcrypt?

2019-04-22 Thread Sam Whited
On Mon, Apr 22, 2019, at 10:14, whitehexagon via golang-nuts wrote:
> I am concerned about the Go binary size, since I'm already at 15MB! So
> I'm trying to limit external dependencies as much as possible.

Staying in the standard library won't help you here. You'll still
have to link in the code you use regardless of where it comes from
(the entire standard library isn't linked into your binary, just
whatever you use).

As someone else mentioned, argon2 is probably what you want [1]. It's
the current OWASP recommendation [2].

—Sam

[1]: https://godoc.org/golang.org/x/crypto/argon2
[2]: 
https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Password_Storage_Cheat_Sheet.md#leverage-an-adaptive-one-way-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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] OCSP revocation checking before completing TLS handshake

2019-04-11 Thread Sam Whited
On Thu, Apr 11, 2019, at 15:49, erikssonfili...@gmail.com wrote:
> Using Go's standard TLS library this does not seem possible, as
> tls.Dial does not seem to do any OCSP checking. Another possible
> workaround would be to fetch the server certificate without
> performing a handshake, then check revocation status, and if status
> is OK, redo the handshake using tls.Dial, but I couldn't find a way
> to do it in Go.

You can use golang.org/x/crypto/ocsp [1] and create your own
dialer which performs an OCSP request. You can also use this to
parse any stapled responses which are returned by crypto/tls's
OCSPResponse() method.

[1]: https://godoc.org/golang.org/x/crypto/ocsp

—Sam

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


[go-nuts] SourceHut Terraform Provider and HTTP API SDK

2019-03-24 Thread Sam Whited


Hi all,

I've been working on a Terraform provider for SourceHut [1] (previously
known as sr.ht) and, as part of this work, an HTTP API SDK in Go.
Both are available on SourceHut itself:

  - https://git.sr.ht/~samwhited/terraform-provider-sourcehut
  - https://git.sr.ht/~samwhited/sourcehut-go/

I'd love to get your feedback or contributions.
The SourceHut APIs are still very limited and new, and will likely
change, so be warned that things may break going forward until SourceHut
itself stabilizes.
Also note that the documentation may not render correctly on GDDO until
some pending changes [2] are merged.


—Sam


[1]: https://sourcehut.org/
[2]: https://golang.org/cl/168065

-- 
Sam Whited

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


Re: [go-nuts] Go command support for "make"

2019-03-19 Thread Sam Whited
On Wed, Mar 20, 2019, at 05:05, Lucio wrote:
> What I just realised is that my Makefile/mkfile-foo isn't sufficient
> to *do something* with such information, but at this point I'm willing
> to cross that bridge when I come to it. For now, having a "go status
> infernal/package", say, even if it provides a single reply:
> "updated=yes", for example (someone here will think of a better
> approach, no doubt) will be a useful start. Obviously, the command is
> run in a directory other than the one being verified.

Make files are meant to check if one file is newer than another, not the
output of a command. If you want to see if your dependencies have been
updated or not, check if the file that contains those dependencies has
been updated (eg. go.mod or Gopkg.toml). If you want to check if local
files have been updated, list those local files. Something like this is
a good start for a Go project (assuming you want to depend on all .go
files in the project, which may or may not be a good assumption
depending on the project).

GOFILES!=find . -name '*.go'

yourbinary:
go.mod $(GOFILES) go build -o $@

—Sam

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


Re: [go-nuts] Go packaging

2019-03-18 Thread Sam Whited
On Mon, Mar 18, 2019, at 06:24, Nada Saif wrote:
> I am learning to Go. For packages, do I need to use GitHub?
> I tried to build two packages one accessing functions from the other.

Welcome! You can use whatever repository hosting you want, and even use your 
own domain name with it!
I encourage using alternatives; the less we tie the Go ecosystem to GitHub the 
better.

For more information on repository lookup, custom domains, and special casing 
of some of the bigger repo hosting services see:

https://golang.org/cmd/go/#hdr-Remote_import_paths

—Sam

-- 
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: Unmarshal nested XML value from dynamic XML document

2019-02-24 Thread Sam Whited
Your function appears to return error text, but it will be much more clear 
what's going on when reading the code if you encode your intent in the return 
type and return an error instead of a string (which gives me no information 
about what that string is supposed to represent: is it an error? is it some 
XML?). fmt.Errorf can be used for this, also just return the io.EOF directly.

—Sam

On Sun, Feb 24, 2019, at 17:28, Steffen Wentzel wrote:
> Thanks for the response. I was hoping it would be possible with just 
> xml.Unmarshal.
> 
> I now have this implementation - any comments on that? (I'm okay with 
> returning the error inline, it's just for logging purposes):
> 
> Playground: https://play.golang.org/p/6J8XndWdlv_N
> 
> `
> func id2(axl []byte) string {
>  dec := xml.NewDecoder(bytes.NewReader(axl))
>  for {
>  tok, err := dec.Token()
>  if err != nil {
>  if err == io.EOF {
>  return "token not found"
>  }
>  return fmt.Sprintf("error decoding XML: %v", err)
> 
>  }
>  if tok, ok := tok.(xml.StartElement); ok {
>  if tok.Name.Local == "return" {
>  var id string
>  err := dec.DecodeElement(, )
>  if err != nil {
>  return fmt.Sprintf("error decoding return element: %v", err)
>  }
>  return id
>  }
>  }
>  }
> }
> `
> 
> 
> 
> Am Samstag, 23. Februar 2019 20:53:07 UTC+1 schrieb Tamás Gulácsi:Walk 
> over it usin xml.Decoder.Token, and UnmarshalElement when found a 
> StartToken with a proper Name.Local.
>  
> 
> 
>  -- 
>  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

-- 
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] inverse of time.Duration?

2019-02-15 Thread Sam Whited
On Fri, Feb 15, 2019, at 20:00, Burak Serdar wrote:
> rate=1.0/double(dur)

nit: s/double/float64/

—Sam

-- 
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] Alternative of defer?

2019-02-08 Thread Sam Whited
It's not pretty, but if you absolutely must write this code and can't refactor 
it, you can always use a closure to scope the defer:

lock1.Lock()
err = func() error {
  defer lock1.Unlock()
  return performOperation1()
}()
if err != nil {
  return err
}
performExpensiveOperation2()

On Fri, Feb 8, 2019, at 18:28, vincent163 wrote:
> I am thinking about how to write programs like this:
> `
> lock1.Lock()
> err = performOperation1()
> if err != nil {
>  lock1.Unlock()
>  return err
> }
> lock1.Unlock()
> performExpensiveOperation2()
> `
> 
> The lock1 must be locked while performing operation1, and I need to use 
> its result to perform operation2. Since operation2 is expensive, I 
> don't want to hold the lock while performing it, and lock1.Unlock() 
> needs to be called before calling operation2.
> Go's defer mechanism doesn't seem to handle this case well since the 
> resource is used only within a block and not throughout the function. 
> Is there a recommended way to write programs in this case?
> I know I could wrap the lock block in a closure, but that creates a 
> completely new scope, so I can't return directly or break out of a loop 
> within the closure, etc.
>  
> 
> 
>  -- 
>  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

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


Re: [go-nuts] go install touches the result file even if no changes

2019-01-28 Thread Sam Whited
On Mon, Jan 28, 2019, at 19:44, 'Tim Hockin' via golang-nuts wrote:
> People already chide me for my affinity for baroque
> Makefiles...

I use bmake too; and here I was all this time thinking that the "b" stood for 
"BSD".

—Sam

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


Re: [go-nuts] Go Module File

2019-01-27 Thread Sam Whited
On Sun, Jan 27, 2019, at 11:24, Kaveh Shahbazian wrote:
> Where can I find the complete reference for Go module files (go.mod)?
> 
> I am particularly interested in getting fluent in using local 
> packages/sub-packages and also redirecting import paths - for example 
> for times I need to use a fork.

I'm glad I'm not the only one who had a hard time finding this:

https://tip.golang.org/cmd/go/#hdr-The_go_mod_file

—Sam

-- 
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 Sam Whited
On Thu, Jan 24, 2019, at 07:00, 伊藤和也 wrote:
> Is it possible?
> package main
> 
> var Number int = 100
> func main() {}
> 
> package hello
> 
> import "fmt"
> 
> func abc() {
>fmt.Println(Number)
> }2019年1月24日木曜日 11時27分57秒 UTC+9 伊藤和也:
> > package main
> > 
> > var Number int = 100
> > 
> > func main() {
> > 
> > }

No, if you simply try this you'll see that you get an error:

import "main" is a program, not an importable package

—Sam

-- 
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 concatenate more type of formatting for the same variable (fmt.Printf)

2019-01-21 Thread Sam Whited
On Tue, Jan 22, 2019, at 03:26, Antonio Romeo Riga wrote:
> I would like to do something like that
> fmt.Printf("%-15v %5.2f %5.2f" , coin, piggyBank)
> 
> %-15v and %5.2f should change the variable 'coin'.

If you want the first two verbs to both affect "coin" in your example, use 
bracket notation:

fmt.Printf("%-15[1]v %5.2[1]f %5.2[2]f", coin, piggyBank)

To find this in the documentation (it's a long read and easy to skip over) 
search for "Explicit argument indexes".


I wasn't entirely sure what you were asking, so if this wasn't what you were 
trying to figure out I apologize.

—Sam

-- 
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 the type of a variable with interface{} "nil"?

2019-01-20 Thread Sam Whited
On Mon, Jan 21, 2019, at 00:39, 伊藤和也 wrote:
> I checked the type of the variable "v" with interface{} using TypeOf 
> function in reflect package but it returned "nil".
> var v interface{}
> fmt.Println(reflect.TypeOf(v))
> 

That is what the reflect.TypeOf function is supposed to do. The docs 
specifically mention this: https://godoc.org/reflect#TypeOf

—Sam

-- 
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: multiple binaries from a single directory with go modules?

2019-01-18 Thread Sam Whited
On Sat, Jan 19, 2019, at 01:12, Tyler Compton wrote:
> What alternative do you recommend?

Use what you're comfortable with. Make is a great tool, and doesn't appear to 
be the problem here.

—Sam

-- 
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] When to use interfaces?

2019-01-18 Thread Sam Whited
On Fri, Jan 18, 2019, at 18:06, 伊藤和也 wrote:
> When to use interfaces?

Reading this chapter in Effective Go might help. You can find answers to many 
of your questions there.

https://golang.org/doc/effective_go.html#interfaces_and_types

—Sam

-- 
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] Transferring host's go-mod-download cache into docker container

2019-01-12 Thread Sam Whited
On Fri, Jan 11, 2019, at 23:03, grego...@unity3d.com wrote:
> But now, I don't know how I can essentially copy the mod cache (or 
> whatever the right term is) like I'd have copied the vendor directory.

If you're suggesting that you already have the module cached on the machine 
that builds your containers, the cache lives at ~/go/pkg/mod by default so you 
could probably copy that tree into your build container.

—Sam

-- 
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: Secure password hashing algorithm in go.

2019-01-07 Thread Sam Whited
On Mon, Jan 7, 2019, at 07:58, minfo...@arcor.de wrote:
> I've often encountered demands for password encryption, where simple string 
> hashing would suffice.

You should never encrypt passwords; encryption implies that you can get the 
original password back out, it's a two way street.
Some form of hashing is always what you want (of course, you can't just hash 
and call it a day; there's still more work to do).

> Speed-wise FNV-1a is barely to beat. Add some magic number to the 
> result and you are good enough.
> The algo fits in a single handful of lines.

You also don't want speed when hashing passwords, this is why all the methods 
other people have been listing (I use Argon2 or PBKDF.2 depending on the 
application, personally) are actually a type of hash called a Key-derivation 
function (KDF).  FNV-1 is not a cryptographic hash function and is not suitable 
for password storage.

OWASP has a good overview of password storage if you're interested: 
https://www.owasp.org/index.php/Password_Storage_Cheat_Sheet

—Sam

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


Re: [go-nuts] go modules go build fails - normal go build with $GOPATH set works

2018-12-25 Thread Sam Whited
This sounds like the version is mismatched. Is the gopath version a newer 
commit (with api changes) than the tag being picked in the go.mod file? I have 
this quite frequently with golang.org/x/text which was last released some time 
ago and have to use a replace directive to get a more up to date version and 
fix the build

—Sam


On December 25, 2018 8:10:08 PM UTC, robr...@gmail.com wrote:
>I have been testing out the new go modules feature.  Our application 
>compiles/installs without problems using the normal $GOPATH way and
>have 
>been using this for a while now.   trying go modules produces the same 
>error over and over 
>
>Steps I followed
>
>unset $GOPATH just to be safe 
>
>1) git clone github project 
>
>2) go mod init 
>
>3) go build 
>
>
>and after some output where I can see it getting all the dependencies I
>
>keep getting 
>
>random.go:14:10: assignment mismatch: 2 variables but 1 values
>random.go:29:10: assignment mismatch: 2 variables but 1 values
>
>Again reverting back to the normal $GOPATH way everything compiles fine
>and 
>I can start the binary. 

-- 
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] tool to automatically refresh godoc ?

2018-12-21 Thread Sam Whited
On Fri, Dec 21, 2018, at 14:48, Beoran wrote:
> Not go specific, there are inotifywait and entr 
> http://eradman.com/entrproject/.

Or a post-push hook on the server where the repos live if you're using Git.

—Sam

-- 
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] Language line in go.mod

2018-12-18 Thread Sam Whited
On Tue, Dec 18, 2018, at 10:13, Ian Lance Taylor wrote:
> https://tip.golang.org/cmd/go/#hdr-The_go_mod_file

Ah thanks! I wouldn't have ever thought to look there for info on the mod file. 
I'll pass that along.

—Sam

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


[go-nuts] Language line in go.mod

2018-12-18 Thread Sam Whited
Hi all,

I've been asked multiple times recently to point people to documentation for 
the language line in a go.mod file (eg. the `go 1.12' line that's added by 
recent builds), but I haven't been able to find any on the wiki or in `go help 
modules` or similar, just the occasional list discussion.

Is this documented anywhere and I'm just missing it?

Thanks,
Sam

-- 
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: json and interface unmarshalling

2018-12-14 Thread Sam Whited
Hi,

In the future, please don't apply formatting when you're emailing code. Lots of 
people will have lots of different mail clients, and it's not always obvious 
how the colors will interact or whether they'll be readable against different 
backgrounds, or by people with various visual disabilities.

Plain text emails are your friend; everyone's individual client (including 
yours when you're composing it, probably) can style those in such a way that 
they'll be able to read it.

Thanks,
Sam

On Fri, Dec 14, 2018, at 13:24, Darko Luketic wrote:
> Of course after I ask my question I find the answer on my own.
> It's always like this.
> 
> The solution is to change
> 
> type MessageRequest struct {
>Typestring  `json:"type"`
>Payload json.RawMessage `json:"payload"`
> }
> 
> 
> So the payload isn't unmarshalled.
> 
> Now, after the MessageRequest is unmarshalled I can check for the type and 
> then
> 
> payload := new(model.ChatMessage)
> if e := json.Unmarshal(m.Payload, payload); e != nil {
>logrus.Error(e)
>return
> }
> 
> 
> 
> On Friday, December 14, 2018 at 8:17:25 PM UTC+1, Darko Luketic wrote:
> >
> > Hello,
> >
> > I'm sending messages over websocket.
> > I have a "generic" MessageRequest and MessageResponse struct.
> >
> > type MessageRequest struct {
> >Typestring  `json:"type"`
> >Payload interface{} `json:"payload"`
> > }
> >
> > type MessageResponse struct {
> >Typestring  `json:"type"`
> >Payload interface{} `json:"payload"`
> > }
> >
> >
> >
> > I'm trying to unmarshall this.
> >
> > m := new(MessageRequest)
> > if e := json.Unmarshal(msg, m); e != nil {
> >logrus.Error(e)
> >return
> > }
> >
> >
> > Then I switch by MessageRequest.Type to know what kind of message was sent 
> > by the client.
> >
> > However, when I do something like
> > payload, ok := m.Payload.(*MessageRequest)
> > if !ok {
> > //error
> > }
> >
> > It isn't compatible to type *MessageRequest
> > As a workaround I could imagine marshalling the interface again, then 
> > unmarshalling into the correct message payload type (e.g. ChatMessage)
> > But that is unnecessary overhead. However it beats marshalling into 
> > map[string]interface and manually assigning values in terms of code 
> > readability.
> >
> > tmp, e := json.Marshal(m.Payload)
> > if e != nil {
> >logrus.Error(e)
> >return
> > }
> > payload := new(model.ChatMessage)
> > if e := json.Unmarshal(tmp, payload); e != nil {
> >logrus.Error(e)
> >return
> > }
> >
> >
> >
> > vs
> >
> > pmap, ok := m.Payload.(map[string]interface{})
> > if !ok {
> >logrus.Error("can not convert to map[string]interface{}")
> >return
> > }
> > payload := new(model.ChatMessage)
> > user := pmap["user"].(string)
> > payload.User = user
> >
> > message := pmap["message"].(string)
> > payload.Message = message
> >
> > tme := pmap["time"].(string)
> > tmee, e := time.Parse(time.RFC3339, tme)
> > if e != nil {
> >logrus.Error("time parse error")
> >return
> > }
> > payload.Time = tmee
> >
> >
> > Is there a better solution to solve 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.


-- 
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.


Re: [go-nuts] Getting .slide of Golang Talks

2018-12-03 Thread Sam Whited
On Mon, Dec 3, 2018, at 10:28, Andrew Frances wrote:
> Is it possible to get the .slide files for the
> Golang Talks https://talks.golang.org/ so I can have more examples (I don't
> really need all the accompanying files)?

https://github.com/golang/talks

-- 
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] [Go2] move everything to gopath so goroot isn't required anymore

2018-12-02 Thread Sam Whited
There has been some discussion of making packages in the standard library into 
modules (once that's the default versioning system) which could be versioned 
separately from Go so that fixes could be released without having to wait on 
the full Go release cycle. I can't find a link at the moment, but the Go team 
has mentioned the possibility of doing this.

—Sam

On Sun, Dec 2, 2018, at 21:04, Gert wrote:
> Can we move stdlib (goroot) to gopath in Go2? On install you can do go get 
> -u stdlib to download the stdlib into gopath. Basically getting rid of 
> goroot.

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


[go-nuts] Syntax highlighting (again) [WAS go language sensitive editor?]

2018-11-24 Thread Sam Whited
On Fri, Nov 23, 2018, at 17:06, Jay Ts wrote:
> Nowadays I use vim 
> because there are a few nice things about it that aren't in vi. At least, 
> vim is ok after you turn off syntax highlighting and all the other newbie 
> crutches. :-P Seriously, how many people can't read or write in English (or 
> their native language) if the verbs, nouns, and prepositions are the same 
> color? I don't get it.

Okay, I'll bite: Anyone can still read code without syntax highlighting, it 
doesn't provide any information that's not already there. It just provides 
another dimension of visibility to that information so that you can make 
certain judgements quicker. If the compiler gives you a worthless error message 
and you don't know why something isn't working, you might be able to see at a 
glance that a multi-line string isn't terminated when everything is in string 
color instead of scrolling up several hundred lines wondering why it said the 
file ended early. It's not a crutch, as it probably doesn't help you if you 
can't walk already.

—Sam

-- 
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] Simple Go http daemon under systemd

2018-11-23 Thread Sam Whited
On Thu, Nov 22, 2018, at 21:14, Tong Sun wrote:
> and it needs to be working under systemd. 
> …
> but there is no mentioning of how it can work under systemd, which could 
> be 
> troublesome, 
> like the question I found at why systemd cannot start golang web app 
> 

I'm not really sure what you're asking, Go binaries aren't doing anything 
special and systemd can start them just like any other program. Are you looking 
for an example service/socket file that lets you bind to port 443, or wondering 
what type of service to use? Or are you getting some other kind of error?

—Sam

-- 
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 Sam Whited
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.


Re: [go-nuts] what does the "replace" in go.mod mean?

2018-11-10 Thread Sam Whited
On Sat, Nov 10, 2018, at 10:39, Paul Jolly wrote:
> I don't think there's anything wrong with this distinction - when you
> say "unless this has been fixed", are you suggesting the behaviour is
> wrong or could be improved in some respect?

I've just seen several projects do this wrong because they don't know about go 
mod tidy so they build, let CI run tests (and don't notice that the file has 
changed in CI), and call it a day never knowing that they're missing 
dependencies. Since I can't imagine why you'd want to have partial dependencies 
in the go.mod file (and even if you do, it's probably not nearly as common as 
wanting all of them), the default behavior of go build seems wrong to me.

—Sam

-- 
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 does the "replace" in go.mod mean?

2018-11-10 Thread Sam Whited
On Sat, Nov 10, 2018, at 09:46, Paul Jolly wrote:
> > 2. "Why doesn't "go build" run "go mod tidy" automatically?
> 
> It does in as much as adding missing dependencies are concerned, but
> doesn't do the tidying (removal) in go.{mod,sum} that go mod tidy
> does.

I don't think this is true (unless this has been fixed, I can't upgrade to 
check right this moment), go build respects build constraints (eg. you won't 
get dependencies that only exist in tests), so even if you're just talking 
about adding missing dependencies, build won't necessarily help you.

I've noticed this causing a lot of confusion in libraries moving to modules 
where dependencies get left out because they're hidden behind a build tag, or 
only get added when tests are run.

—Sam

-- 
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: integration tests and using atom

2018-11-08 Thread Sam Whited
On Thu, Nov 8, 2018, at 13:49, S Ahmed wrote:
> Is there a way to ignore certain tests like my integration tests that setup
> db etc. and are long running?

I like to add a build tag to my integration tests, something like:

// +build integration

Then when I want to run them:

go test -tags "integration"

Sometimes I also use T.Short() and `go test -short' with this if some tests 
take a lot longer to run and should only happen in CI or only run before a 
release build, etc. but I don't like to use it to separate integration tests 
from unit tests since I might have short/long tests in both categories.

—Sam

-- 
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] database for protobuf - profanedb or similar

2018-10-30 Thread Sam Whited
On Tue, Oct 30, 2018, at 13:48, Tharaneedharan Vilwanathan wrote:
> I am looking for a database for protobuf, preferably the one that fits Go
> environment better. I located profanedb. I am wondering if anyone tried it
> with Go and if there is any example code that I can take a look at. Also,
> please let me know if there is anything else I should try too.

I'm not sure what you mean by "fits the Go environment", but PostgreSQL is very 
reliable and could easily hold protobufs in the BYTEA type, or of course the 
JSON representation in the JSONB type. The lib/pq [1] driver is very good.

I tend to think that choosing a niche database for a specific serialization 
format is a bad idea; instead think about your application and what you care 
about (speed, reliability, etc.), and about the general type of data you'll be 
storing (is it time series, highly relational, etc.) then pick something that's 
well tested and proven which meets your criteria.

—Sam

[1]: https://godoc.org/github.com/lib/pq

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


Re: [go-nuts] go src organization question

2018-10-21 Thread Sam Whited
On Sun, Oct 21, 2018, at 11:31, Sankar wrote:
> For such a hybrid requirement, what is the most recommended way to import 
> and structure our libraries and the source directories, to work with go 
> modules?

A single module at the root of the project should give you what you want. 
Create the file: ~/go/src/gitlab.com/example/go.mod
and then add the line: 

module gitlab.com/example

and build. Everything should work and the local copy of your libraries will be 
used because they are in the same module.

—Sam

-- 
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] Having trouble installing golint

2018-10-17 Thread Sam Whited
TL;DR — you don't need to run the second command, just the first one.

I'm sorry for being unclear. Go get looks up packages by their import path. The 
import path of golint is "golang.org/x/lint/golint", so the second command you 
ran with the github URL will never work since that is the repo, not the package 
path. When you run go get golang.org/x/lint/golint it will look up the repo, 
discover that it lives at GitHub, clone it, and build it.

If you don't specify another package import path and you host your source on 
GitHub the github.com url is the default one, which may be why you are 
confused. However, golint specifies a custom import path 
(golang.org/x/lint/golint) so you need to use that.

—Sam

On Wed, Oct 17, 2018, at 14:48, 'kalekold' via golang-nuts wrote:
> I've already tried that and the original command still fails.
> 
> $ go get -u -v golang.org/x/lint/golint
> Fetching https://golang.org/x/lint/golint?go-get=1
> Parsing meta tags from https://golang.org/x/lint/golint?go-get=1 (status 
> code 200)
> get "golang.org/x/lint/golint": found meta tag get.metaImport{Prefix:
> "golang.org/x/lint", VCS:"git", 
> RepoRoot:"https://go.googlesource.com/lint"} 
> at https://golang.org/x/lint/golint?go-get=1
> get "golang.org/x/lint/golint": verifying non-authoritative meta tag
> Fetching https://golang.org/x/lint?go-get=1
> Parsing meta tags from https://golang.org/x/lint?go-get=1 (status code 
> 200)
> golang.org/x/lint (download)
> Fetching https://golang.org/x/lint?go-get=1
> Parsing meta tags from https://golang.org/x/lint?go-get=1 (status code 
> 200)
> get "golang.org/x/lint": found meta tag get.metaImport{Prefix:
> "golang.org/x/lint", VCS:"git", 
> RepoRoot:"https://go.googlesource.com/lint"} 
> at https://golang.org/x/lint?go-get=1
> Fetching https://golang.org/x/tools/go/ast/astutil?go-get=1
> Parsing meta tags from 
> https://golang.org/x/tools/go/ast/astutil?go-get=1 
> (status code 200)
> get "golang.org/x/tools/go/ast/astutil": found meta tag get.metaImport{
> Prefix:"golang.org/x/tools", VCS:"git", RepoRoot:
> "https://go.googlesource.com/tools"} at https:
> //golang.org/x/tools/go/ast/astutil?go-get=1
> get "golang.org/x/tools/go/ast/astutil": verifying non-authoritative 
> meta 
> tag
> Fetching https://golang.org/x/tools?go-get=1
> Parsing meta tags from https://golang.org/x/tools?go-get=1 (status code 
> 200)
> golang.org/x/tools (download)
> Fetching https://golang.org/x/tools/go/gcexportdata?go-get=1
> Parsing meta tags from 
> https://golang.org/x/tools/go/gcexportdata?go-get=1 
> (status code 200)
> get "golang.org/x/tools/go/gcexportdata": found meta tag get.metaImport{
> Prefix:"golang.org/x/tools", VCS:"git", RepoRoot:
> "https://go.googlesource.com/tools"} at https:
> //golang.org/x/tools/go/gcexportdata?go-get=1
> get "golang.org/x/tools/go/gcexportdata": verifying non-authoritative 
> meta 
> tag
> Fetching https://golang.org/x/tools/go/internal/gcimporter?go-get=1
> Parsing meta tags from 
> https://golang.org/x/tools/go/internal/gcimporter?go-get=1 
> (status code 200)
> get "golang.org/x/tools/go/internal/gcimporter": found meta tag get.
> metaImport{Prefix:"golang.org/x/tools", VCS:"git", RepoRoot:
> "https://go.googlesource.com/tools"} at https:
> //golang.org/x/tools/go/internal/gcimporter?go-get=1
> get "golang.org/x/tools/go/internal/gcimporter": verifying non-
> authoritative 
> meta tag
> 
> $ go get -u -v github.com/golang/lint/golint
> github.com/golang/lint (download)
> package github.com/golang/lint/golint: code in directory /media/Data/
> Projects/Go/src/github.com/golang/lint/golint expects import 
> "golang.org/x/lint/golint"
> 
> 
> On Wednesday, 17 October 2018 17:53:50 UTC+1, Sam Whited wrote:
> >
> > As the error says, you need to use golang.org/x/lint/golint: 
> >
> > go get -u -v golang.org/x/lint/golint 
> >
> > —Sam 
> >
> > On Wed, Oct 17, 2018, at 10:12, gary.wi...@victoriaplumb.com  
> > wrote: 
> > > I'm having trouble installing golint. Any idea what the problem could 
> > be? 
> > > 
> > > $ go get -u -v github.com/golang/lint/golint 
> > > github.com/golang/lint (download) 
> > > package github.com/golang/lint/golint: code in directory 
> > /home/gary/Code/go/ 
> > > src/github.com/golang/lint/golint expects import "
> > golang.org/x/lint/golint" 
> > > 
> > > -- 
> > > You received this message because you are sub

Re: [go-nuts] Having trouble installing golint

2018-10-17 Thread Sam Whited
As the error says, you need to use golang.org/x/lint/golint:

go get -u -v golang.org/x/lint/golint

—Sam

On Wed, Oct 17, 2018, at 10:12, gary.willoug...@victoriaplumb.com wrote:
> I'm having trouble installing golint. Any idea what the problem could be?
> 
> $ go get -u -v github.com/golang/lint/golint
> github.com/golang/lint (download)
> package github.com/golang/lint/golint: code in directory /home/gary/Code/go/
> src/github.com/golang/lint/golint expects import "golang.org/x/lint/golint"
> 
> -- 
> 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.


Re: [go-nuts] Temporary files in go

2018-10-11 Thread Sam Whited
On Thu, Oct 11, 2018, at 18:48, Greg Saylor wrote:
> 1. Create a temporary file and squirrel away the file handle
> 2. Unlink the temporary file by name
> 3. Various functions would write stuff to the file
> 4. If the programs completes to some successful state, create a hardlink to 
> the file handle with the final filename

The golang.org/x/sys/unix [1] package gives you a lower level interface that 
might be familiar to you if you're used to using C. Something like this is 
probably similar to what you were doing (though you'll need /proc mounted, I'm 
not sure if there's a better way to do that):

oldfd, err := unix.Open(".", unix.O_TMPFILE|unix.O_RDWR, 
unix.S_IRUSR|unix.S_IWUSR)
if err != nil {
panic(err)
}

f := os.NewFile(uintptr(oldfd), "myoldfile")
_, err = f.Write([]byte("Hello, World"))
if err != nil {
panic(err)
}

dir, err := os.Open(".")
if err != nil {
panic(err)
}
procdir, err := os.Open("/proc/self/fd/")
if err != nil {
panic(err)
}

err = unix.Linkat(int(procdir.Fd()), strconv.Itoa(oldfd), 
int(dir.Fd()), "mynewfile", unix.AT_SYMLINK_FOLLOW)
if err != nil {
panic(err)
}

—Sam

[1]: https://godoc.org/golang.org/x/sys/unix

-- 
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: Compatibility between golang.org/x/crypto/argon2 and the legacy one

2018-10-11 Thread Sam Whited
On Thu, Oct 11, 2018, at 14:14, Thomas Bruyelle wrote:
> That say, the downside is I have to keep both hash system, until all users
> connect, which can take a long time, or can never happen!

Or at least until enough users have updated that you don't mind forcing the 
rest to update their password if they ever log in again.

—Sam

-- 
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: Compatibility between golang.org/x/crypto/argon2 and the legacy one

2018-10-11 Thread Sam Whited
On Thu, Oct 11, 2018, at 13:56, Thomas Bruyelle wrote:
> Unfortunately, because of that version mismatch, all my users' hashes were 
> created with a version not supported by golang.org/x/crypto/argon2, so I 
> can't migrate :/

I hope no problems are ever discovered in Argon2 then, it's generally a good 
idea to have some sort of system for migrating hashes :)

For example, when the user next logs in you could verify that he hash is 
correct, but also calculate the new hash and update it and set a prefix or a 
bit in the database somewhere saying that they're on "hash mechanism v2". 
There's no need to force reset every password all at once since this isn't a 
security issue.

—Sam

-- 
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] Compatibility between golang.org/x/crypto/argon2 and the legacy one

2018-10-11 Thread Sam Whited
On Thu, Oct 11, 2018, at 11:37, Thomas Bruyelle wrote: 
> I want to update my authentication code by using 
> golang.org/x/crypto/argon2, as a replacement of 
> github.com/tvdburgt/go-argon2 which uses the legacy C lib under the hood 
> through CGO.
> The main benefit is of course to drop the usage of CGO.
> 
> But I encounter a serious issue, with the same inputs (password, salt, 
> times, threads, memory), the 2 libraries give me 2 different hashes. 
> That means it's impossible for me to migrate, or else I have to ask all my 
> users to regenerate their passwords, which is not acceptable for me.

The x/crypto/argon2 package implements version 13, if you add "Version:  
Version13," to your context they should be the same. The docs claim this is the 
default for the legacy version, but they appear to be wrong.

—Sam

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


[go-nuts] Getting Go module versions from Git Log

2018-09-24 Thread Sam Whited
Hi all,

Here's a quick Git config for getting go module meta-versions from Git Log 
output, hopefully its useful to someone else who was getting frustrated by 
trying to make up v0.0.0 versions:

https://blog.samwhited.com/2018/09/go-module-versions-from-git-log/

—Sam

-- 
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 it possible to build a module without a hosted repository?

2018-09-14 Thread Sam Whited
On Fri, Sep 14, 2018, at 20:32, K Davidson wrote:
> Is there a way that I can build my package as a module without having to 
> host it on the internet?

I've found myself just making up fake import statements. While you're 
prototyping it doesn't hurt:

package main // import "golang.org/totally-official-and-real"

—Sam

-- 
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] Golang equivalent of Python's context manager

2018-09-12 Thread Sam Whited
On Wed, Sep 12, 2018, at 14:12, Mirko Friedenhagen wrote:
> However, coming from Java lately, retrieving a DB-connection from a pool, 
> opening a transaction and committing/aborting and returningafterwards seems 
> something which could be handled with such a construct. How would you do 
> this in Golang?

I frequently do something similar to this:

https://gist.github.com/SamWhited/d81d081aed0351a1c1d128acf3a16b5c

(there may be some extra parameters, I cut out some row-level-security stuff 
from something being used in prod and pasted everything into the gist without 
really checking it)

—Sam

-- 
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 it needed to close a HTTP request body ?

2018-09-10 Thread Sam Whited



On Mon, Sep 10, 2018, at 09:27, Pierre Durand wrote:
> When I learned Go a few years ago, I was told to always defer/close the 
> HTTP request body, otherwise it will cause a resource leak.
> 
> But today I read this: https://golang.org/pkg/net/http/#Request.Body
> // The Server will close the request body. The ServeHTTP
> // Handler does not need to.
> 
> Am I misunderstanding something ?

The rule is that HTTP *clients* must close the *response* body. Servers handle 
closing the request body themselves.

—Sam

-- 
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] Operator Overloading Implies Generics?

2018-09-09 Thread Sam Whited



On September 9, 2018 1:43:09 PM UTC, robert engels  
wrote:
>I think the lack of method overload is a poor choice.
>
> …
>
>I would much rather write
>
>NewCircle([]Point)
>NewCircle(center Point,radius int)
>
>than
>
>NewCircleFromPoints
>NewCircleFromCenterWithRadius
>
>and this is just a very simple example.


Allowing this would also open us up to a lot of Java-like ambiguity:


func Foo(i int) {…}
func Foo(i ...int) {…}

Foo(1) // Which function signature does this match?

—Sam

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


Re: [go-nuts] Go 2 Draft Design Question : Error Handling

2018-09-08 Thread Sam Whited



On Sat, Sep 8, 2018, at 12:41, Henry wrote:
> I have read the Go 2 Draft Design about Error Handling. You can read about 
> it here Go 2 Draft Designs 
> . The 
> draft suggested something like this:
> 
> func CopyFile(src, dst string) throws error {
> r := os.Open(src)
> defer r.Close()
> 
> w := os.Create(dst)
> io.Copy(w, r)
> w.Close()
> }

You may need to go back and read that page again; this example is from the 
problem statement of the overview document. The actual draft design does not 
include any such syntax.

The document you want to read can be found here: 
https://go.googlesource.com/proposal/+/master/design/go2draft-error-handling.md

—Sam

-- 
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: Can't print GO2 draft documents with firefox 61.0.1 (64 bits) Ubuntu

2018-09-06 Thread Sam Whited
On Wed, Sep 5, 2018, at 20:28, peterGo wrote:
> What happenned when you followed the instructions I gave to Christophe?

I believe this is exactly what I was doing before; I don't love having to use 
the simplify option though, so it's possible I left it off and didn't notice. 
I'll try again at some point and follow up if something was off.


—Sam

-- 
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: Can't print GO2 draft documents with firefox 61.0.1 (64 bits) Ubuntu

2018-09-05 Thread Sam Whited
On Wed, Sep 5, 2018, at 15:04, peterGo wrote:
> Print the draft documents from Firefox Quantum 61.0.1 (64-bit) for Mozilla 
> Firefox for Ubuntu canonical - 1.0. 

I'm using Firefox 63.0a1 nightly cut 2018-08-19 and am also getting only one 
page; I had to download a new browser to print.

—Sam

-- 
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] help seek: creating and using go package

2018-09-04 Thread Sam Whited
On Tue, Sep 4, 2018, at 01:33, Sayan Shankhari wrote:
> Probably I am making some nonsense post here and disturbing you but as a 
> beginner, I want to know how in Go I can implement the following. If I can 
> not, please suggest me suitable solution:

Not at all; welcome! If you're just getting started with Go, I recommend that 
you take the tour (https://tour.golang.org). This probably covers most of what 
you want.


> 1. Create a package "myNum"

This is a good resource for getting started with creating Go packages: 
https://golang.org/doc/code.html

It's a tiny bit out of date, there are some experimental features in Go 1.11 
that make using GOPATH obsolete, but it will still work for now.

> 2. containing data type like:
> type Num struct {
> n, d int // numerator, denominator
> }
> 3. and a function to print like
> func printMyNum(x Num) {
> fmt.Println("the fractional number is: %d/%d", x.n, x.d)
> }

Looks like you've already done this, good job :)



In Go, the case of the first letter of an identifier determines if it's 
exported or not.
In your code "Num" will be exported (it can be used from another package), but 
its fields are not (so you won't be able to set "n" or "d" from another 
package). Similarly, "printMyNum" will not be exported, so you won't be able to 
call it from another package.

Here is a more detailed explanation: 
https://stackoverflow.com/questions/38616687/which-way-to-name-a-function-in-go-camelcase-or-semi-camelcase/38617771#38617771

And here is a nice post about how to name things: 
https://blog.golang.org/package-names


I hope that's helpful. Welcome to Go!

—Sam

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


Re: [go-nuts] go module for library developer workflow

2018-09-04 Thread Sam Whited
On Tue, Sep 4, 2018, at 09:58, Yulrizka wrote:
> What is the recommended workflow to easily develop new functionality for 
> lib 'a'?

Add a replace directive to your go.mod file in 'b' while you are developing:

replace github.com/my/a => /home/me/Projects/wherever/a

Unfortunately, you'll have to be careful not to accidentally commit this line.

—Sam

-- 
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.


Re: [go-nuts] Panic getting swallowed by defer in Go 1.11

2018-09-03 Thread Sam Whited
On Mon, Sep 3, 2018, at 04:10, ama...@naucera.net wrote:
> type S []int
> 
> func (s *S) Last() int {
> return (*s)[len(*s) - 1]
> }

On an unrelated matter, the extra indirection is (probably) not what you want 
here, slices are already a pointer type. For more information see 
https://blog.golang.org/go-slices-usage-and-internals.

That is to say, the following works in more or less the same way (and is much 
easier to read):

func (s S) Last() int {
return s[len(s)-1]
}

Apologies if this is something you're already aware of; for future generations 
finding this thread I wanted to mention it.

—Sam

-- 
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 deal with binaries compilation with go modules enabled?

2018-08-30 Thread Sam Whited
FWIW, I have the same issue (I have to unset GO111MODULE before attempting to 
fetch a binary or before building Go) and there appear to be several comments 
on the closed issue suggesting that this is still a problem:

https://golang.org/issues/26639

I just tested this on tip (currently devel +360771e422) but haven't dug in 
further.

—Sam

On Thu, Aug 30, 2018, at 13:29, Denis Cheremisov wrote:
> strange, still the same
> 
> $ go get -x -u golang.org/x/tools/cmd/goimports 
> go: cannot find main module; see 'go help modules'
> 
> I am using 
> 
> $ go version
> go version go1.11 linux/amd64
> 
> with
> 
> export GO111MODULE=on
> 
> 
> 
> четверг, 30 августа 2018 г., 18:21:45 UTC+3 пользователь Ian Davis написал:
> >
> >
> > On Thu, 30 Aug 2018, at 3:37 PM, Denis Cheremisov wrote:
> >
> > Hi!
> > With Go 1.10 and earlier one can install binaries via regular `go get`, `go 
> > get golang.org/x/tools/cmd/goimports` for instance.
> > It doesn't work with Go modules enabled:
> >
> > $ go get golang.org/x/tools/cmd/goimports
> > go: cannot find main module; see 'go help modules'
> >
> > this is an obvious usability downgrade. I wonder if someone knows about 
> > some sort of replacement for the functionality?
> >
> >
> > It should still work (and does for me).
> >
> > Can you try go get -x -u golang.org/x/tools/cmd/goimports and see what 
> > the output prints about the problem.
> >
> >
> >
> 
> -- 
> 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.


Re: [go-nuts] Is this a go fmt bug? map[string]int{...}

2018-08-09 Thread Sam Whited
I can't reproduce this behavior. What version of Go are you running?

On Thu, Aug 9, 2018, at 14:27, russo...@gmail.com wrote:
> With the following code, running go fmt shows different behavior depending 
> on the (1) length of the keys, and (2) the order of the keys.
> 
> var m_19_chars = map[string]int{
>  "i":   0,
>  "iii": 0,
>  "iii": 0,
> }
> var m_18_chars = map[string]int{
>  "i":  0,
>  "iii":0,
>  "ii": 0,
> }
> var m_19_chars_reorder = map[string]int{
>  "i": 0,
>  "iii": 0,
>  "iii": 0,
> }
> 
> 
> In the 1st map, the unexpected behavior is that the first two values are 
> indented a different amount than the third.
> 
> In the 2nd map, the large key is reduced to 18 chars long.  All keys are 
> indented evenly, as expected.
> 
> In the 3rd map, the large key is now 19 chars long again, but is listed 
> second.  Now all 3 values are indented differently.
> 
> -- 
> 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.


  1   2   >