Re: [go-nuts] Re: how do I make my function always run at exit in `go test`?

2019-01-09 Thread Justin Israel
Oh, I see. Well also adding a signal handler for SIGINT/SIGTERM also works
for me:
https://play.golang.org/p/93VmTTgE4YB

Justin


On Thu, Jan 10, 2019 at 6:29 PM 김용빈  wrote:

> Sorry I didn't clarify but I mean when it is killed/terminated.
>
> 2019년 1월 10일 목요일 오후 2시 24분 35초 UTC+9, 김용빈 님의 말:
>
>> I tried signal.Notify but it seems it doesn't work.
>>
>> Then I find this:
>> https://github.com/golang/go/issues/15553#issuecomment-217162874
>>
>> So what should I do to make my function always run at exit in test?
>>
> --
> 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.


Re: [go-nuts] Re: Temporarily allow unused variables

2019-01-09 Thread Jan Mercl
On Thu, Jan 10, 2019 at 6:30 AM Justin Israel 
wrote:

> On Thu, Jan 10, 2019 at 6:04 PM 김용빈  wrote:
>
>> package main
>>
>> func unused(x interface{}) {}
>>
>> func main() {
>> a := 1
>> unused(a)
>> }
>>
>
> The function isn't even required here. Assigning to underscore will
> prevent the error:
>
> func main() {
> a := 1
> _ = a
> }
>

 Both versions above have the same problem - it's possible to forgot the
bypass hack in production code.

For many years I'm using

func use(...interface{}) {}

but defined in tests, for example in all_test.go. This enables easy
disabling of the 'unused variable' error during development/debugging, but
the code does not otherwise compile until the 'use(foo, bar') hack is
removed or commented out.

-- 

-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] Re: Temporarily allow unused variables

2019-01-09 Thread Justin Israel
On Thu, Jan 10, 2019 at 6:04 PM 김용빈  wrote:

> package main
>
> func unused(x interface{}) {}
>
> func main() {
> a := 1
> unused(a)
> }
>

The function isn't even required here. Assigning to underscore will prevent
the error:

func main() {
a := 1
_ = a
}


>
> 2012년 3월 7일 수요일 오후 8시 32분 19초 UTC+9, Elazar Leibovich 님의 말:
>
>> I sometimes have a very strange error, which I can't understand its
>> source.
>>
>> One of my techniques for finding it, is isolate the problem to a very
>> small case, by commenting out pieces of the code, and noticing which pieces
>> of codes cause the problem.
>>
>> Go really helps me with it due to the short compile run cycles, but it is
>> very difficult to use this technique without leaving unused variables.
>>
>> Is there a flag that enables you to temporarily compile without this
>> warning?
>>
> --
> 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: how do I make my function always run at exit in `go test`?

2019-01-09 Thread 김용빈
Sorry I didn't clarify but I mean when it is killed/terminated.

2019년 1월 10일 목요일 오후 2시 24분 35초 UTC+9, 김용빈 님의 말:
>
> I tried signal.Notify but it seems it doesn't work.
>
> Then I find this: 
> https://github.com/golang/go/issues/15553#issuecomment-217162874
>
> So what should I do to make my function always run at exit in test?
>

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


Re: [go-nuts] how do I make my function always run at exit in `go test`?

2019-01-09 Thread Justin Israel
On Thu, Jan 10, 2019 at 6:24 PM 김용빈  wrote:

> I tried signal.Notify but it seems it doesn't work.
>
> Then I find this:
> https://github.com/golang/go/issues/15553#issuecomment-217162874
>
> So what should I do to make my function always run at exit in test?
>

A custom TestMain() is a good way to add setup and teardown functionality
around the entire test process:
https://golang.org/pkg/testing/#hdr-Main

It won't help you if you kill the "go test" process though. In that case
you would need a SIGTERM handler via signal.Notify()

> --
> 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] how do I make my function always run at exit in `go test`?

2019-01-09 Thread 김용빈
I tried signal.Notify but it seems it doesn't work.

Then I find this: 
https://github.com/golang/go/issues/15553#issuecomment-217162874

So what should I do to make my function always run at exit in test?

-- 
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: Temporarily allow unused variables

2019-01-09 Thread 김용빈
package main

func unused(x interface{}) {}

func main() {
a := 1
unused(a)
}

2012년 3월 7일 수요일 오후 8시 32분 19초 UTC+9, Elazar Leibovich 님의 말:
>
> I sometimes have a very strange error, which I can't understand its source.
>
> One of my techniques for finding it, is isolate the problem to a very 
> small case, by commenting out pieces of the code, and noticing which pieces 
> of codes cause the problem.
>
> Go really helps me with it due to the short compile run cycles, but it is 
> very difficult to use this technique without leaving unused variables.
>
> Is there a flag that enables you to temporarily compile without this 
> warning?
>

