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

2017-11-09 Thread al14031
I see . Thank you for replying.
By the way, is there somewhere you want the document to modify somewhere?
I absolutely want to contribute to golang 

2017年11月9日木曜日 15時23分15秒 UTC+9 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 the Google 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] Writing your own Context, making sure it's compatible with context.Context

2017-11-09 Thread Albert Tedja


> Can you just have a field of your Context type be a value of type 
> context.Context? 
>
> Ian 
>

I managed to do this eventually. The confusion was that my library has 
multiple types of contexts and they need to be stacked in any particular 
order. So at first, the values from previous (parent) contexts did not seem 
to transfer well to the child contexts. When looking at the context.Context 
source code to learn how it does that, I was surprised to learn that it 
propagates those cancellation signals down to its children manually, which 
is yucky.

What I ended up doing is create another Context interface for my package 
that has all the functions I need. Create a parent struct that implements 
those functions with empty features. Then each feature context can overload 
those functions as needed.

package yourpackage

import "context"

type Context interface{
context.Context
FeatureX() *X
FeatureY() *Y
FeatureZ() *Z
}

type BasicContext struct {
context.Context
}

func (ctx *BasicContext) FeatureX() *X {
return nil;
}

func WithBasicContext(parent context.Context) Context {
return &BasicContext{Context: parent}
}

type featureXContext struct {
Context
x *X
}

func (ctx *featureXContext) FeatureX() *X {
return ctx.x
}

func WithFeatureX(parent Context, x *X) Context {
return &featureXContext{Context: parent, x: x}
}

It seems to be functioning as expected, and compatible with the other 
contexts like WithDeadline or WithTimeout.

-- 
You received this message because you are subscribed to the Google 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] Upcasting/Downcasting in Go

2017-11-09 Thread Konstantin Khomoutov
On Wed, Nov 08, 2017 at 02:48:06PM -0800, Ian Lance Taylor wrote:

[...]
>> So when should I expect the type casting to work?
[...]
> When thinking about Go it's best to avoid concepts that do not apply,
> like derived class, upcast, and downcast.  You can't write
> d.testUnderlyingTypeAsReceiver() because the method is only defined on
> the type S, and d is type []int, not type S.  Passing d to
> testUnderlyingTypeAsParam works because a value of an unnamed type is
> assignable to a value of a named type when the underlying type of the
> named type is the same as the unnamed type.  There is no upcasting or
> downcasting involved.  There is just simple assignment.

Haiyu Zhen, please also note that there are no such thing as "type casting"
in Go: it only has "type conversions" and "type assertions" (which come in
several forms).

-- 
You received this message because you are subscribed to the Google 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] Not getting correct results with sort.Slice().

2017-11-09 Thread gaurav
Hi All,

I must be missing something basic here: a simple usage of sort.Slice is not 
sorting the slice correctly for me. I must be missing something very basic 
here; could someone please check this out?

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

package main
import (
"fmt"
"sort"
)
func main() {
ratings := []int{58, 21, 72, 77, 48, 9, 38, 71, 68, 77, 82, 47, 25, 94, 89, 
54, 26, 54, 54, 99, 64, 71, 76, 63, 81, 82, 60, 64, 29, 51, 87, 87, 72, 12, 
16, 20, 21, 54, 43, 41, 83, 77, 41, 61, 72, 82, 15, 50, 36, 69, 49, 53, 92, 
77, 16, 73, 12, 28, 37, 41, 79, 25, 80, 3, 37, 48, 23, 10, 55, 19, 51, 38, 
96, 92, 99, 68, 75, 14, 18, 63, 35, 19, 68, 28, 49, 36, 53, 61, 64, 91, 2, 
43, 68, 34, 46, 57, 82, 22, 67, 89}

indexes := make([]int, len(ratings))
for i := range ratings {
indexes[i] = i
}
sort.Slice(indexes, func(i, j int) bool {
return ratings[i] < ratings[j]
})
for _, ind := range indexes {
fmt.Println(ratings[ind])
}
// sort the indexes on basis of ratings stored at the given index.
sorted := sort.SliceIsSorted(indexes, func(i, j int) bool {
return ratings[i] < ratings[j]
})
fmt.Println(sorted)
}


-- 
You received this message because you are subscribed to the Google 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] Not getting correct results with sort.Slice().

2017-11-09 Thread Jan Mercl
On Thu, Nov 9, 2017 at 1:17 PM gaurav  wrote:

> I must be missing something basic here: a simple usage of sort.Slice is
not sorting the slice correctly for me. I must be missing something very
basic here; could someone please check this out?

The less test is perfomed on the ratings slice, but the item swap is
perfomed on the indexes slice. This breaks the contract of SortSlice and it
cannot work.

-- 

-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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Not getting correct results with sort.Slice().

2017-11-09 Thread Gaurav Agarwal
Hi Jan,

I am still unable to understand why is the contract broken? The "magnitude"
of each entry in "indexes" slice is defined by less func in a consistent
way. What exactly am I doing incorrect here? If I changed the program to
create structs

type entry struct {
rating int
index int
}

And then create slice of these structs and defined less() based on rating,
would it change anything conceptually?

On Thu, Nov 9, 2017 at 5:54 PM, Jan Mercl <0xj...@gmail.com> wrote:

> On Thu, Nov 9, 2017 at 1:17 PM gaurav  wrote:
>
> > I must be missing something basic here: a simple usage of sort.Slice is
> not sorting the slice correctly for me. I must be missing something very
> basic here; could someone please check this out?
>
> The less test is perfomed on the ratings slice, but the item swap is
> perfomed on the indexes slice. This breaks the contract of SortSlice and it
> cannot work.
>
> --
>
> -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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Not getting correct results with sort.Slice().

2017-11-09 Thread gaurav
I realized the mistake :-p
It needs to be this:

sort.Slice(indexes, func(i, j int) bool {
   return ratings[indexes[i]] < ratings[indexes[j]]
})


