[go-nuts] Reusing tcp connections on tunnels

2020-01-16 Thread XXX ZZZ
Hello,

I'm trying to write an application that will basically serve as a tunnel 
between some servers outside our network and our internal servers. For this 
I've started using a snippet that creates a tcp listener and then dials to 
a remote host. Code is shown here:

https://play.golang.org/p/4wjCZFXq6Yg

The code works just fine, however every time it gets a new request it dials 
a new connection to the remote host, and then after all data has been 
forwarded to both sides it closes them. I'm no expert on networking but 
this looks like its just opening/closing tcp connections instead of just 
reusing them, is this correct? if so, what would be the correct way of 
resuing the connection? 

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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/3497df63-df20-4e07-a2b8-db1a49159c2d%40googlegroups.com.


Re: [go-nuts] Re: Random panic in production with Sprintf

2019-05-02 Thread XXX ZZZ
No use of C via CGO at all.

Afaik, there isn't any unsafe use of the string, we are basically reading 
it from a get parameter (fasthttp server) on an http request and then 
adding it into this structure, most of the times is just a 5 char string. 
Out of several millions requests, this panic happens.

I failed to find any kind of race using go race detector, I'm currently 
doing some more debugging, hopefuly I should have more info/tests soon.

El jueves, 2 de mayo de 2019, 20:44:33 (UTC-3), Burak Serdar escribió:
>
> On Thu, May 2, 2019 at 3:56 PM Ian Lance Taylor  > wrote: 
> > 
> > On Thu, May 2, 2019 at 2:50 PM Anthony Martin  > wrote: 
> > > 
> > > What version of Go are you using? 
> > > 
> > > XXX ZZZ > once said: 
> > > > fmt.(*pp).fmtString(0xc023c17740, 0x0, 0x5, 0xc00076) 
> > > > /usr/local/go/src/fmt/print.go:448 +0x132 
> > > > fmt.(*pp).printArg(0xc023c17740, 0x9978e0, 0xc016a68a30, 0x76) 
> > > > /usr/local/go/src/fmt/print.go:684 +0x880 
> > > > fmt.(*pp).doPrintf(0xc023c17740, 0xa6e22f, 0x5, 0xc048c27818, 0x1, 
> 0x1) 
> > > > /usr/local/go/src/fmt/print.go:1112 +0x3ff 
> > > > fmt.Sprintf(0xa6e22f, 0x5, 0xc048c27818, 0x1, 0x1, 0x80, 0xa36200) 
> > > > /usr/local/go/src/fmt/print.go:214 +0x66 
> > > 
> > > This shows signs of memory corruption. The last argument passed to 
> > > fmtString (0xc00076) should be the same as the last argument 
> > > passed to printArg (0x76 or 'v') but it has some high bits set. Also, 
> > > the pointer to the format string data changes from 0xa6e22f (which is 
> > > probably in the .rodata section of the binary) to 0x0. 
> > > 
> > > Something is amiss. 
> > 
> > The change from 0x76 to 0xc00076 does not necessarily indicate a 
> > problem.  The stack backtrace does not know the types.  The value here 
> > is a rune, which is 32 bits.  The compiler will only set the low order 
> > 32 bits on the stack, leaving the high order 32 bits unset.  So the 
> > 0xc0 could just be garbage left on the stack. 
> > 
> > I don't *think* the format string is changing.  I think the 0 is from 
> > the string being printed, not the format string.  They both happen to 
> > be length 5. 
>
> There's something that doesn't make sense here. The 0 is from the 
> string being printed, it is not the format string. But how can that 
> be? 
>
> Even if there is a race, the string cannot have a 0 for the slice, can 
> it? So the other option is when Sprintf is called, the string being 
> printed is already corrupt. Can there be an overflow somewhere that is 
> somehow undetected? Any unsafe use in the program? 
>
>
> > 
> > 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 golan...@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: Random panic in production with Sprintf