-- 
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: Temporarily allow unused variables

2019-01-09 Thread robert engels
I’m pretty sure that is rose colored glasses…

It is a pain, but at the same time, the lack of dynamic code modification is 
more of a pain, coupled with no private methods in file scope (because with 
those you could decompose the larger functions without polluting the namespace).

But in many ways, the inability to test/debug “interactively” does force you 
down the road to better design - but when you are debugging someone else’s code 
that’s a whole other issue...

Test cases mitigate the problem immensely.

> On Jan 9, 2019, at 9:49 PM, Ekow  wrote:
> 
> It is a good kind of pain. 
> 
> This intentional construct forces you to only use what you need at the point 
> where you actually need it. 
> 
> YAGNI.
> 
> Regards,
> B Charles Jnr.
> 
> On Jan 9, 2019, at 8:17 PM, Rich mailto:rma...@gmail.com>> 
> wrote:
> 
>> Yes at times it's a pain, after programming for a while in Go you just get 
>> used to it, and I seldom run into an unused variable. Use Visual Studio 
>> Code, you'll get a red squiggly line and an error long before you ever try 
>> to compile the code. If you really want to keep the variable, variable=_ 
>> takes care of it. 
>> 
>> On Wednesday, January 9, 2019 at 5:01:52 PM UTC-5, Ian Lance Taylor wrote:
>> On Wed, Jan 9, 2019 at 1:46 PM > wrote: 
>> > 
>> > So, 2019 year. Still no compiler flag. Slphers :) 
>> 
>> This isn't a matter of being slow, it's an intentional decision. 
>> 
>> 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 
>> .
> 
> 
> -- 
> 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.


Re: [go-nuts] Re: Temporarily allow unused variables

2019-01-09 Thread Ekow
It is a good kind of pain. 

This intentional construct forces you to only use what you need at the point 
where you actually need it. 

YAGNI.

Regards,
B Charles Jnr.

> On Jan 9, 2019, at 8:17 PM, Rich  wrote:
> 
> Yes at times it's a pain, after programming for a while in Go you just get 
> used to it, and I seldom run into an unused variable. Use Visual Studio Code, 
> you'll get a red squiggly line and an error long before you ever try to 
> compile the code. If you really want to keep the variable, variable=_ takes 
> care of it. 
> 
>> On Wednesday, January 9, 2019 at 5:01:52 PM UTC-5, Ian Lance Taylor wrote:
>> On Wed, Jan 9, 2019 at 1:46 PM  wrote: 
>> > 
>> > So, 2019 year. Still no compiler flag. Slphers :) 
>> 
>> This isn't a matter of being slow, it's an intentional decision. 
>> 
>> 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.

-- 
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: Temporarily allow unused variables

2019-01-09 Thread Rich
Yes at times it's a pain, after programming for a while in Go you just get 
used to it, and I seldom run into an unused variable. Use Visual Studio 
Code, you'll get a red squiggly line and an error long before you ever try 
to compile the code. If you really want to keep the variable, variable=_ 
takes care of it. 

On Wednesday, January 9, 2019 at 5:01:52 PM UTC-5, Ian Lance Taylor wrote:
>
> On Wed, Jan 9, 2019 at 1:46 PM > wrote: 
> > 
> > So, 2019 year. Still no compiler flag. Slphers :) 
>
> This isn't a matter of being slow, it's an intentional decision. 
>
> 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.


Re: [go-nuts] Re: Temporarily allow unused variables

2019-01-09 Thread Glen Newton
I use the "if false{..." extensively as described above.

-- 
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] Code coverage for a project

2019-01-09 Thread alex . besogonov
I actually have a similar request. I have an application that I want to 
test with integration tests and right now there's no real way to get 
coverage except by running everything using a unit test launcher.

On Wednesday, January 9, 2019 at 6:22:23 AM UTC-8, Ian Lance Taylor wrote:
>
> On Tue, Jan 8, 2019 at 11:52 PM > 
> wrote: 
> > 
> > I have creates all my test files in a separate single folder. Is it 
> possible to get code coverage as the source files are in different location 
> not with test files. 
> > I am getting code coverage report with coverprofile when  test files and 
> source are in same location. 
> > 
> > Here I was running all the test files with  a make file for sequential 
> execution of test files as I have some dependency from one file to another 
> file. 
>
> Tell us exactly what you did, tell us exactly what happened, and tell 
> us what you expected to happen instead. 
>
> I'm not sure but perhaps you want to use the -coverpkg option to go test. 
>
> 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.


Re: [go-nuts] Re: Temporarily allow unused variables