On Thursday, November 9, 2017 at 6:02:29 PM UTC+5:30, gaurav wrote:
>
> Hi Jan,
>
> I am still unable to understand why is the contract broken? The 
> "magnitude" of each entry in "indexes" slice is defined by less func in a 
> consistent way. What exactly am I doing incorrect here? If I changed the 
> program to create structs 
>
> type entry struct {
> rating int
> index int
> }
>
> And then create slice of these structs and defined less() based on rating, 
> would it change anything conceptually?
>
> On Thu, Nov 9, 2017 at 5:54 PM, Jan Mercl <0xj...@gmail.com> wrote:
>
>> On Thu, Nov 9, 2017 at 1:17 PM gaurav  wrote:
>>
>> > I must be missing something basic here: a simple usage of sort.Slice is 
>> not sorting the slice correctly for me. I must be missing something very 
>> basic here; could someone please check this out?
>>
>> The less test is perfomed on the ratings slice, but the item swap is 
>> perfomed on the indexes slice. This breaks the contract of SortSlice and it 
>> cannot work.
>>
>> -- 
>>
>> -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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Opening a Chrome Extension (.crx) file

2017-11-09 Thread Luis Furquim
Hello Gophers!

I am trying to open a chrome extension file to read its manifest.json. It
is a zip file with a .crx extension. When I unzip via command line it works
like a charm. But, if I try with golang using package archive/zip it gives
me the "zip: not a valid zip file" error. It's not the first time I use
this package and it always worked fine, including working with Libre Office
documents (.odt). I checked with the "file" command and with "od -c | head"
commands and realized that the Chrome Extensions files differ in the magic
bytes:

The regular zip file:
vuco@azrael ~/Documents $ od -c ./root/prms-minuano.zip | head -n 1 000
P K 003 004 024 \0 \0 \0 \b \0 016 210 0 @ 034 255 vuco@azrael ~/Documents
$ file ./root/prms-minuano.zip ./root/prms-minuano.zip: Zip archive data,
at least v2.0 to extract


The odt file:
vuco@azrael ~/Documents $ od -c ./mpf/v1.ProjetoIntegracao.odt | head -n 1
000 P K 003 004 024 \0 \0 \b \0 \0 256 y 026 ? ^ 306 vuco@azrael
~/Documents $ file ./mpf/v1.ProjetoIntegracao.odt
./mpf/v1.ProjetoIntegracao.odt: OpenDocument Text


The crx file:
sherlock@asspadev ~/work/download $ od -c lestrade.crx | head -n 1
000 C r 2 4 002 \0 \0 \0 & 001 \0 \0 \0 001 \0 \0
sherlock@asspadev ~/work/download $ file lestrade.crx lestrade.crx: data


Any suggestions on how to open the file?

Thank you in advance
Luis Otavio de Colla Furquim

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


[go-nuts] Re: Opening a Chrome Extension (.crx) file

2017-11-09 Thread Tamás Gulácsi

2017. november 9., csütörtök 14:11:13 UTC+1 időpontban Luis Furquim a 
következőt írta:
>
> Hello Gophers!
>
> I am trying to open a chrome extension file to read its manifest.json. It 
> is a zip file with a .crx extension. When I unzip via command line it works 
> like a charm. But, if I try with golang using package archive/zip it gives 
> me the "zip: not a valid zip file" error. It's not the first time I use 
> this package and it always worked fine, including working with Libre Office 
> documents (.odt). I checked with the "file" command and with "od -c | head" 
> commands and realized that the Chrome Extensions files differ in the magic 
> bytes:
>
> The regular zip file:
> vuco@azrael ~/Documents $ od -c ./root/prms-minuano.zip | head -n 1 
> 000 P K 003 004 024 \0 \0 \0 \b \0 016 210 0 @ 034 255 vuco@azrael 
> ~/Documents $ file ./root/prms-minuano.zip ./root/prms-minuano.zip: Zip 
> archive data, at least v2.0 to extract 
>
>
> The odt file:
> vuco@azrael ~/Documents $ od -c ./mpf/v1.ProjetoIntegracao.odt | head -n 1 
> 000 P K 003 004 024 \0 \0 \b \0 \0 256 y 026 ? ^ 306 vuco@azrael 
> ~/Documents $ file ./mpf/v1.ProjetoIntegracao.odt 
> ./mpf/v1.ProjetoIntegracao.odt: OpenDocument Text 
>
>
> The crx file:
> sherlock@asspadev ~/work/download $ od -c lestrade.crx | head -n 1
> 000 C r 2 4 002 \0 \0 \0 & 001 \0 \0 \0 001 \0 \0 
> sherlock@asspadev ~/work/download $ file lestrade.crx lestrade.crx: data 
>
>
> Any suggestions on how to open the file?
>
> Thank you in advance
> Luis Otavio de Colla Furquim
>
>
As "CRX files are ZIP files with a special header and the .crx file 
extension. ", and ZIP has a "PK\x05\x06" magic sequence, 
a working solution is to read all the bytes of the .crx into a []byte, 
change the "Cr24" to "PK\x05\x06",
then use a bytes.NewBuffer(b) as a ReaderAt.

The problem is that this signature is in every block.

-- 
You received this message because you are subscribed to the Google 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 performance benchmarks on arm64 (Qualcomm Centriq 2400)

2017-11-09 Thread Gerald Henriksen
On Wed, 8 Nov 2017 13:57:03 -0800 (PST), you wrote:

>"Go support for aarch64 is quite disappointing.

>Qualcomm and other ARMv8 
>vendors intends to put significant engineering resources to amend this 
>situation, but really any one can contribute to Go. So if you want to live 
>your mark, now is the time."

I would turn this around and say hardware support for aarch64 is quite
disappointing, and as a result nobody is interested in developing for
it (outside of certain companies who can either afford the hardware
costs or are given the hardware).

If the aarch64 hardware makers want the open source community to
develop and test for aarch64, then they need to make appropriate
hardware available to the community at a cost your average open source
developer can afford.  Yes, it nice the blogger in question was given
some (likely very expensive) hardware, but that doesn't apply to the
community in general.

[and this is restriced to ARM, POWER has the same issue]

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


[go-nuts] Re: Opening a Chrome Extension (.crx) file

2017-11-09 Thread Luis Furquim
Thank you for the directions! But this was just the first bit of the 
problem...
I changed locally the archive/zip sources, making it accept both magic 
sequences on fileHeaderSignature and directoryHeaderSignature. Then I ran 
in UnexpectedEOF trap!
I think that there is some version/flavor of the zip format that is just 
unsupported by the archive/zip package (but is supported by the zip command 
line).
I am using Go1.8.3, I will try to upgrade to current (1.9.2) version. The 
release notes mention the zip package but only for the Writer type. Anyway 
I should upgrade sooner or later...

Cheers