2019-05-02 Thread XXX ZZZ
using go version go1.12.4 linux/amd64

El jueves, 2 de mayo de 2019, 18:50:24 (UTC-3), Anthony Martin escribió:
>
> What version of Go are you using? 
>
> XXX ZZZ > once said: 
> > fmt.(*pp).fmtString(0xc023c17740, 0x0, 0x5, 0xc00076) 
> > /usr/local/go/src/fmt/print.go:448 +0x132 
> > fmt.(*pp).printArg(0xc023c17740, 0x9978e0, 0xc016a68a30, 0x76) 
> > /usr/local/go/src/fmt/print.go:684 +0x880 
> > fmt.(*pp).doPrintf(0xc023c17740, 0xa6e22f, 0x5, 0xc048c27818, 0x1, 0x1) 
> > /usr/local/go/src/fmt/print.go:1112 +0x3ff 
> > fmt.Sprintf(0xa6e22f, 0x5, 0xc048c27818, 0x1, 0x1, 0x80, 0xa36200) 
> > /usr/local/go/src/fmt/print.go:214 +0x66 
>
> This shows signs of memory corruption. The last argument passed to 
> fmtString (0xc00076) should be the same as the last argument 
> passed to printArg (0x76 or 'v') but it has some high bits set. Also, 
> the pointer to the format string data changes from 0xa6e22f (which is 
> probably in the .rodata section of the binary) to 0x0. 
>
> Something is amiss. 
>
>   Anthony 
>

-- 
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] Random panic in production with Sprintf

2019-05-02 Thread XXX ZZZ
I'm testing race conditions again as we speak, however this object is 
created WITHIN the goroutine (the http request), there is no way, afaik, 
that is being used from another routine.

El jueves, 2 de mayo de 2019, 15:19:02 (UTC-3), Marcin Romaszewicz escribió:
>
> If that's the actual problem, you'd just be masking it, and producing an 
> invalid "x". Look here:
>
> func (r *Subid_info) Prepare_subid_logic(){
> r.Second_subid_8=fmt.Sprintf("1%07v", r.Second_subid) > panic 
> happens here.
> }
>
> r.Second_subid is in an invalid state which normal Go code could not 
> create. This means that some other goroutine might be in the middle of 
> changing its value at the same time, and you have a race condition, so Ian 
> Lance Taylor's suggestion to run using the race detector is probably the 
> best bet.
>
> -- Marcin
>
>
> On Thu, May 2, 2019 at 11:13 AM Burak Serdar  > wrote:
>
>> On Thu, May 2, 2019 at 11:31 AM XXX ZZZ > > wrote:
>> >
>> > Hello,
>> >
>> > We are having a random panic on our go application that is happening 
>> once every million requests or so, and so far we haven't been able to 
>> reproduce it nor to even grasp what's going on.
>> >
>> > Basically our code goes like:
>> >
>> > type Subid_info struct{
>> > Affiliate_subid string
>> > Second_subidstring
>> > Second_subid_8string
>> > S2string
>> > Internal_subidstring
>> > Internal_subid_9string
>> > Internal_subid_12 string
>> > Result string
>> > }
>> >
>> > func (r *Subid_info) Prepare_subid_logic(){
>> > r.Second_subid_8=fmt.Sprintf("1%07v", r.Second_subid) > panic 
>> happens here.
>> > }
>> >
>> > And the trace we get is:
>> >
>> > panic: runtime error: invalid memory address or nil pointer dereference
>> > [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x466b6e]
>> >
>> > goroutine 17091 [running]:
>> > unicode/utf8.RuneCountInString(0x0, 0x5, 0xc048c275a8)
>> > /usr/local/go/src/unicode/utf8/utf8.go:411 +0x2e
>> > fmt.(*fmt).padString(0xc023c17780, 0x0, 0x5)
>> > /usr/local/go/src/fmt/format.go:113 +0x134
>> > fmt.(*fmt).fmtS(0xc023c17780, 0x0, 0x5)
>> > /usr/local/go/src/fmt/format.go:347 +0x61
>> > fmt.(*pp).fmtString(0xc023c17740, 0x0, 0x5, 0xc00076)
>>
>> Right here in fmtString, the function gets a 0x0, 0x5 arg, which is I
>> believe a string of length 5 with a nil slice. So it looks like
>> somehow r.Second_subid has nil buffer here. When a string is used as
>> an interface{}, afaik, the interface keeps the value, not the pointer
>> to the string. So I can't see how this is possible. But I wonder if
>> copying the value before sprintf could fix it:
>>
>> x:=r.Second_subid
>> r.Second_subid_8=fmt.Sprintf("1%07v", x)
>>
>>
>>
>>
>> > /usr/local/go/src/fmt/print.go:448 +0x132
>> > fmt.(*pp).printArg(0xc023c17740, 0x9978e0, 0xc016a68a30, 0x76)
>> > /usr/local/go/src/fmt/print.go:684 +0x880
>> > fmt.(*pp).doPrintf(0xc023c17740, 0xa6e22f, 0x5, 0xc048c27818, 0x1, 0x1)
>> > /usr/local/go/src/fmt/print.go:1112 +0x3ff
>> > fmt.Sprintf(0xa6e22f, 0x5, 0xc048c27818, 0x1, 0x1, 0x80, 0xa36200)
>> > /usr/local/go/src/fmt/print.go:214 +0x66
>> > 
>> code/sharedobjects/sources.(*Subid_info).Prepare_subid_logic(0xc019292f80, 
>> 0x2)
>> >
>> > Given that we can't reproduce it, what's the logical way to debug this 
>> and find out what's happening?
>> >
>> > 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 golan...@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 golan...@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] Random panic in production with Sprintf