2019-01-09 Thread Ian Lance Taylor
On Wed, Jan 9, 2019 at 1:46 PM  wrote:
>
> So, 2019 year. Still no compiler flag. Slphers :)

This isn't a matter of being slow, it's an intentional decision.

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] Re: Temporarily allow unused variables

2019-01-09 Thread xenginex
So, 2019 year. Still no compiler flag. Slphers :)

среда, 7 марта 2012 г., 14:32:19 UTC+3 пользователь Elazar Leibovich 
написал:
>
> I sometimes have a very strange error, which I can't understand its source.
>
> One of my techniques for finding it, is isolate the problem to a very 
> small case, by commenting out pieces of the code, and noticing which pieces 
> of codes cause the problem.
>
> Go really helps me with it due to the short compile run cycles, but it is 
> very difficult to use this technique without leaving unused variables.
>
> Is there a flag that enables you to temporarily compile without this 
> warning?
>

-- 
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] Can I say that a pointer is a memory address where a variable is?

2019-01-09 Thread robert engels
I think this show move to r/programming

> On Jan 9, 2019, at 12:55 PM, Justin Israel  wrote:
> 
> 
> 
> On Thu, Jan 10, 2019, 7:53 AM Justin Israel  > wrote:
> 
> 
> On Thu, Jan 10, 2019, 7:43 AM 伊藤和也  > wrote:
> Can I say that a pointer is a memory address where a variable is?
> 
> A pointer is a memory address to a value (data in memory). 
> 
> A "variable" is just a name/label to *something*. That something could be a 
> pointer or it could be a value. That is, you can have a pointer that points 
> to the value of another pointer which points to the value of an int in memory 
> (**x) 
> 
> And I just now saw this was double posted. I don't want to fork two 
> conversations ;) 
> 
> 
> 
> 
> -- 
> 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 
> .

-- 
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] Can I say that a pointer is a memory address where a variable is?

2019-01-09 Thread Justin Israel
On Thu, Jan 10, 2019, 7:53 AM Justin Israel  wrote:

>
>
> On Thu, Jan 10, 2019, 7:43 AM 伊藤和也  wrote:
>
>> Can I say that a pointer is a memory address where a variable is?
>>
>
> A pointer is a memory address to a value (data in memory).
>
> A "variable" is just a name/label to *something*. That something could be
> a pointer or it could be a value. That is, you can have a pointer that
> points to the value of another pointer which points to the value of an int
> in memory (**x)
>

And I just now saw this was double posted. I don't want to fork two
conversations ;)


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


Re: [go-nuts] Re: Wuffs: a new, memory-safe programming language

2019-01-09 Thread 'Thomas Bushnell, BSG' via golang-nuts
On Wed, Jan 9, 2019 at 10:07 AM Eric S. Raymond  wrote:

> > Reasonable people can disagree, but I favor rewriting over
> > transpilation, for draining that swamp.
>
> The problem is that in general nobody *does* rewrite old
> infrastructure code.  It tends to work just well enough to fester in
> place for a long time, and then you get shocks like the Heartbleed
> bug.  It is my aim to head off that sort of thing in the future.
>

I'm curious about why transpilation would have significantly mitigated the
Heartbleed bug.

It sounds as though the idea is a mass transpilation of old libraries, but
that's going to require more than just a library. Suppose openssl had been
transpiled into Go well in advance of the attack. This isn't going to stop
old C code from linking against the old library, and it's all going to stay
there. So you'd need to transpile all the programs which use the library
too, it seems to me, and release them into all the distros, and have them
all agree. That seems a rather high hurdle. You could, of course, just
release a transpiled version of a bunch of libraries, but now my guess is
there's two things to maintain instead of one, and nothing ever makes the
old one go away.

But suppose that hurdle is fixed, and think about the specific Heartbleed
bug. The bug involved a mistake in unmarshalling a particular type of SSL
packet, trusting a length field from an inbound packet; the fix was to see
the length and discard the incoming packet if it was bogusly long.

The specific problem was that if the length field was bogusly big, the code
would do the echo reply with the next N bytes after the incoming packet in
memory, which could include whatever was in memory after the packet.

The transpiler is going to be amazing clever to even get this code right.
It's code which bounces around *char manually unmarshalling a piece of
structured data. Consider this: hbtype = *p++.

What's that going to be? Is it going to be turned into pointer arithmetic
using the unsafe package? Now you'll just get the same bug again. Obviously
new Go code would stick the packet in a []byte, and then use the facilities
of the binary package to read the bits, and the attempt to read past the
end of the slice will fail. But how is a transpiler going to automatically
take the C code of openssl and do that?