Em quinta-feira, 9 de novembro de 2017 11:39:24 UTC-2, Tamás Gulácsi 
escreveu:
>
>
> 2017. november 9., csütörtök 14:11:13 UTC+1 időpontban Luis Furquim a 
> következőt írta:
>>
>> Hello Gophers!
>>
>> I am trying to open a chrome extension file to read its manifest.json. It 
>> is a zip file with a .crx extension. When I unzip via command line it works 
>> like a charm. But, if I try with golang using package archive/zip it gives 
>> me the "zip: not a valid zip file" error. It's not the first time I use 
>> this package and it always worked fine, including working with Libre Office 
>> documents (.odt). I checked with the "file" command and with "od -c | head" 
>> commands and realized that the Chrome Extensions files differ in the magic 
>> bytes:
>>
>> The regular zip file:
>> vuco@azrael ~/Documents $ od -c ./root/prms-minuano.zip | head -n 1 
>> 000 P K 003 004 024 \0 \0 \0 \b \0 016 210 0 @ 034 255 vuco@azrael 
>> ~/Documents $ file ./root/prms-minuano.zip ./root/prms-minuano.zip: Zip 
>> archive data, at least v2.0 to extract 
>>
>>
>> The odt file:
>> vuco@azrael ~/Documents $ od -c ./mpf/v1.ProjetoIntegracao.odt | head -n 
>> 1 000 P K 003 004 024 \0 \0 \b \0 \0 256 y 026 ? ^ 306 vuco@azrael 
>> ~/Documents $ file ./mpf/v1.ProjetoIntegracao.odt 
>> ./mpf/v1.ProjetoIntegracao.odt: OpenDocument Text 
>>
>>
>> The crx file:
>> sherlock@asspadev ~/work/download $ od -c lestrade.crx | head -n 1
>> 000 C r 2 4 002 \0 \0 \0 & 001 \0 \0 \0 001 \0 \0 
>> sherlock@asspadev ~/work/download $ file lestrade.crx lestrade.crx: data 
>>
>>
>> Any suggestions on how to open the file?
>>
>> Thank you in advance
>> Luis Otavio de Colla Furquim
>>
>>
> As "CRX files are ZIP files with a special header and the .crx file 
> extension. ", and ZIP has a "PK\x05\x06" magic sequence, 
> a working solution is to read all the bytes of the .crx into a []byte, 
> change the "Cr24" to "PK\x05\x06",
> then use a bytes.NewBuffer(b) as a ReaderAt.
>
> The problem is that this signature is in every block.
>

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


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

2017-11-09 Thread Mauricio Rojas
Hi All,

(S(d)).testUnderlyingTypeReciever()

Regards

El miércoles, 8 de noviembre de 2017, 18:44:36 (UTC-3), Haiyu Zhen escribió:
>
> 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 
> doesn't "downcast" it to S.
> I do know that S and []int are treated as different types in Go, but as 
> the append function shows, Go will "upcast" S to slice to use 
> slice.append(). 
>
> So when should I expect the type casting to work? Or or specific to the 
> scenario, why it fails if I use slice as the function receiver for S?
>  
>
>> package main
>> import (
>> "fmt"
>> )
>> type S []int
>>  
>> func (s S) testUnderlyingTypeAsReciever() {
>> fmt.Println("Hello, playground")
>> }
>> func testUnderlyingTypeAsParam(s S) {
>> fmt.Println("Hello, playground")
>> }
>> func main() {
>> d := []int{2}
>> s := S{}
>> s = append(s, 1) // use append function for slice
>> testUnderlyingTypeAsParam(d) // pass
>> d.testUnderlyingTypeAsReciever() // fail
>> }
>
>

-- 
You received this message because you are subscribed to the Google 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] Not getting correct results with sort.Slice().

2017-11-09 Thread mrojasb2000
Hi,

sorted := sortSliceIsSorted(indexes, func(i, j int) bool {
   return  rantings[indexes[i]] < rantings[indexes[j]]
})

fmt.Println("Slice sorted?:", sorted)



El jueves, 9 de noviembre de 2017, 9:36:47 (UTC-3), gaurav escribió:
>
> I realized the mistake :-p
> It needs to be this:
>
> sort.Slice(indexes, func(i, j int) bool {
>return ratings[indexes[i]] < ratings[indexes[j]]
> })
>
>
> On Thursday, November 9, 2017 at 6:02:29 PM UTC+5:30, gaurav wrote:
>>
>> Hi Jan,
>>
>> I am still unable to understand why is the contract broken? The 
>> "magnitude" of each entry in "indexes" slice is defined by less func in a 
>> consistent way. What exactly am I doing incorrect here? If I changed the 
>> program to create structs 
>>
>> type entry struct {
>> rating int
>> index int
>> }
>>
>> And then create slice of these structs and defined less() based on 
>> rating, would it change anything conceptually?
>>
>> On Thu, Nov 9, 2017 at 5:54 PM, Jan Mercl <0xj...@gmail.com 
>> > wrote:
>>
>>> On Thu, Nov 9, 2017 at 1:17 PM gaurav >> > wrote:
>>>
>>> > I must be missing something basic here: a simple usage of sort.Slice 
>>> is not sorting the slice correctly for me. I must be missing something very 
>>> basic here; could someone please check this out?
>>>
>>> The less test is perfomed on the ratings slice, but the item swap is 
>>> perfomed on the indexes slice. This breaks the contract of SortSlice and it 
>>> cannot work.
>>>
>>> -- 
>>>
>>> -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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] question about GO and realtime GC interest by the user community

2017-11-09 Thread David Beberman
Hi,
I asked this on the golang-dev list.  They redirected me here.
We are a hard realtime JavaVM GC company.  By hard realtime
we mean that the GC is preemptible, reentrant, non-blocking, non-pausing.
For multicore it is also parallel and concurrent.
Further for realtime we support priority inheritance for synchronization 
primitives, and of course hard realtime thread priorities.

GO's requirements for GC are slightly different. The concept
would be to add our hard RTGC to the GO runtime without
disrupting the language.  

My question is about the interest level in the GO user community.
We have developed and marketed hard realtime Java bytecode VM's
for 16+ years.  
GO looks like the new kid on the block.  Maybe it moves into 
realtime use-cases, maybe it doesn't.

Kind of doing an extremely informal poll here.  
Open to any thoughts, comments.

Thanks 
David Beberman
Aicas GmbH

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


[go-nuts] Re: Short Term DSN for database/sql

2017-11-09 Thread agruetz45
So this would allow for the driver to support a different method of opening 
the connection that the sql interface would use when it needed to open a 
new connection correct?

Anthony