2019-05-02 Thread XXX ZZZ
I did but nothing detected.

However there aren't any goroutined involved (except for the http request), 
other than that, this variable isn't shared among routines.

El jueves, 2 de mayo de 2019, 14:54:42 (UTC-3), Ian Lance Taylor escribió:
>
> On Thu, May 2, 2019 at 10:31 AM XXX ZZZ > 
> wrote: 
> > 
> > We are having a random panic on our go application that is happening 
> once every million requests or so, and so far we haven't been able to 
> reproduce it nor to even grasp what's going on. 
> > 
> > Basically our code goes like: 
> > 
> > type Subid_info struct{ 
> > Affiliate_subid string 
> > Second_subidstring 
> > Second_subid_8string 
> > S2string 
> > Internal_subidstring 
> > Internal_subid_9string 
> > Internal_subid_12 string 
> > Result string 
> > } 
> > 
> > func (r *Subid_info) Prepare_subid_logic(){ 
> > r.Second_subid_8=fmt.Sprintf("1%07v", r.Second_subid) > panic 
> happens here. 
> > } 
> > 
> > And the trace we get is: 
> > 
> > panic: runtime error: invalid memory address or nil pointer dereference 
> > [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x466b6e] 
> > 
> > goroutine 17091 [running]: 
> > unicode/utf8.RuneCountInString(0x0, 0x5, 0xc048c275a8) 
> > /usr/local/go/src/unicode/utf8/utf8.go:411 +0x2e 
> > fmt.(*fmt).padString(0xc023c17780, 0x0, 0x5) 
> > /usr/local/go/src/fmt/format.go:113 +0x134 
> > fmt.(*fmt).fmtS(0xc023c17780, 0x0, 0x5) 
> > /usr/local/go/src/fmt/format.go:347 +0x61 
> > fmt.(*pp).fmtString(0xc023c17740, 0x0, 0x5, 0xc00076) 
> > /usr/local/go/src/fmt/print.go:448 +0x132 
> > fmt.(*pp).printArg(0xc023c17740, 0x9978e0, 0xc016a68a30, 0x76) 
> > /usr/local/go/src/fmt/print.go:684 +0x880 
> > fmt.(*pp).doPrintf(0xc023c17740, 0xa6e22f, 0x5, 0xc048c27818, 0x1, 0x1) 
> > /usr/local/go/src/fmt/print.go:1112 +0x3ff 
> > fmt.Sprintf(0xa6e22f, 0x5, 0xc048c27818, 0x1, 0x1, 0x80, 0xa36200) 
> > /usr/local/go/src/fmt/print.go:214 +0x66 
> > 
> code/sharedobjects/sources.(*Subid_info).Prepare_subid_logic(0xc019292f80, 
> 0x2) 
> > 
> > Given that we can't reproduce it, what's the logical way to debug this 
> and find out what's happening? 
>
> The first thing to try is running your program under the race detector. 
>
> 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.