Suppose it has a way, however. Now you have Go code which will have a
bounds fault instead of a data leak. That's better, I suppose - the
resulting bug is now "the server crashes" instead of "the server maybe
leaks a key". This is an improvement, but a packet-of-death across a widely
used library this puts the world in a not dissimilar position in terms of
the level of panic and rapid response everybody needs.

So I'm not quite seeing it. It seems like a great idea from the outside
("hey, we could turn all these programs into memory-safe Go programs,
automatically, what a win!") but in practice, I'm not sure I see such a
transpiler actually working in a way that would achieve the result - and
the end is to preserve a profound denial of service attack anyway.

Thomas

-- 

memegen delenda est

-- 
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] Can I say that a pointer is a memory address where a variable is?

2019-01-09 Thread Justin Israel
On Thu, Jan 10, 2019, 7:43 AM 伊藤和也  wrote:

> Can I say that a pointer is a memory address where a variable is?
>

A pointer is a memory address to a value (data in memory).

A "variable" is just a name/label to *something*. That something could be a
pointer or it could be a value. That is, you can have a pointer that points
to the value of another pointer which points to the value of an int in
memory (**x)


> --
> 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: Get data from url insert to mongo but can't insert json array

2019-01-09 Thread pdbw58107


expect result:

[

{

"contentData":"1 \u0e21\u0e01\u0e23\u0e32\u0e04\u0e21 ",

"historyData":" 
\u0e27\u0e31\u0e19\u0e02\u0e36\u0e49\u0e19\u0e1b\u0e35\u0e43\u0e2b\u0e21\u0e48\u00a0
 
\u0e27\u0e31\u0e19\u0e2b\u0e22\u0e38\u0e14\u0e23\u0e32\u0e0a\u0e01\u0e32\u0e23",

"id":1

},

{"contentData":"\u0e27\u0e31\u0e19\u0e40\u0e2a\u0e32\u0e23\u0e4c\u0e17\u0e35\u0e48
 2 
\u0e02\u0e2d\u0e07\u0e40\u0e14\u0e37\u0e2d\u0e19\u0e21\u0e01\u0e23\u0e32\u0e04\u0e21
 ",

"historyData":" 
\u0e27\u0e31\u0e19\u0e40\u0e14\u0e47\u0e01\u0e41\u0e2b\u0e48\u0e07\u0e0a\u0e32\u0e15\u0e34","id":2}

]


เมื่อ วันพฤหัสบดีที่ 10 มกราคม ค.ศ. 2019 1 นาฬิกา 30 นาที 19 วินาที UTC+7, 
pdbw...@gmail.com เขียนว่า:
>
> package main
>
> import (
>   "log"
>   "net/http"
>   "time"
>
>   "github.com/PuerkitoBio/goquery"
>   "gopkg.in/mgo.v2"
>   //"gopkg.in/mgo.v2"
> )
>
> type Data struct {
>   Name string `json:"name" bson:"name"`
> Away string `json:"away" bson:"away"`
> Pop int `json:"pop" bson:"pop"`
>   CreatedAt time.Time `bson:"createdAt"`
> }
>
> func ExampleScrape() {
>   // Request the HTML page.
>   session, err := mgo.Dial("mongodb://127.0.0.1:27017")
>   res, err := http.Get("
> https://www.edtguide.com/place/%E0%B8%AB%E0%B8%A1%E0%B8%A7%E0%B8%94%E0%B9%82%E0%B8%A3%E0%B8%87%E0%B8%9E%E0%B8%A2%E0%B8%B2%E0%B8%9A%E0%B8%B2%E0%B8%A5/%E0%B8%AA%E0%B8%A1%E0%B8%B8%E0%B8%97%E0%B8%A3%E0%B8%9B%E0%B8%A3%E0%B8%B2%E0%B8%81%E0%B8%B2%E0%B8%A3/view/P0
> ")
>   if err != nil {
> log.Fatal(err)
>   }
>   defer res.Body.Close()
>   if res.StatusCode != 200 {
> log.Fatalf("status code error: %d %s", res.StatusCode, res.Status)
>   }
>
>   // Load the HTML document
>   doc, err := goquery.NewDocumentFromReader(res.Body)
>   if err != nil {
> log.Fatal(err)
>   }
>
>   // Find the review items
>   doc.Find(".archive-list article ").Each(func(i int, s 
> *goquery.Selection) {
> // For each item found, get the band and title
> band := s.Find("p").Text()
>
> title := s.Find("h2").Text()
> log.Printf("Review %d: %s - %s\n", i, band, title)
> session.SetMode(mgo.Monotonic, true)
> d := session.DB("api").C("api")
>
> doc := Data{
>   Name: title,
> Away: band,
> Pop: 1000,
> }
>
> err = d.Insert(doc)
>
> if err != nil {
>   panic(err)
> }
>
>   })
>
> }
>
> func main() {
>   ExampleScrape()
>
> }
>
>

-- 
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] Can I say that a pointer is a memory address where a variable is?

2019-01-09 Thread 伊藤和也
Can I say that a pointer is a memory address where a variable is?

-- 
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] Get data from url insert to mongo but can't insert json array