On Tuesday, November 7, 2017 at 9:44:05 AM UTC-8, Daniel Theophanes wrote:
>
> Go1.10 will ship with a driver connector 
> https://tip.golang.org/pkg/database/sql/driver/#Connector . It would be 
> possible for a driver to provide a callback function that returned the most 
> recent authentication parameters by using that.
>
> Thanks, -Daniel
>
>
> On Tuesday, November 7, 2017 at 5:34:20 AM UTC-8, Anthony Gruetzmacher 
> wrote:
>>
>> It appears the Generic Interface for SQL (database/sql) does not support 
>> the ability to use short lived DSN's for cases like AWS's IAM 
>> Authentication to RDS instances. It appears that when doing its connection 
>> pooling activities it always uses whatever DSN was passed initially on Open.
>>
>> 1) Is this correct.
>> 2) Assuming one is correct would the Golang project every consider adding 
>> this feature?
>> 3) If the answer is yes. How would one go about either helping to get it 
>> on the road map or better yet contributing this feature back to the 
>> community? What is this process?
>>
>> Thanks,
>> Anthony Gruetzmacher
>>
>

-- 
You received this message because you are subscribed to the Google 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] Scaleway

2017-11-09 Thread tactician
Am running on Windows. How do I load Go 1.9 onto ubuntu 

-- 
You received this message because you are subscribed to the Google 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: Short Term DSN for database/sql

2017-11-09 Thread Daniel Theophanes
It allows drivers a way to provide a connection to the pool on demand,
without needing to go through a static connection string.

On Thu, Nov 9, 2017 at 9:09 AM  wrote:

> So this would allow for the driver to support a different method of
> opening the connection that the sql interface would use when it needed to
> open a new connection correct?
>
> Anthony
>
>
> On Tuesday, November 7, 2017 at 9:44:05 AM UTC-8, Daniel Theophanes wrote:
>>
>> Go1.10 will ship with a driver connector
>> https://tip.golang.org/pkg/database/sql/driver/#Connector . It would be
>> possible for a driver to provide a callback function that returned the most
>> recent authentication parameters by using that.
>>
>> Thanks, -Daniel
>>
>>
>> On Tuesday, November 7, 2017 at 5:34:20 AM UTC-8, Anthony Gruetzmacher
>> wrote:
>>>
>>> It appears the Generic Interface for SQL (database/sql) does not support
>>> the ability to use short lived DSN's for cases like AWS's IAM
>>> Authentication to RDS instances. It appears that when doing its connection
>>> pooling activities it always uses whatever DSN was passed initially on Open.
>>>
>>> 1) Is this correct.
>>> 2) Assuming one is correct would the Golang project every consider
>>> adding this feature?
>>> 3) If the answer is yes. How would one go about either helping to get it
>>> on the road map or better yet contributing this feature back to the
>>> community? What is this process?
>>>
>>> Thanks,
>>> Anthony Gruetzmacher
>>>
>> --
> 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/fl0GiIEmbLM/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

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


[go-nuts] [ANN] Pocket Gophers’ Guide to JSON - Early Access Special

2017-11-09 Thread Nathan Kerr
The Pocket Gophers’ Guide to JSON 

Learn how to confidently handle *any* JSON with the Pocket Gophers’ Guide 
to JSON.

You’ll learn a universal approach to deal with any JSON that leverages 
encoding/json and other JSON tools in the Go ecosystem along with how to 
evaluate your implementation.

The Pocket Gophers’ Guide to JSON includes a PDF that explains the 
approach, the tools, and the evaluation method. The guide also includes 
examples based on real-world JSON with many solutions (where possible) with 
detailed evaluations.

You’ll learn how to efficiently handle your JSON with confidence that your 
solution balances the implementation with how dynamic the JSON is and at 
the same time be idiomatic Go.

Just fire up your editor and buy The Pocket Gophers’ Guide to JSON. Then 
you’ll be confidently handling *any* JSON today.

Early Access Special


   - 40% off the full price of $50!
   - Free updates as they are released!
   - The price will go up as the guide reaches completion.


Learn more about the Guide 

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


[go-nuts] Re: Scaleway

2017-11-09 Thread Mauricio Rojas
Hi,

1.- Install DockerToolbox
2.- Run command: 
   docker build -t my-golang-app .

Or 
1.- Download https://redirector.gvt1.com/edgedl/go/go1.9.2.windows-amd64.zip
2.- Unzip go1.9.2.windows-amd64.zip
3.- Set environment variable GOPATH to workspace GO
4.- Set path /bin

Regards


El jueves, 9 de noviembre de 2017, 14:30:00 (UTC-3), tactician escribió:
>
> Am running on Windows. How do I load Go 1.9 onto ubuntu 
>

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


[go-nuts] Re: Scaleway

2017-11-09 Thread Mauricio Rojas
Hi,

1.- Install Docker: apt-get install docker
2.- Search Golang image docker on Docker Hub: docker search golang
3.- Install image 
4.- Run application...

Or 

1.- Download 
https://redirector.gvt1.com/edgedl/go/go1.9.2.linux-amd64.tar.gz 

2.- tar -zxvf go1.9.2.linux-amd64.tar.gz 

3.- Set environment variable GOPATH to workspace GO
4.- Set path /bin

Regards

El jueves, 9 de noviembre de 2017, 14:30:00 (UTC-3), tactician escribió:
>
> Am running on Windows. How do I load Go 1.9 onto ubuntu 
>

-- 
You received this message because you are subscribed to the Google 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] question about GO and realtime GC interest by the user community

2017-11-09 Thread John Souvestre
I occasionally see projects which have hard real-time requirements, so I’m 
interested.

 

I understand your concern with GC but you have looked at Go’s current GC?  I 
don’t know if its limits (max pause time, max overhead) are “hard” but they are 
stated.  The one which isn’t is latency due to stopping goroutines since they 
aren’t exactly pre-emptible.  But there’s been some talk about addressing this.

 

I would think that you would need to add priorities and perhaps fairness 
guarantees to scheduling and synchronization methods.

 

It certainly sounds like a lot of work!  Perhaps firm real-time would be a good 
first step?

 

John

John Souvestre - New Orleans LA

 

From: golang-nuts@googlegroups.com [mailto:golang-nuts@googlegroups.com] On 
Behalf Of David Beberman
Sent: 2017 November 09, Thu 05:59
To: golang-nuts
Subject: [go-nuts] question about GO and realtime GC interest by the user 
community

 