[go-nuts] Random panic in production with Sprintf

2019-05-02 Thread XXX ZZZ
Hello,

We are having a random panic on our go application that is happening once 
every million requests or so, and so far we haven't been able to reproduce 
it nor to even grasp what's going on.

Basically our code goes like:

type Subid_info struct{
Affiliate_subid string
Second_subidstring
Second_subid_8string
S2string
Internal_subidstring
Internal_subid_9string
Internal_subid_12 string
Result string
}

func (r *Subid_info) Prepare_subid_logic(){
r.Second_subid_8=fmt.Sprintf("1%07v", r.Second_subid) > panic 
happens here.
}

And the trace we get is:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x466b6e]

goroutine 17091 [running]:
unicode/utf8.RuneCountInString(0x0, 0x5, 0xc048c275a8)
/usr/local/go/src/unicode/utf8/utf8.go:411 +0x2e
fmt.(*fmt).padString(0xc023c17780, 0x0, 0x5)
/usr/local/go/src/fmt/format.go:113 +0x134
fmt.(*fmt).fmtS(0xc023c17780, 0x0, 0x5)
/usr/local/go/src/fmt/format.go:347 +0x61
fmt.(*pp).fmtString(0xc023c17740, 0x0, 0x5, 0xc00076)
/usr/local/go/src/fmt/print.go:448 +0x132
fmt.(*pp).printArg(0xc023c17740, 0x9978e0, 0xc016a68a30, 0x76)
/usr/local/go/src/fmt/print.go:684 +0x880
fmt.(*pp).doPrintf(0xc023c17740, 0xa6e22f, 0x5, 0xc048c27818, 0x1, 0x1)
/usr/local/go/src/fmt/print.go:1112 +0x3ff
fmt.Sprintf(0xa6e22f, 0x5, 0xc048c27818, 0x1, 0x1, 0x80, 0xa36200)
/usr/local/go/src/fmt/print.go:214 +0x66
code/sharedobjects/sources.(*Subid_info).Prepare_subid_logic(0xc019292f80, 
0x2)

Given that we can't reproduce it, what's the logical way to debug this and 
find out what's happening?

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: Launching a windows app from command line with paths in arguments problem

2019-03-21 Thread XXX ZZZ
I just found out that removing "" from arguments seems to be somewhat 
working, so if we do:

{" --user-data-dir=C:\ProfileTest 1",
" --load-extension="C:\test",

Golang automatically adds the " when running the command, in fact the 
command line -as per chrome chrome:version- is correct. The extension is 
loaded properly but the --user-data-dir is not being recognized (although 
it appears on the command line). Oddly enough, If i copy paste the executed 
command line in cmd, it works as it should.

Is there anything else am I missing?

Otherwise, the .bat option seems to be the way to go.

El jueves, 21 de marzo de 2019, 15:05:29 (UTC-3), Krzysztof Kowalczyk 
escribió:
>
> As a total work-around you can always write start_chrome.bat::
> your command to launch chrome.
>
> and then from go execute as: "cmd.exe", "/k", "start_chrome.bat" 
> (double-check the "/k", I'm writing from memory).
>
> Also, to me the red flag is using -foo="quoted argument".parts.
>
> On windows, cmd-line args are just a single string (see 
> https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-createprocessw)
>  
> and the standard for quoting arguments is informal. So Go encodes 
> []string{arg1, arg2, ...} as a single string in what they believe is the 
> right way and chrome decodes this back into separate arguments the way it 
> believes is the right way.
>
> If there's a mismatch, problems ensue.
>
> For that reason, if chrome accepts it, use []string(`-foo`, `arg with 
> space`} instead of []string{`-foo="arg with space"`}.. Double-quoting of 
> `"` is most likely the reason for the mismatch.
>
> In the end, you don't have to guess.
>
> Go's implementation of os/exec is a wrapper around windows API for 
> creating processes 
> https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-createprocessw
>
> That implementation is shipped with the compiler. You can step through 
> this code in the debugger down to the point of calling said windows API. 
> You can see exactly what Go is passing as cmd-line arg and you can then 
> test with chrome what the right form would be.
>
> You'll either notice that you made a mistake in how you're calling it or 
> that there is a bug in the implementation.
>
> If there's a bug in the implementation, you can open an issue on GitHub 
> and you can fix the bug yourself by copying the implementation and making a 
> fix.
>
> That being said, to reiterate, the quoting of args i.e. constructing a 
> single string out of multiple args and then parsing it back into parts is 
> not formally specified and even if it was, different implementations can 
> have bugs. It could just as well be issue on the chrome side.
>
> -- kjk
>
> On Thursday, March 21, 2019 at 9:13:52 AM UTC-7, XXX ZZZ wrote:
>>
>> Hello,
>>
>> I'm trying to launch Chrome from Go under windows, some of the arguments 
>> I'm passing have custom paths in it and it seems that go is sanitizing 
>> these arguments and not recognizing the paths. Basically it seems to be 
>> appending the application path into the arguments with a path.
>>
>> Code is as follows:
>>
>> package main
>>
>> import(
>> "os/exec"
>> "fmt"
>> )
>>
>> func main(){
>> fmt.Printf("Trying to start Chrome\n")
>>
>> 
>> AppCommand:="C:\\Users\\User\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"
>> Args:=[]string{" --user-data-dir=\"C:\\ProfileTest 1\"",
>> " --load-extension=\"C:\\test\"",
>> " --disk-cache-dir=\"C:\\profileCache\"",
>> " --disable-preconnect",
>> " --dns-prefetch-disable",
>> " --start-maximized",
>> " --allow-insecure-localhost",
>> " --ignore-certificate-errors",
>> " --ignore-certificate-errors-spki-list",
>> " --no-default-browser-check",
>> " --disable-infobars"}
>>
>> cmd := exec.Command(AppCommand,  Args...)
>> //stdout, err := cmd.Output()
>> if err := cmd.Start(); err != nil {
>> fmt.Printf("Start Chrome error %+v\n", err)
>> continue
>> }
>> }
>>
>> At chrome, we noticed that the load-extension path is being appended 
>> with: "C:\\Users\\User\\AppData\\Local\\Google\\Chrome\\Application\\" so 
>> it ends up with: 
>> "C:\\Users\\User\\AppData\\Local\\Google\\Chrome\\Application\\""C:\\test", 
>> same goes for the other arguments with a path.
>>
>> Is there any way to tell go to avoid doing this? Maybe just executing a 
>> command straight from a command line?
>>
>> 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: Launching a windows app from command line with paths in arguments problem

2019-03-21 Thread XXX ZZZ
Just tried it out, unfortunately, it keeps having the same error, even if I 
apply this format to the rest of the arguments


El jueves, 21 de marzo de 2019, 13:46:29 (UTC-3), Jake Montgomery escribió:
>
> It is likely that the spaces before the command line arguments is 
> confusing the Chrome parser. Try removing them for every item in Args, and 
> it may work. 
>
> On a style note, I would use:
>
> AppCommand:=
> `C:\Users\User\AppData\Local\Google\Chrome\Application\chrome.exe`
>
>  instead of:
>
> AppCommand:=
> "C:\\Users\\User\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"
>
>
>
>
>
> On Thursday, March 21, 2019 at 12:13:52 PM UTC-4, XXX ZZZ wrote:
>>
>> Hello,
>>
>> I'm trying to launch Chrome from Go under windows, some of the arguments 
>> I'm passing have custom paths in it and it seems that go is sanitizing 
>> these arguments and not recognizing the paths. Basically it seems to be 
>> appending the application path into the arguments with a path.
>>
>> Code is as follows:
>>
>> package main
>>
>> import(
>> "os/exec"
>> "fmt"
>> )
>>
>> func main(){
>> fmt.Printf("Trying to start Chrome\n")
>>
>> 
>> AppCommand:="C:\\Users\\User\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"
>> Args:=[]string{" --user-data-dir=\"C:\\ProfileTest 1\"",
>> " --load-extension=\"C:\\test\"",
>> " --disk-cache-dir=\"C:\\profileCache\"",
>> " --disable-preconnect",
>> " --dns-prefetch-disable",
>> " --start-maximized",
>> " --allow-insecure-localhost",
>> " --ignore-certificate-errors",
>> " --ignore-certificate-errors-spki-list",
>> " --no-default-browser-check",
>> " --disable-infobars"}
>>
>> cmd := exec.Command(AppCommand,  Args...)
>> //stdout, err := cmd.Output()
>> if err := cmd.Start(); err != nil {
>> fmt.Printf("Start Chrome error %+v\n", err)
>> continue
>> }
>> }
>>
>> At chrome, we noticed that the load-extension path is being appended 
>> with: "C:\\Users\\User\\AppData\\Local\\Google\\Chrome\\Application\\" so 
>> it ends up with: 
>> "C:\\Users\\User\\AppData\\Local\\Google\\Chrome\\Application\\""C:\\test", 
>> same goes for the other arguments with a path.
>>
>> Is there any way to tell go to avoid doing this? Maybe just executing a 
>> command straight from a command line?
>>
>> 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] Launching a windows app from command line with paths in arguments problem

2019-03-21 Thread XXX ZZZ
Hello,

I'm trying to launch Chrome from Go under windows, some of the arguments 
I'm passing have custom paths in it and it seems that go is sanitizing 
these arguments and not recognizing the paths. Basically it seems to be 
appending the application path into the arguments with a path.

Code is as follows:

package main

import(
"os/exec"
"fmt"
)

func main(){
fmt.Printf("Trying to start Chrome\n")


AppCommand:="C:\\Users\\User\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"
Args:=[]string{" --user-data-dir=\"C:\\ProfileTest 1\"",
" --load-extension=\"C:\\test\"",
" --disk-cache-dir=\"C:\\profileCache\"",
" --disable-preconnect",
" --dns-prefetch-disable",
" --start-maximized",
" --allow-insecure-localhost",
" --ignore-certificate-errors",
" --ignore-certificate-errors-spki-list",
" --no-default-browser-check",
" --disable-infobars"}

cmd := exec.Command(AppCommand,  Args...)
//stdout, err := cmd.Output()
if err := cmd.Start(); err != nil {
fmt.Printf("Start Chrome error %+v\n", err)
continue
}
}

At chrome, we noticed that the load-extension path is being appended with: 
"C:\\Users\\User\\AppData\\Local\\Google\\Chrome\\Application\\" so it ends 
up with: 
"C:\\Users\\User\\AppData\\Local\\Google\\Chrome\\Application\\""C:\\test", 
same goes for the other arguments with a path.

Is there any way to tell go to avoid doing this? Maybe just executing a 
command straight from a command line?

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: Checking IP against CIDR ranges

2018-05-16 Thread XXX ZZZ
Thanks guys, Patricia Tree did the trick

-- 
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] Checking IP against CIDR ranges