2019-01-09 Thread pdbw58107
package main

import (
  "log"
  "net/http"
  "time"

  "github.com/PuerkitoBio/goquery"
  "gopkg.in/mgo.v2"
  //"gopkg.in/mgo.v2"
)

type Data struct {
  Name string `json:"name" bson:"name"`
Away string `json:"away" bson:"away"`
Pop int `json:"pop" bson:"pop"`
  CreatedAt time.Time `bson:"createdAt"`
}

func ExampleScrape() {
  // Request the HTML page.
  session, err := mgo.Dial("mongodb://127.0.0.1:27017")
  res, err := http.Get(
"https://www.edtguide.com/place/%E0%B8%AB%E0%B8%A1%E0%B8%A7%E0%B8%94%E0%B9%82%E0%B8%A3%E0%B8%87%E0%B8%9E%E0%B8%A2%E0%B8%B2%E0%B8%9A%E0%B8%B2%E0%B8%A5/%E0%B8%AA%E0%B8%A1%E0%B8%B8%E0%B8%97%E0%B8%A3%E0%B8%9B%E0%B8%A3%E0%B8%B2%E0%B8%81%E0%B8%B2%E0%B8%A3/view/P0;
)
  if err != nil {
log.Fatal(err)
  }
  defer res.Body.Close()
  if res.StatusCode != 200 {
log.Fatalf("status code error: %d %s", res.StatusCode, res.Status)
  }

  // Load the HTML document
  doc, err := goquery.NewDocumentFromReader(res.Body)
  if err != nil {
log.Fatal(err)
  }

  // Find the review items
  doc.Find(".archive-list article ").Each(func(i int, s *goquery.Selection) 
{
// For each item found, get the band and title
band := s.Find("p").Text()

title := s.Find("h2").Text()
log.Printf("Review %d: %s - %s\n", i, band, title)
session.SetMode(mgo.Monotonic, true)
d := session.DB("api").C("api")

doc := Data{
  Name: title,
Away: band,
Pop: 1000,
}

err = d.Insert(doc)

if err != nil {
  panic(err)
}

  })

}

func main() {
  ExampleScrape()

}

-- 
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: Wuffs: a new, memory-safe programming language

2019-01-09 Thread Eric S. Raymond
Nigel Tao :
> Spun out of the "C++ 11 to Golang convertor" thread...
> 
> 
> On Mon, Jan 7, 2019 at 12:27 AM Eric S. Raymond  wrote:
> > Perry and I have two different target languages in mind.  Perry's
> > target language is basically a repaired C - type-safe, almost
> > upward-compatible. He and I have the same strategic goal - draining
> > the swamp of old, leaky C code - we're just betting on slightly
> > different ways to do it. We intend to cooperate as much as possible.
> 
> This is drifting quite off-topic, but I would expect transpiling C to
> Go would result in something slower than the original, especially if
> it involves a lot of low-level, slice-of-bytes processing. Faster is
> obviously easier to sell than slower.

I agree.  The class of old C program I am interested in is, however,
not generally limited by CPU but by network and (less commonly) disk
stalls.  Again bear in mind that my type examples are NTP and DNS service.
A lot of other legacy infrastructure code fits this pattern.

> Go is memory-safe, but that entails e.g. runtime bounds checking. Any
> individual bounds check might be cheap, measured in nanos, but for
> e.g. image decoding, a per pixel bounds check multiplied by a
> megapixel image (a 'low-res' photo, by today's standards) means that
> nanos become millis.

Again agreed.  Transpilation to Go is only appropriate for cases where
nanos becoming millis doesn't matter. Typically, old infrastructure code
was designed for platforms now enough Dennard-scaling cycles in the past
that Go on current hardware will run faster than C did originally.

> Reasonable people can disagree, but I favor rewriting over
> transpilation, for draining that swamp.

The problem is that in general nobody *does* rewrite old
infrastructure code.  It tends to work just well enough to fester in
place for a long time, and then you get shocks like the Heartbleed
bug.  It is my aim to head off that sort of thing in the future.

> https://github.com/google/wuffs is a new, memory-safe programming
> language and a written-from-scratch library of various file formats.
> Runtime performance is a special concern: there are no implicit
> (runtime) bounds checks. Unlike Go, bounds checks have to be explicit,
> which means that programs can eliminate them from the object code by,
> well, eliminating them from the source code.

That is an interesting and clever approach.

I think all three approaches should be in the toolkit.  They fit different
use cases.
-- 
http://www.catb.org/~esr/;>Eric S. Raymond

My work is funded by the Internet Civil Engineering Institute: https://icei.org
Please visit their site and donate: the civilization you save might be your own.


-- 
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] Can I say that a pointer is a reference or memory address to a value?