Hi,
I asked this on the golang-dev list.  They redirected me here.
We are a hard realtime JavaVM GC company.  By hard realtime
we mean that the GC is preemptible, reentrant, non-blocking, non-pausing.
For multicore it is also parallel and concurrent.
Further for realtime we support priority inheritance for synchronization 
primitives, and of course hard realtime thread priorities.

GO's requirements for GC are slightly different. The concept
would be to add our hard RTGC to the GO runtime without
disrupting the language.  

My question is about the interest level in the GO user community.
We have developed and marketed hard realtime Java bytecode VM's
for 16+ years.  
GO looks like the new kid on the block.  Maybe it moves into 
realtime use-cases, maybe it doesn't.

Kind of doing an extremely informal poll here.  
Open to any thoughts, comments.

Thanks 
David Beberman
Aicas GmbH

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

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


[go-nuts] Starting an HTTP server and logging about it

2017-11-09 Thread Kevin Burke
I want to start an HTTP server, and then once it's started, log a message 
that the server has started. Here are the options for doing that:

- log ahead of time. The message gets logged before the server starts 
listening on a socket, which means you might get the message and then an 
error

log.Info("starting server on port", "port", 4567)
server.ListenAndServe()

- create a net.Listener, listen on a socket, log a message, start the 
server.

ln, err := net.Listen("tcp", addr)
log.Info("started server", "port", 4567)
server.Serve(ln)


This is fine howeve the code in ListenAndServe() does not do the same 
thing as net.Listen, it inserts a tcpKeepAliveListener in the middle there. 
To get the same behavior I have to recreate the tcpKeepAliveListener.

ln, err := net.Listen("tcp", addr) 
if err != nil { return err } 
return srv.Serve(tcpKeepAliveListener{ln.(*net.TCPListener)})

- Spin up a goroutine that tries to connect to the socket and then logs. 
This is more verbose

 for {
conn, err := net.Dial("tcp", ":"+port)
if err == nil {
defer conn.Close()
log.Info("Started server", "port", port)
return
}
time.Sleep(10 * time.Millisecond)
}

- Petition for a new http.Listen(net, addr) (net.Listener, error) API (or 
httputil.Listen) that gives you back the tcpKeepAliveListener in that 
package.

Thoughts? Has anyone else ran into or cared about this problem, or just me?

-- 
You received this message because you are subscribed to the Google 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] Starting an HTTP server and logging about it

2017-11-09 Thread Caleb Spare
I always just go with (1). This problem occurs to me and always bugs
me a little, but I file it under "issues the day is too short to worry
about". In practice when you see this in the logs

starting server on port 4567


it's clear enough what happened.

On Thu, Nov 9, 2017 at 12:16 PM, Kevin Burke  wrote:
> I want to start an HTTP server, and then once it's started, log a message
> that the server has started. Here are the options for doing that:
>
> - log ahead of time. The message gets logged before the server starts
> listening on a socket, which means you might get the message and then an
> error
>
> log.Info("starting server on port", "port", 4567)
> server.ListenAndServe()
>
> - create a net.Listener, listen on a socket, log a message, start the
> server.
>
> ln, err := net.Listen("tcp", addr)
> log.Info("started server", "port", 4567)
> server.Serve(ln)
>
>
> This is fine howeve the code in ListenAndServe() does not do the same
> thing as net.Listen, it inserts a tcpKeepAliveListener in the middle there.
> To get the same behavior I have to recreate the tcpKeepAliveListener.
>
> ln, err := net.Listen("tcp", addr)
> if err != nil { return err }
> return srv.Serve(tcpKeepAliveListener{ln.(*net.TCPListener)})
>
> - Spin up a goroutine that tries to connect to the socket and then logs.
> This is more verbose
>
>  for {
> conn, err := net.Dial("tcp", ":"+port)
> if err == nil {
> defer conn.Close()
> log.Info("Started server", "port", port)
> return
> }
> time.Sleep(10 * time.Millisecond)
> }
>
> - Petition for a new http.Listen(net, addr) (net.Listener, error) API (or
> httputil.Listen) that gives you back the tcpKeepAliveListener in that
> package.
>
> Thoughts? Has anyone else ran into or cared about this problem, or just me?
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

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


[go-nuts] try to avoid additional memory allocations

2017-11-09 Thread Vasiliy Tolstov
Hi. I have server that read/write data to many files (each is about
4-32Mb). To determine on which file i need to read/write i'm use this
function to os.OpenFile

func oid2filepath(cfg *Config, oID uint64) string {
file_path := filepath.Join(cfg.WorkDir, fmt.Sprintf("%x",
oid2vid(oID)), fmt.Sprintf("%016x", oID))
return file_path
}

oid2vid function get uint32 and return uint32 with shift some bits
path looks like (for one of 4Mb chunk) store/obj/7c2b25/007c2b250180

When i'm write 4Gb data i need to call this function 1024 times for
single big chunk of data.
Does it possible to write function that does not have additional allocations?
And does it possible to write it in portable way (i mean path separator).


-- 
Vasiliy Tolstov,
e-mail: v.tols...@selfip.ru

-- 
You received this message because you are subscribed to the Google 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: Short Term DSN for database/sql

2017-11-09 Thread agruetz45
What would happen if idle/closed connections that are in the SQL 
interface's connection pool? They go back to the driver provided Connector 
interface to re-authenticate/create a connection?

Thanks,
Anthony

On Thursday, November 9, 2017 at 10:49:00 AM UTC-8, Daniel Theophanes wrote:
>
> It allows drivers a way to provide a connection to the pool on demand, 
> without needing to go through a static connection string.
>
> On Thu, Nov 9, 2017 at 9:09 AM > wrote:
>
>> So this would allow for the driver to support a different method of 
>> opening the connection that the sql interface would use when it needed to 
>> open a new connection correct?
>>
>> Anthony
>>
>>
>> On Tuesday, November 7, 2017 at 9:44:05 AM UTC-8, Daniel Theophanes wrote:
>>>
>>> Go1.10 will ship with a driver connector 
>>> https://tip.golang.org/pkg/database/sql/driver/#Connector . It would be 
>>> possible for a driver to provide a callback function that returned the most 
>>> recent authentication parameters by using that.
>>>
>>> Thanks, -Daniel
>>>
>>>
>>> On Tuesday, November 7, 2017 at 5:34:20 AM UTC-8, Anthony Gruetzmacher 
>>> wrote:

 It appears the Generic Interface for SQL (database/sql) does not 
 support the ability to use short lived DSN's for cases like AWS's IAM 
 Authentication to RDS instances. It appears that when doing its connection 
 pooling activities it always uses whatever DSN was passed initially on 
 Open.

 1) Is this correct.
 2) Assuming one is correct would the Golang project every consider 
 adding this feature?
 3) If the answer is yes. How would one go about either helping to get 
 it on the road map or better yet contributing this feature back to the 
 community? What is this process?

 Thanks,
 Anthony Gruetzmacher

