[go-nuts] I want to add comment crypto/sha1

2017-11-08 Thread Dave Cheney
You cannot add an example to an unexported type, because that type cannot be constructed from outside your package. If you export the type then the name of the function would be ExampleDigest_Write https://blog.golang.org/examples -- You received this message because you are subscribed to th

Re: [go-nuts] Writing your own Context, making sure it's compatible with context.Context

2017-11-08 Thread Bruno Albuquerque
FYI, I just started writing a drop in replacement for Context that supports waiting on child contexts. I literally just submitted de initial code and did not test anything seriously yet, but this can help you find your with some ideas of how to proceed: http://github.com/brunoga/context On Wed, N

[go-nuts] Problem designing APIs after the compress stdlib

2017-11-08 Thread Glen Huang
I'm writing a small image processing tool, given an image content, it only does two things: 1. compressing the image content 2. generating a thumbnail (by resizing and then compressing it) I want to model the compressing(the same goes for resizing) after the compress stdlib: you create a compre

[go-nuts] I want to add comment crypto/sha1

2017-11-08 Thread al14031
I think this function name does not conform to the contract of golang ``` crypto/sha1/example_test.go func ExampleNew_file() { f, err := os.Open("file.txt") if err != nil { log.Fatal(err) } defer f.Close() h := sha1.New() if _, err := io.Copy(h, f); err != nil { log.Fatal(err) } fmt.Printf("% x

Re: [go-nuts] Writing your own Context, making sure it's compatible with context.Context

2017-11-08 Thread Ian Lance Taylor
On Wed, Nov 8, 2017 at 4:18 PM, Albert Tedja wrote: > > I am writing a library that could use the benefit of context, but I also > want to add additional functionalities to the context my library using, > while keeping the same golang idiom of using With*() to create a new context > based off its

[go-nuts] [ANN] Prometheus 2.0 Released

2017-11-08 Thread Brandon Philips
Hello Everyone- ICYMI Prometheus, a fellow CNCF project for container monitoring, has released their v2.0 today. You can learn more from the release from these links: 1. CoreOS post with in-depth benchmarks 2. Project blog

[go-nuts] gomobile + go protobuf

2017-11-08 Thread jay . graves
I've been trying to use Protobufs as a data transport between go code and native iOS and Android code. This has worked great on iOS as I can use this to output go and objc code to work with the objects. protoc --go_out=. --objc_out=. *.proto However, when I try to run gomobile bind -target=and

[go-nuts] Pruning unused methods

2017-11-08 Thread Jim Minter
Hi, I understand that if a codebase uses reflect.Value.Call() (among other things) then link-time optimisation to prune unused methods is disabled. As codebases expand and include third party libraries, it becomes harder to prevent a reflect.Value.Call() or equivalent from slipping in somewh

[go-nuts] Writing your own Context, making sure it's compatible with context.Context

2017-11-08 Thread Albert Tedja
I am writing a library that could use the benefit of context, but I also want to add additional functionalities to the context my library using, while keeping the same golang idiom of using With*() to create a new context based off its parent. At first, it seems that all I need to do is to sati

[go-nuts] Re: Is there a way or lib to read a binary into a sturct{len int32;data [len]int32}

2017-11-08 Thread as
I made a code generator for this, but I consider it an unmaintained experiment at best. http://github.com/as/wire9 It can read a comment in the form //wire9 bstr n[4] data[n] and generate the type along with a binary codec for it type On Sunday, October 29, 2017 at 11:40:36 PM UTC-7, hui zhang

Re: [go-nuts] Upcasting/Downcasting in Go

2017-11-08 Thread Ian Lance Taylor
On Wed, Nov 8, 2017 at 1:39 PM, Haiyu Zhen wrote: > > As someone who is new to Golang world, I am confused with the following > code. > > As sample code shown, type S's "underlying" type is slice (in C++ jargon S > is the derived class of slice), and if I pass a slice as S in function > parameter,

[go-nuts] Golang performance benchmarks on arm64 (Qualcomm Centriq 2400)

2017-11-08 Thread Ed Vielmetti
Vlad Krasnov from Cloudflare has an excellent blog post up about performance on Qualcomm's new Centriq 2400. In it he discusses several deficiencies in Go's arm64 support that show up in performance numbers that are both less than anticipated and easily improved. https://blog.cloudflare.com/arm-t

[go-nuts] Upcasting/Downcasting in Go

2017-11-08 Thread Haiyu Zhen
As someone who is new to Golang world, I am confused with the following code. As sample code shown, type S's "underlying" type is slice (in C++ jargon S is the derived class of slice), and if I pass a slice as S in function parameter, it works; but if I pass slice as S in function receiver, Go

[go-nuts] Re: %T question

2017-11-08 Thread jake6502
Constants in Go do not automatically have a type. From the language specification Constants section: An untyped constant has a *default type* which is the type to which the constant is implicitly converted in contexts where a typed value is required, for

[go-nuts] Re: Update Mongodb fields with omitempty flag in Golang structure

2017-11-08 Thread Diego Medina
replied on the mgo list https://groups.google.com/d/topic/mgo-users/F3LbWdyPGDc/discussion (pasted here to save a click) Hi, > the checkbox is unchecked and form is submitted to save. Now as I have applied "omitempty" if the checkbox is unchecked, your client side code should send "false" t

Re: [go-nuts] Calling Go from C++

2017-11-08 Thread Ian Lance Taylor
On Wed, Nov 8, 2017 at 9:41 AM, jhallock via golang-nuts wrote: > > I've seen that Go can call C++ functions using SWIG, but can C++ call Go > functions? > > I work on a data service written in C++ with an internal validation library. > We'd like to allow our users to contribute and manage the val

[go-nuts] Calling Go from C++

2017-11-08 Thread jhallock via golang-nuts
I've seen that Go can call C++ functions using SWIG, but can C++ call Go functions? I work on a data service written in C++ with an internal validation library. We'd like to allow our users to contribute and manage the validation rules themselves. We can assume they know Go, but not C++. -- Y

[go-nuts] %T question

2017-11-08 Thread k1attila1
Hello, i'm absolute beginner Could you help me ? package main import "fmt" const ( // Create a huge number by shifting a 1 bit left 100 places. // In other words, the binary number that is 1 followed by 100 zeroes. Big = 1 << 100 // Shift it right again 99 places, so we end up with 1<<1, or 2.

[go-nuts] Re: GO Syntax Coloring for BBEdit and TextWrangler

2017-11-08 Thread matthew . boehm
This does not recognize struct methods. Can you improve it? Example: func (p *MyClass) DoSomething(p string, i int) { ... } On Wednesday, November 11, 2009 at 9:54:23 PM UTC-6, ajstarks wrote: > > Here is the Codeless language Module used by BBEdit and TextWrangler > that will provide syntax col

Re: [go-nuts] Efficient to copy Hash?

2017-11-08 Thread Christian LeMoussel
I found why.. hash.Hash interface does not have a .Copy, -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubs

Re: [go-nuts] gccgo programs use which garbage collector?

2017-11-08 Thread Jason E. Aten
Wow. Just wow. Very exciting. That is great news. Thank you, Ian! Building gcc-tip right now... On Wednesday, November 8, 2017 at 9:34:28 AM UTC-6, Ian Lance Taylor wrote: > > > On GCC tip, which is to say the future GCC 8, gccgo uses essentially > the same garbage collector. In GCC 7 and ear

Re: [go-nuts] gccgo programs use which garbage collector?

2017-11-08 Thread Ian Lance Taylor
On Tue, Nov 7, 2017 at 8:55 PM, Jason E. Aten wrote: > > Just a general question about the binaries produced by gccgo. To wit: > > Do these binaries use the same garbage collector as gc-produced binaries -- > the highly-tuned/low-latency garbage collector that Rick and Austin work on > -- or do th

Re: [go-nuts] Efficient to copy Hash?

2017-11-08 Thread Christian LeMoussel
I optimize like this // Copy returns a copy of hash.Hash func (d *digest) Copy() hash.Hash { dCopy := *d return &dCopy } But I got error d1.Copy undefined (type hash.Hash has no field or method Copy) with this code d1 := sha256.New() d2 := sha256.New() d1.Write([]byte("a")

[go-nuts] License discussion (was Re: Zero-dependency, small codebase logger which supports StackDriver (Kubernetes) logging.

2017-11-08 Thread Shawn Milochik
On Wed, Nov 8, 2017 at 9:41 AM, Sotirios Mantziaris wrote: > i see a lot of open source under MIT and Apache-2.0, which is pretty > straightforward and clean. > > > So far, all you've said is that BSD 3-clause "might be a problem for some," and that MIT and Apache 2 are "pretty straightforward an

Re: [go-nuts] Re: Zero-dependency, small codebase logger which supports StackDriver (Kubernetes) logging.

2017-11-08 Thread Sotirios Mantziaris
i see a lot of open source under MIT and Apache-2.0, which is pretty straightforward and clean. On Wednesday, November 8, 2017 at 4:20:11 PM UTC+2, Jan Mercl wrote: > > On Wed, Nov 8, 2017 at 3:15 PM Sotirios Mantziaris > wrote: > > > BSD 3-clause? This might be a problem for some. > > Why so

Re: [go-nuts] Re: Zero-dependency, small codebase logger which supports StackDriver (Kubernetes) logging.

2017-11-08 Thread Jan Mercl
On Wed, Nov 8, 2017 at 3:15 PM Sotirios Mantziaris wrote: > BSD 3-clause? This might be a problem for some. Why so? Which license would be better? -- -j -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and sto

Re: [go-nuts] Re: Zero-dependency, small codebase logger which supports StackDriver (Kubernetes) logging.

2017-11-08 Thread Shawn Milochik
On Wed, Nov 8, 2017 at 9:15 AM, Sotirios Mantziaris wrote: > BSD 3-clause? This might be a problem for some. > > > Why's that? Seems that BSD 2-clause and MIT are pretty much the same thing, and all the 3-clause adds is that the company/contributor names can't be used to endorse products. What am

[go-nuts] Re: Zero-dependency, small codebase logger which supports StackDriver (Kubernetes) logging.

2017-11-08 Thread Sotirios Mantziaris
BSD 3-clause? This might be a problem for some. On Wednesday, November 8, 2017 at 3:41:53 PM UTC+2, Shawn Milochik wrote: > > > http://www.nikola-breznjak.com/blog/go/go-logger-kubernetes-stackdriver-format-compatibility/ > > We evaluated Apex and other loggers, and had been using logrus, but ende

Re: [go-nuts] Efficient to copy Hash?

2017-11-08 Thread Christian LeMoussel
JB, Thank you very much for your help. For adding a copy method direcly on sha256.digest, I propose this // Copy returns a copy of hash.Hash func (d *digest) Copy() hash.Hash { dh := new(digest) dh.h = d.h dh.x = d.x dh.nx = d.nx dh.len = d.len dh.is224 = d.is224 retu

[go-nuts] Managing Dependencies (as in IoC) and Avoid Globals

2017-11-08 Thread dc0d
There are Go packages that help with dependency injection, employing reflection. And other practices insist on passing everything as an argument, down the pipe; employing mostly factory methods. At the same time putting long-lived instances inside a context is not recommended - I like context fo

[go-nuts] What are Parse Html token methods for email templates in golang?

2017-11-08 Thread mkaur25355
Hi everyone, I am trying to create email templates having html tokens in golang. I have searched all over the web and found "html/template" library. It supports token format like below Hello {{.Name}} Confirm email address But the requirement for html token is something like Name: {{ te

[go-nuts] Zero-dependency, small codebase logger which supports StackDriver (Kubernetes) logging.

2017-11-08 Thread Shawn Milochik
http://www.nikola-breznjak.com/blog/go/go-logger-kubernetes-stackdriver-format-compatibility/ We evaluated Apex and other loggers, and had been using logrus, but ended up with an in-house library we like better. The primary concerns were working with StackDriver for our Google-hosted infrastructu

Re: [go-nuts] Efficient to copy Hash?

2017-11-08 Thread Jakob Borg
You can make it a teensy bit more efficient by copying the pointed-at value directly and skipping an allocation. (This isn’t safe in general but works for sha256.digest in this case.) I refactored away the string copies etc to focus on the actual hashing. https://play.golang.org/p/TxN2ni1o4v

[go-nuts] Efficient to copy Hash?

2017-11-08 Thread Christian LeMoussel
Hi, I want to calculate hash on 3 strings. First string is always the same, the other may vary. The first approach is to calculate the hash each time for the 3 strings ( BenchmarkHash) Another approach would be to calculate once for the first string, and then reuse this hash to calculate the ha

Re: [go-nuts] How to check if a request was cancelled

2017-11-08 Thread Glen Huang
In my case the client is the sole consumer of the context, so it should be fine. But I agree, checking error directly is more bullet-proof. I should probably form a habit adopting it. > On 8 Nov 2017, at 8:40 PM, Jakob Borg wrote: > > (expanding the code from the link) > > _, err := http.Defa

Re: [go-nuts] How to check if a request was cancelled

2017-11-08 Thread Jakob Borg
(expanding the code from the link) _, err := http.DefaultClient.Do(r) log.Println(err, ctx.Err() == context.Canceled) Note that, to be pedantic, this only tells you that the context has been cancelled - not that that was the error returned by the HTTP request. The HTTP request may have succeede

Re: [go-nuts] Re: How to check if a request was cancelled

2017-11-08 Thread Glen Huang
Yep, that's a good way too. Thanks. Ain also posted it on SO. On Wednesday, November 8, 2017 at 8:20:25 PM UTC+8, Jan Mercl wrote: > > On Wed, Nov 8, 2017 at 1:12 PM Glen Huang > > wrote: > > see https://play.golang.org/p/wMJ5PX1x9H > > -- > > -j > -- You received this message because you are

Re: [go-nuts] Re: How to check if a request was cancelled

2017-11-08 Thread Glen Huang
Really neat! Didn't know it was wrapped. Thank you. On Wednesday, November 8, 2017 at 8:17:59 PM UTC+8, Jakob Borg wrote: > > Errors from net/http are wrapped in an url.Error to contain information > about the request that failed. You can unwrap it with an assertion or type > switch; > > _, err

Re: [go-nuts] Re: How to check if a request was cancelled

2017-11-08 Thread Jan Mercl
On Wed, Nov 8, 2017 at 1:12 PM Glen Huang wrote: see https://play.golang.org/p/wMJ5PX1x9H -- -j -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+u

Re: [go-nuts] Re: How to check if a request was cancelled

2017-11-08 Thread Jakob Borg
Errors from net/http are wrapped in an url.Error to contain information about the request that failed. You can unwrap it with an assertion or type switch; _, err := http.DefaultClient.Do(r) if urlErr, ok := err.(*url.Error); ok { log.Println(urlErr.Err == context.Canceled) // “true", in your exam

[go-nuts] Re: How to check if a request was cancelled

2017-11-08 Thread Glen Huang
Yes. Thanks for point it out, and maybe I should've mentioned that. After posing that on SO, I have a gut feeling that it should be the intuitive way to check that. I was hoping a go author could see the question here and maybe offer some rationale why that's not the case. Sorry if it's conside

[go-nuts] Re: How to check if a request was cancelled

2017-11-08 Thread Ain
I noticed that OP has also posted this question to SO: https://stackoverflow.com/questions/47179024/how-to-check-if-a-request-was-cancelled ain kolmapäev, 8. november 2017 14:02.13 UTC+2 kirjutas Glen Huang: > > I have this simple code in which I try to check if the request was > cancelled. B

[go-nuts] How to check if a request was cancelled

2017-11-08 Thread Glen Huang
I have this simple code in which I try to check if the request was cancelled. But surprisingly, it prints false instead of true in go 1.9. I wonder what's the correct way to check that? package main import ( "context" "log" "net/http" ) func main() { r, _ := http.NewRequest("

Re: [go-nuts] newbie trying unusual sort

2017-11-08 Thread rob
Thanks guys for such a quick response. I plan on using the sort.Slice method. I looked at the SortKeys example and that will take much more study for me to understand it. --rob solomon -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsub

[go-nuts] Re: Announcing: Skylark in Go

2017-11-08 Thread bsr
looks like Nate has the answer :-) https://github.com/hippogryph/skyhook On Tuesday, November 7, 2017 at 10:29:06 PM UTC-5, bsr wrote: > > Like Nate mentioned, I too like to try it instead of lua. Is there a good > example on how to embed skylark to define custom logic. Thanks. > > On Monday, Oct

Re: [go-nuts] Re: who does go compiler link executable to glibc without an apparent reason?

2017-11-08 Thread Howard Guo
Thanks Ian. It came as a pleasant surprise that using statically compiled executable reduced(!) runtime memory usage by a noticeable portion. And gladly, till now the components are behaving well. Kind regards, Howard On Tuesday, 7 November 2017 16:23:17 UTC+1, Ian Lance Taylor wrote: > > On T

[go-nuts] Re: A way to detect closed channel

2017-11-08 Thread Christian Surlykke
This little pattern may also be useful: ticket := make(chan bool, 1) ticket <- true close(ticket) Now, first read from ticket will yield true, all subsequent reads will yield false. So any number of go-routines can do this if, but the call to close will happen at most once: if (<-ticket) {