2019-01-09 Thread Ian Denhardt
Possibly it's misleading if you're coming from C++ -- but if that's the
case you probably already know what pointers are. It's compatible with
how I've heard the term "reference" used in every other context. The
fact that they are first class values is an important point, however.

-Ian

Quoting Wagner Riffel (2019-01-09 11:31:44)
> i think the term reference is misleading, pointers holds a memory
> address, but they are variables, have their own space in memory.
> var i int
> var p1, p2 = , 
> fmt.Printf("%p, %p, %p", , , ) // 0x1000, 0x1004, 0x1008
>
> while in c++ references variables for example, address are shared for
> referenced and reference.
> int i;
> int =i, =i;
> printf("%p, %p, %p", , , ); // 0x1000, 0x1000, 0x1000
>
> probably "memory address to a value" fits better for pointers.
>
> On Wed, Jan 9, 2019 at 12:44 PM Ian Lance Taylor  wrote:
> >
> > On Tue, Jan 8, 2019 at 9:46 PM 伊藤和也  wrote:
> > >
> > > Can I say that a pointer is a reference or memory address to a value?
> >
> > Sure.
> >
> > 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.
>
> --
> 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.


Re: [go-nuts] Can I say that a pointer is a reference or memory address to a value?

2019-01-09 Thread Wagner Riffel
i think the term reference is misleading, pointers holds a memory
address, but they are variables, have their own space in memory.
var i int
var p1, p2 = , 
fmt.Printf("%p, %p, %p", , , ) // 0x1000, 0x1004, 0x1008

while in c++ references variables for example, address are shared for
referenced and reference.
int i;
int =i, =i;
printf("%p, %p, %p", , , ); // 0x1000, 0x1000, 0x1000

probably "memory address to a value" fits better for pointers.

On Wed, Jan 9, 2019 at 12:44 PM Ian Lance Taylor  wrote:
>
> On Tue, Jan 8, 2019 at 9:46 PM 伊藤和也  wrote:
> >
> > Can I say that a pointer is a reference or memory address to a value?
>
> Sure.
>
> 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.

-- 
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] Can I say that a pointer is a reference or memory address to a value?

2019-01-09 Thread Ian Lance Taylor
On Tue, Jan 8, 2019 at 9:46 PM 伊藤和也  wrote:
>
> Can I say that a pointer is a reference or memory address to a value?

Sure.

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] Re: How to insert to mongodb in json{[]}

2019-01-09 Thread pdbw58107
I don't know get Title insert to mongo if it is solution your
Full code :
package main

import (
"fmt"
"log"
"net/http"
"gopkg.in/mgo.v2"
"github.com/PuerkitoBio/goquery"
"time"

)
type Data struct{
  Name string ` bson:"name"`
Away string ` bson:"away"`
CreatedAt time.Time `bson:"createdAt"`
}
func ExampleScrape() {
// Request the HTML page.
  session, err := mgo.Dial("mongodb://127.0.0.1:27017")
res, err := http.Get(
"https://www.edtguide.com/place/%E0%B8%AB%E0%B8%A1%E0%B8%A7%E0%B8%94%E0%B9%82%E0%B8%A3%E0%B8%87%E0%B8%9E%E0%B8%A2%E0%B8%B2%E0%B8%9A%E0%B8%B2%E0%B8%A5/%E0%B8%AA%E0%B8%A1%E0%B8%B8%E0%B8%97%E0%B8%A3%E0%B8%9B%E0%B8%A3%E0%B8%B2%E0%B8%81%E0%B8%B2%E0%B8%A3/view/P0;
)
if err != nil {
log.Fatal(err)
}
defer res.Body.Close()
if res.StatusCode != 200 {
log.Fatalf("status code error: %d %s", res.StatusCode, res.Status)
}

// Load the HTML document
doc, err := goquery.NewDocumentFromReader(res.Body)
if err != nil {
log.Fatal(err)
}

// Find the review items
doc.Find(".archive-list article ").Each(func(i int, s *goquery.Selection) {
// For each item found, get the band and title
band := s.Find("p").Text()

title := s.Find("h2").Text()
fmt.Printf("Review %d: %s - %s\n", i,band, title)
// var data []Data
session.SetMode(mgo.Monotonic, true)

d:= session.DB("api").C("api")
  doc := Data{
Name: title,
Away: band,
  }
  err = d.Insert(doc)
if err != nil {
  panic(err)
}
})
}