>>> -- 
>> 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/fl0GiIEmbLM/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to 
>> golang-nuts...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

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


Re: [go-nuts] Re: Short Term DSN for database/sql

2017-11-09 Thread Daniel Theophanes
I don't quite understand you question. It just allows drivers an alternate
way for the pool (sql.DB) to open a connection. Nothing ever is "returned".

On Thu, Nov 9, 2017 at 1:19 PM  wrote:

> What would happen if idle/closed connections that are in the SQL
> interface's connection pool? They go back to the driver provided Connector
> interface to re-authenticate/create a connection?
>
> Thanks,
> Anthony
>
>
> On Thursday, November 9, 2017 at 10:49:00 AM UTC-8, Daniel Theophanes
> wrote:
>
>> It allows drivers a way to provide a connection to the pool on demand,
>> without needing to go through a static connection string.
>>
>> On Thu, Nov 9, 2017 at 9:09 AM  wrote:
>>
> So this would allow for the driver to support a different method of
>>> opening the connection that the sql interface would use when it needed to
>>> open a new connection correct?
>>>
>>> Anthony
>>>
>>>
>>> On Tuesday, November 7, 2017 at 9:44:05 AM UTC-8, Daniel Theophanes
>>> wrote:

 Go1.10 will ship with a driver connector
 https://tip.golang.org/pkg/database/sql/driver/#Connector . It would
 be possible for a driver to provide a callback function that returned the
 most recent authentication parameters by using that.

 Thanks, -Daniel


 On Tuesday, November 7, 2017 at 5:34:20 AM UTC-8, Anthony Gruetzmacher
 wrote:
>
> It appears the Generic Interface for SQL (database/sql) does not
> support the ability to use short lived DSN's for cases like AWS's IAM
> Authentication to RDS instances. It appears that when doing its connection
> pooling activities it always uses whatever DSN was passed initially on 
> Open.
>
> 1) Is this correct.
> 2) Assuming one is correct would the Golang project every consider
> adding this feature?
> 3) If the answer is yes. How would one go about either helping to get
> it on the road map or better yet contributing this feature back to the
> community? What is this process?
>
> Thanks,
> Anthony Gruetzmacher
>
 --
>>> 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/fl0GiIEmbLM/unsubscribe.
>>>
>> To unsubscribe from this group and all its topics, send an email to
>>> golang-nuts...@googlegroups.com.
>>
>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/golang-nuts/fl0GiIEmbLM/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: [go-nuts] Re: Short Term DSN for database/sql

2017-11-09 Thread agruetz45
Makes sense. I think my question was more asking about the details of how 
the pool (sql.DB) worked. So this clears it up. The driver would provide 
the pool this connector to use vs the DNS string and that Connector could 
re-auth etc... This definitely allows for what I am looking for to be 
solved. The next step would be to get an IAM Connector added into the 
driver. Anyway thank you for the response very helpful.

Anthony

On Thursday, November 9, 2017 at 1:45:14 PM UTC-8, Daniel Theophanes wrote:
>
> I don't quite understand you question. It just allows drivers an alternate 
> way for the pool (sql.DB) to open a connection. Nothing ever is "returned".
>
> On Thu, Nov 9, 2017 at 1:19 PM > wrote:
>
>> What would happen if idle/closed connections that are in the SQL 
>> interface's connection pool? They go back to the driver provided Connector 
>> interface to re-authenticate/create a connection?
>>
>> Thanks,
>> Anthony
>>
>>
>> On Thursday, November 9, 2017 at 10:49:00 AM UTC-8, Daniel Theophanes 
>> wrote:
>>
>>> It allows drivers a way to provide a connection to the pool on demand, 
>>> without needing to go through a static connection string.
>>>
>>> On Thu, Nov 9, 2017 at 9:09 AM  wrote:
>>>
>> So this would allow for the driver to support a different method of 
 opening the connection that the sql interface would use when it needed to 
 open a new connection correct?

 Anthony


 On Tuesday, November 7, 2017 at 9:44:05 AM UTC-8, Daniel Theophanes 
 wrote:
>
> Go1.10 will ship with a driver connector 
> https://tip.golang.org/pkg/database/sql/driver/#Connector . It would 
> be possible for a driver to provide a callback function that returned the 
> most recent authentication parameters by using that.
>
> Thanks, -Daniel
>
>
> On Tuesday, November 7, 2017 at 5:34:20 AM UTC-8, Anthony Gruetzmacher 
> wrote:
>>
>> It appears the Generic Interface for SQL (database/sql) does not 
>> support the ability to use short lived DSN's for cases like AWS's IAM 
>> Authentication to RDS instances. It appears that when doing its 
>> connection 
>> pooling activities it always uses whatever DSN was passed initially on 
>> Open.
>>
>> 1) Is this correct.
>> 2) Assuming one is correct would the Golang project every consider 
>> adding this feature?
>> 3) If the answer is yes. How would one go about either helping to get 
>> it on the road map or better yet contributing this feature back to the 
>> community? What is this process?
>>
>> Thanks,
>> Anthony Gruetzmacher
>>
> -- 
 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/fl0GiIEmbLM/unsubscribe.

>>> To unsubscribe from this group and all its topics, send an email to 
 golang-nuts...@googlegroups.com.
>>>
>>>
 For more options, visit https://groups.google.com/d/optout.

>>> -- 
>> You received this message because you are subscribed to a topic in the 
>> Google Groups "golang-nuts" group.
>> To unsubscribe from this topic, visit 
>> https://groups.google.com/d/topic/golang-nuts/fl0GiIEmbLM/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to 
>> golang-nuts...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

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


[go-nuts] interface{} as type []interface{}

2017-11-09 Thread Trig
Is it possible to have an interface{} as type []interface{}?

-- 
You received this message because you are subscribed to the Google 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] Why is there a difference between floating-point multiplication with literals vs. variables in Go?

2017-11-09 Thread eriksrocks
Why are the following unequal in Go? Is this a bug, or is it by design? If 
it's by design, why does this occur and is this type of behavior documented 
anywhere?

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

package main

import (
"fmt"
)