2018-05-15 Thread XXX ZZZ
Hello,

I'm trying to check an IP against a list of several CIDR ranges, so far the 
most obvious way to do it seems to parse both the IP and the cidr ranges (
ParseCIDR) and then do a net.contain() however, if we have more than 1 CIDR 
we have to loop checking one by one which imho is incredible unefficient + 
slow if the cidr range is big.

Is there any more efficient way of achieving this? I have thought on making 
a map[string]string with all the IPs (within the CIDR) but the amount of 
required memory for big lists goes up to a few GB.

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: Help with XML parsing

2018-04-03 Thread XXX ZZZ
Thanks a lot for your reply, any particular reason of why "response" should 
be left out? given that is still a parent tag.

As for getting the bid attribute, any idea how to do that? 

El martes, 3 de abril de 2018, 19:29:41 (UTC-3), C Banning escribió:
>
> https://play.golang.org/p/MwpdBwvRnUP
>
> On Tuesday, April 3, 2018 at 2:47:49 PM UTC-6, XXX ZZZ wrote:
>>
>> Hello,
>>
>> I'm trying to parse an XML with golang but I'm having a hard time 
>> creating a parser for the string, in fact I couldn't even get an output 
>> using interface{}.
>>
>> package main
>>
>> import (
>> "fmt"
>> "encoding/xml"
>> )
>>
>>
>> type MMXML_Listing struct {
>> Original_title string `xml:"title"`
>> Original_desc   string `xml:"description"`
>> Original_domain   string `xml:"displayurl"`
>> Original_URL   string `xml:"clickurl"`
>> }
>>
>> type MMXML_HostProperties struct {
>> Tags[]MMXML_Listing`xml:"response>adverts>advert"`
>> }
>> const s = `> results="1" search="806848020741095496" query="whatsapp" country="XX" 
>> platform="zzz" currency="USD" guid="FP.66.66.66.61">> provider="0" bid="1" campaign="1" copy="1" network="1" sector="0" 
>> ecpmi="1000">AdvertTitleAdvertSummaryClickThroughURL
>> http://feed.domain.net/click.ashx?sys=aaae=sBG08dZWyRwhRESxvC6tX6WzJWV8BdmTrS%2bTR5ER3iawNpt8CrWuXiUojalDVLd%2b0mecpq8jjsCmDIKOgWIVyMkLLh4%2f6XAsMfxC535sUJC%2fb2agNsARWsEYXrPgvu%2b9sBPCJWM6YQUuN8PWqP1k8MTFpq0XwVGgGcSs03i6VRu61q9oC6JSVpARh44Sx10YOnY1Clsm24833w3TAYm0QqPDOVLMMKqrQErT0n66okBFchacKl2EhZy64VnpzJI4xJRaL%2bkavtFnsX18b6bPl0PWJadPPz%2fZ%2fe7cpS7U7qiT74wIIPwBNkoxCBLO7xqT4E8t62OSIRpUTgMxYY4Z9REWoGZYBq%2fyox8YGTV509gknMpdzQfY9uBKEj5BZgNmzkzozVelNi0agbsdLEbWhQ%3d%3d
>> StandardText`
>>
>> func main() {
>> r := MMXML_HostProperties {}
>> err := xml.Unmarshal([]byte(s), )
>> if err != nil {
>> panic(err)
>> }
>> fmt.Printf("%+v", r)
>> }
>>
>> playground: https://play.golang.org/p/BbsrKYFPj5-
>>
>> Basically I want to get the elements within "advert" tag, however it 
>> always returns empty. Any ideas why?
>>
>> As for the "bid" attribute within "adverts" tag, what would be the 
>> appropiate approach?
>>
>> Thanks in advance.
>>
>>
>>