func main() {
ExampleScrape()

}
เมื่อ วันพุธที่ 9 มกราคม ค.ศ. 2019 18 นาฬิกา 21 นาที 01 วินาที UTC+7, 
Mahendra Bhoir เขียนว่า:
>
> Hi,
> This code works for me.
> You need to pass referance instead of actual variable.
>
> //here mongo is my package where function MongoConnect() creates a globle 
> session and returns clone of session.
>
> func addTempCategory(category MainCategory) {
> mongoSession = mongo.MongoConnect()
> defer mongoSession.Close()
> c := mongo.MongoSession.DB("testDB").C("testCategories")
>
> err := c.Insert()
> if err != nil {
> log.Fatal(err)
> }
> }
>
> And struct for category
>
> type MainCategory struct {
> Category   string `bson:"category" json:"category"`
> CategoryID string `bson:"categoryId" json:"categoryId"`
> CategoryName   string `bson:"categoryName" json:"categoryName"`
> HaveAttributes int`bson:"haveAttributes" json:"haveAttributes"`
> HaveSubCatsint`bson:"haveSubCats" json:"haveSubCats"`
> ImageIcon  string `bson:"imageIcon" json:"imageIcon"`
> }
>
> On Wednesday, January 9, 2019 at 4:29:39 PM UTC+5:30, pdbw...@gmail.com 
> wrote:
>>
>> My code:
>> session.SetMode(mgo.Monotonic, true)
>> d:= session.DB("api").C("api")
>>   doc := Data{
>>   Name: title,
>>   Away: band,
>>   }
>>   err = d.Insert(doc)
>> json to expect
>> [
>>   {
>> "contentData": "",
>> "historyData": " ",
>>   
>>   },
>>  {
>>  },
>> ]
>>
>

-- 
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] Code coverage for a project

2019-01-09 Thread Ian Lance Taylor
On Tue, Jan 8, 2019 at 11:52 PM  wrote:
>
> I have creates all my test files in a separate single folder. Is it possible 
> to get code coverage as the source files are in different location not with 
> test files.
> I am getting code coverage report with coverprofile when  test files and 
> source are in same location.
>
> Here I was running all the test files with  a make file for sequential 
> execution of test files as I have some dependency from one file to another 
> file.

Tell us exactly what you did, tell us exactly what happened, and tell
us what you expected to happen instead.

I'm not sure but perhaps you want to use the -coverpkg option to go test.

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] Re: How to insert to mongodb in json{[]}

2019-01-09 Thread Mahendra Bhoir
Hi,
This code works for me.
You need to pass referance instead of actual variable.

//here mongo is my package where function MongoConnect() creates a globle 
session and returns clone of session.

func addTempCategory(category MainCategory) {
mongoSession = mongo.MongoConnect()
defer mongoSession.Close()
c := mongo.MongoSession.DB("testDB").C("testCategories")

err := c.Insert()
if err != nil {
log.Fatal(err)
}
}

And struct for category

type MainCategory struct {
Category   string `bson:"category" json:"category"`
CategoryID string `bson:"categoryId" json:"categoryId"`
CategoryName   string `bson:"categoryName" json:"categoryName"`
HaveAttributes int`bson:"haveAttributes" json:"haveAttributes"`
HaveSubCatsint`bson:"haveSubCats" json:"haveSubCats"`
ImageIcon  string `bson:"imageIcon" json:"imageIcon"`
}

On Wednesday, January 9, 2019 at 4:29:39 PM UTC+5:30, pdbw...@gmail.com 
wrote:
>
> My code:
> session.SetMode(mgo.Monotonic, true)
> d:= session.DB("api").C("api")
>   doc := Data{
>   Name: title,
>   Away: band,
>   }
>   err = d.Insert(doc)
> json to expect
> [
>   {
> "contentData": "",
> "historyData": " ",
>   
>   },
>  {
>  },
> ]
>

-- 
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 insert to mongodb in json{[]}

2019-01-09 Thread pdbw58107
My code:
session.SetMode(mgo.Monotonic, true)
d:= session.DB("api").C("api")
  doc := Data{
  Name: title,
  Away: band,
  }
  err = d.Insert(doc)
json to expect
[
  {
"contentData": "",
"historyData": " ",
  
  },
 {
 },
]

-- 
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: Patch method

2019-01-09 Thread Amnon Baron Cohen
try https://golang.org/pkg/net/http/ 
and https://golang.org/pkg/encoding/json/