func main() {
x := 10.1

fmt.Println("x == 10.1:", x == 10.1)
fmt.Println("x*3.0 == 10.1*3.0:", x*3.0 == 10.1*3.0)
fmt.Println("x*3.0:", x*3.0)
fmt.Println("10.1*3.0: ", 10.1*3.0)
}

Produces:

x == 10.1: true
x*3.0 == 10.1*3.0: false
x*3.0: 30.297
10.1*3.0:  30.3


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


Re: [go-nuts] Why is there a difference between floating-point multiplication with literals vs. variables in Go?

2017-11-09 Thread andrey mirtchovski
It's in the spec under constants: arithmetic has arbitrary precision. When
you restrict to a floating point type by assigning to a variable you also
restrict the precision of the result.

On Thu, Nov 9, 2017, 4:35 PM  wrote:

> Why are the following unequal in Go? Is this a bug, or is it by design? If
> it's by design, why does this occur and is this type of behavior documented
> anywhere?
>
> https://play.golang.org/p/itEV9zwV2a
>
> package main
>
> import (
> "fmt"
> )
>
> func main() {
> x := 10.1
>
> fmt.Println("x == 10.1:", x == 10.1)
> fmt.Println("x*3.0 == 10.1*3.0:", x*3.0 == 10.1*3.0)
> fmt.Println("x*3.0:", x*3.0)
> fmt.Println("10.1*3.0: ", 10.1*3.0)
> }
>
> Produces:
>
> x == 10.1: true
> x*3.0 == 10.1*3.0: false
> x*3.0: 30.297
> 10.1*3.0:  30.3
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

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


[go-nuts] Re: Why is there a difference between floating-point multiplication with literals vs. variables in Go?

2017-11-09 Thread Trig
There are 3rd-party packages/vendors that help with this, such as:

https://github.com/shopspring/decimal

On Thursday, November 9, 2017 at 5:36:03 PM UTC-6, Erik Swan wrote:
>
> Why are the following unequal in Go? Is this a bug, or is it by design? If 
> it's by design, why does this occur and is this type of behavior documented 
> anywhere?
>
> https://play.golang.org/p/itEV9zwV2a
>
> package main
>
> import (
> "fmt"
> )
>
> func main() {
> x := 10.1
>
> fmt.Println("x == 10.1:", x == 10.1)
> fmt.Println("x*3.0 == 10.1*3.0:", x*3.0 == 10.1*3.0)
> fmt.Println("x*3.0:", x*3.0)
> fmt.Println("10.1*3.0: ", 10.1*3.0)
> }
>
> Produces:
>
> x == 10.1: true
> x*3.0 == 10.1*3.0: false
> x*3.0: 30.297
> 10.1*3.0:  30.3
>
>
>

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


[go-nuts] Re: Why is there a difference between floating-point multiplication with literals vs. variables in Go?

2017-11-09 Thread eriksrocks
Thanks for the answers. I wasn't interested as much in fixed decimal 
solutions as understanding why what appeared to be the same floating-point 
math on the surface was returning different results.

I also posted this question on Stack Overflow and I think the answers there 
are pretty comprehensive:
https://stackoverflow.com/questions/47213283/why-is-there-a-difference-between-floating-point-multiplication-with-literals-vs

On Thursday, November 9, 2017 at 5:16:37 PM UTC-7, Trig wrote:
>
> There are 3rd-party packages/vendors that help with this, such as:
>
> https://github.com/shopspring/decimal
>
> On Thursday, November 9, 2017 at 5:36:03 PM UTC-6, Erik Swan wrote:
>>
>> Why are the following unequal in Go? Is this a bug, or is it by design? 
>> If it's by design, why does this occur and is this type of behavior 
>> documented anywhere?
>>
>> https://play.golang.org/p/itEV9zwV2a
>>
>> package main
>>
>> import (
>> "fmt"
>> )
>>
>> func main() {
>> x := 10.1
>>
>> fmt.Println("x == 10.1:", x == 10.1)
>> fmt.Println("x*3.0 == 10.1*3.0:", x*3.0 == 10.1*3.0)
>> fmt.Println("x*3.0:", x*3.0)
>> fmt.Println("10.1*3.0: ", 10.1*3.0)
>> }
>>
>> Produces:
>>
>> x == 10.1: true
>> x*3.0 == 10.1*3.0: false
>> x*3.0: 30.297
>> 10.1*3.0:  30.3
>>
>>
>>

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


[go-nuts] Re: try to avoid additional memory allocations

2017-11-09 Thread krolaw
func oid2filepath(cfg *Config, oID uint64) string { 
   return fmt.Sprintf("%s%c%x%c%016x", cfg.WorkDir, filepath.Seperator, 
oid2vid(oID), filepath.Seperator, oID)
}

On Friday, 10 November 2017 09:58:03 UTC+13, Vasiliy Tolstov wrote:
>
> Hi. I have server that read/write data to many files (each is about 
> 4-32Mb). To determine on which file i need to read/write i'm use this 
> function to os.OpenFile 
>
> func oid2filepath(cfg *Config, oID uint64) string { 
> file_path := filepath.Join(cfg.WorkDir, fmt.Sprintf("%x", 
> oid2vid(oID)), fmt.Sprintf("%016x", oID)) 
> return file_path 
> } 
>
> oid2vid function get uint32 and return uint32 with shift some bits 
> path looks like (for one of 4Mb chunk) store/obj/7c2b25/007c2b250180 
>
> When i'm write 4Gb data i need to call this function 1024 times for 
> single big chunk of data. 
> Does it possible to write function that does not have additional 
> allocations? 
> And does it possible to write it in portable way (i mean path separator). 
>
>
> -- 
> Vasiliy Tolstov, 
> e-mail: v.to...@selfip.ru  
>

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


[go-nuts] Re: try to avoid additional memory allocations

2017-11-09 Thread krolaw