-- 
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] Help with XML parsing

2018-04-03 Thread XXX ZZZ
Hello,

I'm trying to parse an XML with golang but I'm having a hard time creating 
a parser for the string, in fact I couldn't even get an output using 
interface{}.

package main

import (
"fmt"
"encoding/xml"
)


type MMXML_Listing struct {
Original_title string `xml:"title"`
Original_desc   string `xml:"description"`
Original_domain   string `xml:"displayurl"`
Original_URL   string `xml:"clickurl"`
}

type MMXML_HostProperties struct {
Tags[]MMXML_Listing`xml:"response>adverts>advert"`
}
const s = `AdvertTitleAdvertSummaryClickThroughURLhttp://feed.domain.net/click.ashx?sys=aaae=sBG08dZWyRwhRESxvC6tX6WzJWV8BdmTrS%2bTR5ER3iawNpt8CrWuXiUojalDVLd%2b0mecpq8jjsCmDIKOgWIVyMkLLh4%2f6XAsMfxC535sUJC%2fb2agNsARWsEYXrPgvu%2b9sBPCJWM6YQUuN8PWqP1k8MTFpq0XwVGgGcSs03i6VRu61q9oC6JSVpARh44Sx10YOnY1Clsm24833w3TAYm0QqPDOVLMMKqrQErT0n66okBFchacKl2EhZy64VnpzJI4xJRaL%2bkavtFnsX18b6bPl0PWJadPPz%2fZ%2fe7cpS7U7qiT74wIIPwBNkoxCBLO7xqT4E8t62OSIRpUTgMxYY4Z9REWoGZYBq%2fyox8YGTV509gknMpdzQfY9uBKEj5BZgNmzkzozVelNi0agbsdLEbWhQ%3d%3dStandardText`

