[go-nuts] Re: The GO equiv. to 'tail -f' ?

2021-02-20 Thread Steve Murphy

Many, many thanks. The hpcloud/tail hit the spot exactly, along with using 
timer.AfterFunc() along with judicious use of .Stop() calls to 
turn on and off
audible alarms. That was just the help I needed! again, Many thanks!

murf 

On Thursday, February 18, 2021 at 12:02:46 PM UTC-7 Amnon wrote:

> What to do depends on the platform.
> But there are quite a few examples around.
>
> https://github.com/hpcloud/tail
> https://github.com/papertrail/go-tail
>
> https://stackoverflow.com/questions/10135738/reading-log-files-as-theyre-updated-in-go
>
> etc...
>
> On Thursday, 18 February 2021 at 18:50:43 UTC Steve Murphy wrote:
>
>> I'm having a hard time finding some tools in GO to follow log files and 
>> make real-time commentary about stuff like alerting about outages now 
>> underway, and  making alerts over things that *should* happen by now but 
>> weren't, and such-like.
>>
>> Any advice? I'm pretty sure I saw an article or two some months ago, but 
>> now nothing shows up in my search engine.
>>
>> Many thanks
>>
>> murf
>>
>> -- 
>>
>> Steve Murphy
>> ParseTree Corporation
>>
>>

-- 
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/780cb75d-8b1c-48b4-bf56-84362aa1cf94n%40googlegroups.com.


[go-nuts] The GO equiv. to 'tail -f' ?

2021-02-18 Thread Steve Murphy
I'm having a hard time finding some tools in GO to follow log files and
make real-time commentary about stuff like alerting about outages now
underway, and  making alerts over things that *should* happen by now but
weren't, and such-like.

Any advice? I'm pretty sure I saw an article or two some months ago, but
now nothing shows up in my search engine.

Many thanks

murf

-- 

Steve Murphy
ParseTree Corporation

-- 
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/CAPPCp8EiGNG7ZtpgzQKX1nq436wrtv9EHx0RJDqOFd0huOrvHw%40mail.gmail.com.


Re: [go-nuts] A value saved in an interface{} field in a struct not usable in func with interace{} arg

2021-01-12 Thread Steve Murphy
Ian--

You missed the part about the arguments being "shifted left" above, which 
kinda looks like a compiler issue. Maybe something I wrote contributed to 
the problem, but I have no idea what.
If this is a known problem, perhaps I can hand-install aa newer version, or 
something...?

murf

On Tuesday, January 12, 2021 at 7:52:40 AM UTC-7 Ian Davis wrote:

> Note the error says that val was nil, so your type assertion will panic. 
> You can read more about how to make type assertions that report success or 
> failure in the Go Tour: https://tour.golang.org/methods/15
>
> Have you tried printing the type of what you receive before attempting the 
> type assertion? I suspect that the system you are working with is passing 
> you a variety of different types depending on the context, so you'll need 
> to be flexible in what you handle.
>
>
>
>
>
> On Tue, 12 Jan 2021, at 5:55 AM, Steve Murphy wrote:
>
> Many thanks, Ian, I appreciate your suggestions!
>
> I added your code snippet to my program, and got:
>
> panic: interface conversion: interface {} is nil, not *interface {} 
> [recovered]
> panic: interface conversion: interface {} is nil, not *interface {}
>
> According to the trace, it looks like it's crashing while trying to 
> evaluate the valDeref := line.
>
> Looking at the trace provided:
>
> genBox: arg type=*int64 argval=0xc1a150, val type=, val 
> val= offset=0
> genBox: box=
> --- FAIL: TestKd1 (0.09s)
> panic: interface conversion: interface {} is nil, not *interface {} 
> [recovered]
> panic: interface conversion: interface {} is nil, not *interface {}
>
> goroutine 6 [running]:
> testing.tRunner.func1(0xc20200)
> /usr/lib/go-1.13/src/testing/testing.go:874 +0x3a3
> panic(0x523360, 0xcbc330)
> /usr/lib/go-1.13/src/runtime/panic.go:679 +0x1b2
> parsetree.com/kdtree.genBox(0x50eec0, 0xc1a150, 0x0, 0x0, 0x0, 0x2)
> /home/murf/go/kdtree/kdtree1_test.go:43 +0x43e
>
> It kinda looks like the %T and %v aren't working for val; but the stack 
> trace shows 0xc1a150 in the second argument to genBox.
>
> Uh, wait a minute! According to the stack, the first arg (called arg) is 
> 0x50eec0; but the debug output from genbox shows arg's val is 0xc1a150,
> which is what the second arg should be. So it looks like the args have 
> shifted to the left one position! And no errors on compilation?
>
> I don't know what to think.
>
> BTW, I'm on ubuntu 20.04, and the version of go is 1.13.
>
> murf
>
> On Monday, January 11, 2021 at 10:45:29 AM UTC-7 Ian Davis wrote:
>
>
> In genBox your code is saying that val contains a pointer to interface{}. 
> In other words its an interface{} that contains a *interface{}. That is a 
> weird but valid construct.
>
> I suggest you dereference it and see what the contained interface holds. 
> Something like:
>
> valDeref := val.(*interface{})
>
>  fmt.Printf("val contains=%T", valDeref)
>
> You may find that valDeref contains the *int64 you are looking for.
>
> As an aside, *interface{} is usually an indication that someone somewhere 
> is passing the wrong value to the function since it almost never makes 
> sense to pass a pointer to interface{}.
>
>
>
>
>
> On Mon, 11 Jan 2021, at 4:03 PM, Steve Murphy wrote:
>
> Hello!
>
> I keep getting:
> panic: interface conversion: interface {} is *interface {}, not *int64 
> [recovered]
> panic: interface conversion: interface {} is *interface {}, not *int64
>
> I *suspect* what is happening is that the KDElem struct has an item field 
> whose 
> type is interface{}, so that you can store a pointer to some struct (of 
> your own making),
> or an index into an array of structs, or... *whatever*, but in my case, 
> it's an index into an array
> of objects. The itemfunc (or genBox in my test code) is supposed to set 
> the item field in 
> the KDElem struct to the proper index, as the struct has just been 
> created, and the job
> of the itemfunc is to make it point to the right object, and set the 
> bounds info in the new struct.
>
> type KdElem struct {
> item   interface{} // a ptr to a particular struct, or an index 
> into an array of objects, or
> ...
> }
>
> And the func that calls the itemfunc (genBox) looks like this:
>
> func loadItems(itemfunc func(arg interface{}, val interface{}, size 
> *KdBox) int, arg interface{}, extent KdBox, length *int64, mean *float64) 
> *KdElem {
>  ...
>  newItem = new(KdElem)
>  if itemfunc(arg, , newItem.size) != 0 {
>  ...
>
>
> And, in this case the itemfunc declaration looks like this:
>
> func genBox(arg interface{}, val interface{}, box *KdBo

Re: [go-nuts] A value saved in an interface{} field in a struct not usable in func with interace{} arg

2021-01-11 Thread Steve Murphy
Many thanks, Ian, I appreciate your suggestions!

I added your code snippet to my program, and got:

panic: interface conversion: interface {} is nil, not *interface {} 
[recovered]
panic: interface conversion: interface {} is nil, not *interface {}

According to the trace, it looks like it's crashing while trying to 
evaluate the valDeref := line.

Looking at the trace provided:

genBox: arg type=*int64 argval=0xc1a150, val type=, val 
val= offset=0
genBox: box=
--- FAIL: TestKd1 (0.09s)
panic: interface conversion: interface {} is nil, not *interface {} 
[recovered]
panic: interface conversion: interface {} is nil, not *interface {}

goroutine 6 [running]:
testing.tRunner.func1(0xc20200)
/usr/lib/go-1.13/src/testing/testing.go:874 +0x3a3
panic(0x523360, 0xcbc330)
/usr/lib/go-1.13/src/runtime/panic.go:679 +0x1b2
parsetree.com/kdtree.genBox(0x50eec0, 0xc1a150, 0x0, 0x0, 0x0, 0x2)
/home/murf/go/kdtree/kdtree1_test.go:43 +0x43e

It kinda looks like the %T and %v aren't working for val; but the stack 
trace shows 0xc1a150 in the second argument to genBox.

Uh, wait a minute! According to the stack, the first arg (called arg) is 
0x50eec0; but the debug output from genbox shows arg's val is 0xc1a150,
which is what the second arg should be. So it looks like the args have 
shifted to the left one position! And no errors on compilation?

I don't know what to think.

BTW, I'm on ubuntu 20.04, and the version of go is 1.13.

murf

On Monday, January 11, 2021 at 10:45:29 AM UTC-7 Ian Davis wrote:

> In genBox your code is saying that val contains a pointer to interface{}. 
> In other words its an interface{} that contains a *interface{}. That is a 
> weird but valid construct.
>
> I suggest you dereference it and see what the contained interface holds. 
> Something like:
>
> valDeref := val.(*interface{})
>
>  fmt.Printf("val contains=%T", valDeref)
>
> You may find that valDeref contains the *int64 you are looking for.
>
> As an aside, *interface{} is usually an indication that someone somewhere 
> is passing the wrong value to the function since it almost never makes 
> sense to pass a pointer to interface{}.
>
>
>
>
>
> On Mon, 11 Jan 2021, at 4:03 PM, Steve Murphy wrote:
>
> Hello!
>
> I keep getting:
> panic: interface conversion: interface {} is *interface {}, not *int64 
> [recovered]
> panic: interface conversion: interface {} is *interface {}, not *int64
>
> I *suspect* what is happening is that the KDElem struct has an item field 
> whose 
> type is interface{}, so that you can store a pointer to some struct (of 
> your own making),
> or an index into an array of structs, or... *whatever*, but in my case, 
> it's an index into an array
> of objects. The itemfunc (or genBox in my test code) is supposed to set 
> the item field in 
> the KDElem struct to the proper index, as the struct has just been 
> created, and the job
> of the itemfunc is to make it point to the right object, and set the 
> bounds info in the new struct.
>
> type KdElem struct {
> item   interface{} // a ptr to a particular struct, or an index 
> into an array of objects, or
> ...
> }
>
> And the func that calls the itemfunc (genBox) looks like this:
>
> func loadItems(itemfunc func(arg interface{}, val interface{}, size 
> *KdBox) int, arg interface{}, extent KdBox, length *int64, mean *float64) 
> *KdElem {
>  ...
>  newItem = new(KdElem)
>  if itemfunc(arg, , newItem.size) != 0 {
>  ...
>
>
> And, in this case the itemfunc declaration looks like this:
>
> func genBox(arg interface{}, val interface{}, box *KdBox) int {
>  var offsetp = arg.(*int64) // successful
>  var offset = *offsetp // successful
>  // fmt.Printf("genBox: offset=%v offsetp=%v\n", offset, offsetp)
>  fmt.Printf("genBox: arg type=%T argval=%v, val type=%T, val 
> val=%v\n", arg, arg, val, val)
>  if offset < KDBoxes {
>   fmt.Printf("genBox: val=%v  *int64=%v\n", val, val)
>   var realval *int64 = val.(*int64) //  <<-- This is line 
> 43!  Compiles but... Crash!!!
>   *realval = offset + 1
> ...
>
> Now, I get this from a go test:
>
> KdBuild: arg type=*int64  argval=0xcd2078; 
> genBox: arg type=*int64 argval=0xcd2078, val type=*interface {}, 
> val val=0xcba640
> genBox: val=0xcba640  *int64=0xcba640
> --- FAIL: TestKd1 (0.08s)
> panic: interface conversion: interface {} is *interface {}, not *int64 
> [recovered]
> panic: interface conversion: interface {} is *interface {}, not *int64
>
> goroutine 19 [running]:
> testing.tRunner.func1(0xc000108100)
> /usr/lib/go-1.13/src/te

[go-nuts] A value saved in an interface{} field in a struct not usable in func with interace{} arg

2021-01-11 Thread Steve Murphy
Hello!

I keep getting:
panic: interface conversion: interface {} is *interface {}, not *int64
[recovered]
panic: interface conversion: interface {} is *interface {}, not *int64

I *suspect* what is happening is that the KDElem struct has an item field
whose
type is interface{}, so that you can store a pointer to some struct (of
your own making),
or an index into an array of structs, or... *whatever*, but in my case,
it's an index into an array
of objects. The itemfunc (or genBox in my test code) is supposed to set the
item field in
the KDElem struct to the proper index, as the struct has just been created,
and the job
of the itemfunc is to make it point to the right object, and set the bounds
info in the new struct.

type KdElem struct {
item   interface{} // a ptr to a particular struct, or an index
into an array of objects, or
...
}

And the func that calls the itemfunc (genBox) looks like this:

func loadItems(itemfunc func(arg interface{}, val interface{}, size *KdBox)
int, arg interface{}, extent KdBox, length *int64, mean *float64) *KdElem {
 ...
 newItem = new(KdElem)
 if itemfunc(arg, , newItem.size) != 0 {
 ...


And, in this case the itemfunc declaration looks like this:

func genBox(arg interface{}, val interface{}, box *KdBox) int {
 var offsetp = arg.(*int64) // successful
 var offset = *offsetp // successful
 // fmt.Printf("genBox: offset=%v offsetp=%v\n", offset, offsetp)
 fmt.Printf("genBox: arg type=%T argval=%v, val type=%T, val
val=%v\n", arg, arg, val, val)
 if offset < KDBoxes {
  fmt.Printf("genBox: val=%v  *int64=%v\n", val, val)
  var realval *int64 = val.(*int64) //  <<-- This is line 43!
Compiles but... Crash!!!
  *realval = offset + 1
...

Now, I get this from a go test:

KdBuild: arg type=*int64  argval=0xcd2078;
genBox: arg type=*int64 argval=0xcd2078, val type=*interface {},
val val=0xcba640
genBox: val=0xcba640  *int64=0xcba640
--- FAIL: TestKd1 (0.08s)
panic: interface conversion: interface {} is *interface {}, not *int64
[recovered]
panic: interface conversion: interface {} is *interface {}, not *int64

goroutine 19 [running]:
testing.tRunner.func1(0xc000108100)
/usr/lib/go-1.13/src/testing/testing.go:874 +0x3a3
panic(0x523360, 0xcc2360)
/usr/lib/go-1.13/src/runtime/panic.go:679 +0x1b2
parsetree.com/kdtree.genBox(0x50eec0, 0xcd2078, 0x50ef40, 0xcba640,
0x0, 0x0)
/home/murf/go/kdtree/kdtree1_test.go:43 +0x270
parsetree.com/kdtree.loadItems(0x5570f8, 0x50eec0, 0xcd2078,
0x7fff, 0x7fff, 0x8000,
0x8000, 0xc00096ab38, 0xc00096ab30, 0x0)
/home/murf/go/kdtree/kdtree.go:683 +0xec
parsetree.com/kdtree.KdBuild(0x5570f8, 0x50eec0, 0xcd2078, 0x0)
/home/murf/go/kdtree/kdtree.go:168 +0x17e
parsetree.com/kdtree.TestKd1(0xc000108100)
/home/murf/go/kdtree/kdtree1_test.go:72 +0x13a
testing.tRunner(0xc000108100, 0x5570f0)
/usr/lib/go-1.13/src/testing/testing.go:909 +0

How do I set realval to the (*int64) value that's in val?

murf

-- 

Steve Murphy
ParseTree Corporation
57 Lane 17
Cody, WY 82414
✉  murf at parsetree dot com
☎ 307-899-0510

-- 
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/CAPPCp8HGQAcdw7J_vFLW8NKsXqfh5kgUtCrQn41dBLRamQggNA%40mail.gmail.com.