On Friday, 10 November 2017 13:52:51 UTC+13, krolaw wrote:
>
> func oid2filepath(cfg *Config, oID uint64) string { 
>return fmt.Sprintf("%s%c%x%c%016x", cfg.WorkDir, filepath.Separator, 
> oid2vid(oID), filepath.Separator, oID)
> }
>
> On Friday, 10 November 2017 09:58:03 UTC+13, Vasiliy Tolstov wrote:
>>
>> Hi. I have server that read/write data to many files (each is about 
>> 4-32Mb). To determine on which file i need to read/write i'm use this 
>> function to os.OpenFile 
>>
>> func oid2filepath(cfg *Config, oID uint64) string { 
>> file_path := filepath.Join(cfg.WorkDir, fmt.Sprintf("%x", 
>> oid2vid(oID)), fmt.Sprintf("%016x", oID)) 
>> return file_path 
>> } 
>>
>> oid2vid function get uint32 and return uint32 with shift some bits 
>> path looks like (for one of 4Mb chunk) store/obj/7c2b25/007c2b250180 
>>
>> When i'm write 4Gb data i need to call this function 1024 times for 
>> single big chunk of data. 
>> Does it possible to write function that does not have additional 
>> allocations? 
>> And does it possible to write it in portable way (i mean path separator). 
>>
>>
>> -- 
>> Vasiliy Tolstov, 
>> e-mail: v.to...@selfip.ru 
>>
>

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


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

2017-11-09 Thread Glen Huang
Any suggestion how to improve compressor and resizer's APIs?

Regards,
Glen

On Thursday, November 9, 2017 at 12:26:14 PM UTC+8, Glen Huang wrote:
>
> 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 compressor that accepts an io.Writer, and 
> then write to the compressor.
>
> The problem comes when I want to join resizing and compressing. They're 
> Resizer and Compressor respectively, and they conforms to io.WriteCloser. 
> Compressor is nested inside Resizer. When Resizer is closed, I want 
> Compressor to be automatically closed. But I don't know how to do it in a 
> general way. For example
>
> type Thumbnail struct {
> w   io.Writer
> ContentType string
> generator   io.WriteCloser
> }
>
> func NewThumbnail(w io.Writer, contentType string) *Thumbnail {
> c = &Content{w, contentType, nil}
> switch contentType {
> case "image/jpeg":
> compressor := jpeg.NewCompressor(w)
> resizer := jpeg.Resizer(compressor)
> c.generator = jpeg.NewCompressor(w)
> }
> return c
> }
>
> func (c *Thumbnail) Close() error {
> return generator.Close()
> }
>
>
>
> Right now, closing generator won't close compressor.
>
> I don't want to explicitly store compressor and resizer in Thumbnail and 
> close them manually, because I want to support different image types, which 
> might involve different steps to generate the thumbnail.
>
> In this case, should I make Compressor and Resizer accept io.WriteCloser 
> instead? I'm not sure because
>
> 1. why the compress stdlib doesn't accept io.WriteCloser?
> 2. I will need to give io.Write to Compressor eventually, in which case I 
> need to wrap it in a ioutil.NopCloser, which is only for io.Reader. Maybe 
> there is a reason it only wraps io.Reader?
>
> Regards,
> Glen
>

-- 
You received this message because you are subscribed to the Google 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] interface{} as type []interface{}

2017-11-09 Thread Jesse McNelis
On Fri, Nov 10, 2017 at 10:27 AM, Trig  wrote:
> Is it possible to have an interface{} as type []interface{}?

Yep, you can store a slice of interface{} in an interface{}
eg.

// interface{} holding an []interface{} holding ints
var a interface{} = []interface{}{1,2,3,4,5}

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

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


[go-nuts] How to Upload a file using angular4 for browsing and api created in golang?

2017-11-09 Thread Mandeep Kaur
Hi,

I am working on an application in which I need to upload a file using 
Golang and Angular 4.Suppose I have an input type file and an upload button 
on the screen. When I browse a file from my system and clicks upload 
button.Now following are my queries regarding file upload:

1. How will angular process the file at front end?

2. If it processes the file then what it will return to the rest api as 
data.

3. Which method will be used to process the file like if it is an image 
then which methods like XHR, HTTP2.0 and Base64encode will be used?

4. Can file be uploaded via angular script and it will give download url to 
rest api?

5. The uploaded file should not be executable.

6. The file should only be rendered using that download url.Hope I have 
framed the queries well. If there is anything missing please add to the 
question.

Thanks!

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


[go-nuts] Re: gRPC golang server and client testing

2017-11-09 Thread Zeewell Yu
Hi,any solution now?  I am looking for the best way too.

On Sunday, April 24, 2016 at 3:31:19 AM UTC+8, Sankar wrote:
>
> Hi
>
> I have a .proto file which I ran with protoc to generate the _pb.go file. 
> I then wrote a server and a client program that uses the above _pb.go 
> program. Now what is the best way to unit test the server and client pieces 
> ? (complete with mocking, benchmarks for both client and server; end-to-end 
> testing, etc.)
>
> IOW, I am trying to find out the test programs for 
> https://github.com/grpc/grpc-go/blob/master/examples/helloworld/greeter_server/main.go
>  
> and 
> https://github.com/grpc/grpc-go/blob/master/examples/helloworld/greeter_client/main.go
>  
>
> Thanks.
>
> Sankar
>

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


[go-nuts] Re: try to avoid additional memory allocations

2017-11-09 Thread peterGo
Vasiliy,

For portability, when you initialize cfg.WorkDir, clean it: cfg.WorkDir = 
filepath.Clean(cfg.WorkDir)

You can reduce the allocations from 5 to 1. However, optimization can lead 
to obscurity. For example,

$ go test oid_test.go -bench=.
BenchmarkVasiliy-4 200700 ns/op88 B/op5 allocs/op
BenchmarkKrolaw-4  300550 ns/op80 B/op4 allocs/op
BenchmarkPeter-4  1000201 ns/op48 B/op1 allocs/op

Playground: https://play.golang.org/p/DnGoM8PYd6

Peter


On Thursday, November 9, 2017 at 3:58:03 PM UTC-5, Vasiliy Tolstov wrote:
>
> Hi. I have server that read/write data to many files (each is about 
> 4-32Mb). To determine on which file i need to read/write i'm use this 
> function to os.OpenFile 
>
> func oid2filepath(cfg *Config, oID uint64) string { 
> file_path := filepath.Join(cfg.WorkDir, fmt.Sprintf("%x", 
> oid2vid(oID)), fmt.Sprintf("%016x", oID)) 
> return file_path 
> } 
>
> oid2vid function get uint32 and return uint32 with shift some bits 
> path looks like (for one of 4Mb chunk) store/obj/7c2b25/007c2b250180 
>
> When i'm write 4Gb data i need to call this function 1024 times for 
> single big chunk of data. 
> Does it possible to write function that does not have additional 
> allocations? 
> And does it possible to write it in portable way (i mean path separator). 
>
>
> -- 
> Vasiliy Tolstov, 
> e-mail: v.to...@selfip.ru  
>

-- 
You received this message because you are subscribed to the Google 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.