func main() {
r := MMXML_HostProperties {}
err := xml.Unmarshal([]byte(s), )
if err != nil {
panic(err)
}
fmt.Printf("%+v", r)
}

playground: https://play.golang.org/p/BbsrKYFPj5-

Basically I want to get the elements within "advert" tag, however it always 
returns empty. Any ideas why?

As for the "bid" attribute within "adverts" tag, what would be the 
appropiate approach?

Thanks in advance.


-- 
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] Sync pool old data

2017-10-11 Thread XXX ZZZ
Hello,

So I'm starting to play with sync pool on a program that needs to allocate 
a ton of short lived objects per server request. Performance seems to be 
better when using sync pool however I've noticed that upon releasing the 
object and then retrieving it again, will produce a "new object" with "old 
request data". The solution for this would be to reset the object 
values/structs to 0, however I feel this will kinda defeat the purpose of 
using sync pool. After all, we will always be creating new objects. 

Given that sync pool is used to avoid overhead when creating a lot of 
elements, i would assume that I'm missing something here. Could anyone 
please shred some light on this?

package main

import(
"sync"
"fmt"
)
type struct1 struct{
  obj1  struct2
  obj2  struct3
}

type struct2 struct{
   a string
}

type struct3 struct{
  a string
}


func AcquireStruct1() *struct1 {
return struct1pool.Get().(*struct1)
}
func ReleaseStruct1(u *struct1 ) {
//u.Reset()
struct1pool.Put(u)
}
var struct1pool= {
New: func() interface{} {
a:={}
return a
},
}

func main(){
  a:=AcquireStruct1()
  a.obj1.a="a"
  a.obj2.a="a"
  ReleaseStruct1(a)

  a=AcquireStruct1()
  fmt.Printf("%+v", a) // this outputs the data assigned to the first object
}
}

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

Thanks in advance.

-- 
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] when to use Sync pool

2017-10-06 Thread XXX ZZZ
Hello,

So we are making a platform where we have to use a TON of short lived 
structs, in order to optimize this we intend to use sync pool, however on 
our benchmark tests I have found that it only seems to improve performance 
when the struct is big enough, for smaller structs ie: (4-5 string values) 
it seems to be considerably slower, yet I see many packages (such as 
fasthttp) using sync pool for basically everything. Is there anything I am 
missing? Any recommendations of when to use sync pool?

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.