On Tuesday, 8 January 2019 14:24:37 UTC, afriyie...@gmail.com wrote:
>
> Hi,
>
> Am new in Go programming and need help to write a PATCH method for my 
> go-server.
> my data field look like these
>
> type NFProfile struct {
> NFType   string `json:"nftype"`
> NFInstanceID string `json:"instanceid"`
> NFStatus string `json:"nfstatus"`
> ID   string `json:"id"`
> }
>
> //Create NFProfile DB
> type NFProfileDB struct {
> nfprofiles map[string]NFProfile
> }
>
> Can anyone tell me what to and if there is any library to do this such 
> that i can use poastman to send PATCH request
> to the server.
>
> Thanks in advance
> Abraham
>

-- 
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] Web Scraping.result not show that expect result are Stone Age ,Roman Britain

2019-01-09 Thread Wojciech S. Czarnecki
On Wed, 9 Jan 2019 00:50:04 -0800 (PST)
pdbw58...@gmail.com wrote:

> I want to get data from html
https://godoc.org/golang.org/x/net/html
https://schier.co/blog/2015/04/26/a-simple-web-scraper-in-go.html

> insert to database
https://flaviocopes.com/golang-sql-database/

Hope this helps.

-- 
Wojciech S. Czarnecki
 << ^oo^ >> OHIR-RIPE

-- 
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] Web Scraping.result not show that expect result are Stone Age ,Roman Britain

2019-01-09 Thread pdbw58107
I want to get data from html insert to database for data to want are stone 
cold
Contents


https://en.wikipedia.org/wiki/History_of_England#Prehistory>">1 Prehistory

https://en.wikipedia.org/wiki/History_of_England#Stone_Age>">1.1 Stone Age
https://en.wikipedia.org/wiki/History_of_England#Later_Prehistory>">1.2 Later Prehistory

https://en.wikipedia.org/wiki/History_of_England#Genetic_history_of_the_English>
">1.3 Genetic history 
of the English


https://en.wikipedia.org/wiki/History_of_England#Roman_Britain>">2 Roman Britain

https://en.wikipedia.org/wiki/History_of_England#The_Anglo-Saxon_migration>
">3 The Anglo-Saxon 
migration
https://en.wikipedia.org/wiki/History_of_England#Heptarchy_and_Christianisation>
">4 Heptarchy and 
Christianisation
https://en.wikipedia.org/wiki/History_of_England#Viking_challenge_and_the_rise_of_Wessex>
">5 Viking challenge 
and the rise of Wessex
https://en.wikipedia.org/wiki/History_of_England#English_unification>">6 English unification

https://en.wikipedia.org/wiki/History_of_England#England_under_the_Danes_and_the_Norman_conquest>
">7 England under the 
Danes and the Norman conquest
https://en.wikipedia.org/wiki/History_of_England#Norman_England>">8 Norman England

https://en.wikipedia.org/wiki/History_of_England#England_under_the_Plantagenets>
">9 England under the 
Plantagenets

https://en.wikipedia.org/wiki/History_of_England#Magna_Carta>">9.1 Magna Carta
https://en.wikipedia.org/wiki/History_of_England#Henry_III>">9.2 Henry III


https://en.wikipedia.org/wiki/History_of_England#14th_century>">10 14th century

https://en.wikipedia.org/wiki/History_of_England#Black_Death>">10.1 Black Death


https://en.wikipedia.org/wiki/History_of_England#15th_century_%E2%80%93_Henry_V_and_the_Wars_of_the_Roses>
">11 15th century 
 Henry V and the Wars of the Roses
https://en.wikipedia.org/wiki/History_of_England#Tudor_England>">12 Tudor England

เมื่อ วันพุธที่ 9 มกราคม ค.ศ. 2019 15 นาฬิกา 44 นาที 47 วินาที UTC+7, ohir 
เขียนว่า:
>
> On Tue, 8 Jan 2019 21:05:00 -0800 (PST) 
> pdbw...@gmail.com  attached a screenshot: 
>
> https://www.google.com/search?q=how+to+copy+and+paste+text 
>
> > [image: Screen Shot 2019-01-09 at 12.03.04 PM.png] 
>
> -- 
> Wojciech S. Czarnecki 
>  << ^oo^ >> OHIR-RIPE 
>

-- 
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] Web Scraping.result not show that expect result are Stone Age ,Roman Britain

2019-01-09 Thread Wojciech S. Czarnecki
On Tue, 8 Jan 2019 21:05:00 -0800 (PST)
pdbw58...@gmail.com attached a screenshot:

https://www.google.com/search?q=how+to+copy+and+paste+text

> [image: Screen Shot 2019-01-09 at 12.03.04 PM.png]

-- 
Wojciech S. Czarnecki
 << ^oo^ >> OHIR-RIPE

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