Re: [go-nuts] Any recommendation for structured logging library in Golang?

2020-11-17 Thread Gopal M
go.uber.org/zap

On Wed, Nov 18, 2020 at 12:48 PM Mike Spreitzer  wrote:

> > From: ChrisLu 
> > To: golang-nuts 
> > Date: 11/17/2020 11:22 PM
> > Subject: [EXTERNAL] [go-nuts] Any recommendation for structured
> > logging library in Golang?
> > Sent by: golang-nuts@googlegroups.com
> >
> > I am considering moving from glog to structured logging. I tried
> > logrus, go-kit, uber/zap, but could not find one good fit. In short,
> > this is the desired format:
> > [info][timestamp] [filename:line_number] message k1=v1 k2=v2 ...
> > It shows the correct file name(need to pop out a few call stacks)
> > and line number in a customizable format, not as key-value pair for
> > each line which is just too verbose to have the extra "time=" "file=".
> > Please let me know the one you actually use.
> >
> > Thanks!
> > Chris
>
> How about one that has fine-grained debug leveling, like glog or klog,
> too?
>
> Thanks,
> Mike
>
>
> --
> 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/OF42CB2A54.2706B41C-ON85258624.0027F1D3-85258624.00280B00%40notes.na.collabserv.com
> .
>


-- 
Regards,
M. Gopal

-- 
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/CAB-EHXBPQdoyuEz%2BdcswnovUxNgw11Bpg%3DQNh9aT8g1FX%2BWFUA%40mail.gmail.com.


Re: [go-nuts] Any recommendation for structured logging library in Golang?

2020-11-17 Thread Mike Spreitzer
> From: ChrisLu 
> To: golang-nuts 
> Date: 11/17/2020 11:22 PM
> Subject: [EXTERNAL] [go-nuts] Any recommendation for structured 
> logging library in Golang?
> Sent by: golang-nuts@googlegroups.com
> 
> I am considering moving from glog to structured logging. I tried 
> logrus, go-kit, uber/zap, but could not find one good fit. In short,
> this is the desired format:
> [info][timestamp] [filename:line_number] message k1=v1 k2=v2 ...
> It shows the correct file name(need to pop out a few call stacks) 
> and line number in a customizable format, not as key-value pair for 
> each line which is just too verbose to have the extra "time=" "file=".
> Please let me know the one you actually use.
> 
> Thanks!
> Chris

How about one that has fine-grained debug leveling, like glog or klog, 
too?

Thanks,
Mike


-- 
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/OF42CB2A54.2706B41C-ON85258624.0027F1D3-85258624.00280B00%40notes.na.collabserv.com.


[go-nuts] Any recommendation for structured logging library in Golang?

2020-11-17 Thread ChrisLu
I am considering moving from glog to structured logging. I tried logrus, 
go-kit, uber/zap, but could not find one good fit. In short, this is the 
desired format:

[info][timestamp] [filename:line_number] message k1=v1 k2=v2 ...

It shows the correct file name(need to pop out a few call stacks) and line 
number in a customizable format, not as key-value pair for each line which 
is just too verbose to have the extra "time=" "file=".

Please let me know the one you actually use.


Thanks!
Chris
-
https://github.com/chrislusf/seaweedfs

-- 
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/8f882954-f070-4e2c-b8f9-0831c2fb91c9n%40googlegroups.com.


Re: [go-nuts] i can't use defer c.free to release the cgo.cstring memory when my func return the cstring

2020-11-17 Thread 杜仲
that's the problem, i use c just like an channel, the value final send to 
other language. i know i can make an call back function in c and then 
release that memory in c code.
 regrettably, this will take many time and i don;t have so much.
however ,thx

在2020年11月18日星期三 UTC+8 上午10:43:20 写道:

> On Tue, Nov 17, 2020 at 6:38 PM 杜仲  wrote:
> >
> > my go version is 1.13.
> > i used cgo.cstring in my func, and the func will return cstring.
> > i don't know when c complete work about the cstring memory.
> > if i used defer c.free to release the cstring memory, the cstring val 
> will change and return a unexpected value, especially at often apply memory 
> on low memory environment.
> > now i use a funccollect the pointer and release after 1 hour or later.
> > is there any other way to solve?
>
> A string allocated with C.CString is allocated using the C malloc
> function. It sounds like you are passing that string to C, in which
> case it becomes the responsibility of the C code to free the string.
> C code has to be aware of memory use and has to free memory when it is
> no longer needed. If your C code does not track memory properly, that
> is unfortunate, but there is nothing you can do to fix it safely on
> the Go side.
>
> 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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/ef1f610d-650e-43dc-8a98-e2d120aae9c5n%40googlegroups.com.


Re: [go-nuts] i can't use defer c.free to release the cgo.cstring memory when my func return the cstring

2020-11-17 Thread Ian Lance Taylor
On Tue, Nov 17, 2020 at 6:38 PM 杜仲  wrote:
>
> my go version is 1.13.
> i used cgo.cstring in my func, and the func will return cstring.
> i don't know when c complete work about the cstring memory.
> if i used defer c.free to release the cstring memory, the cstring val will 
> change and return a unexpected value, especially at often apply memory on low 
> memory environment.
> now i use a funccollect the pointer and release after 1 hour or later.
> is there any other way to solve?

A string allocated with C.CString is allocated using the C malloc
function.  It sounds like you are passing that string to C, in which
case it becomes the responsibility of the C code to free the string.
C code has to be aware of memory use and has to free memory when it is
no longer needed.  If your C code does not track memory properly, that
is unfortunate, but there is nothing you can do to fix it safely on
the Go side.

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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcUJm5eReHtxOxaTCsCctfv1JSab5hWwyPBoUca2NnEm-w%40mail.gmail.com.


[go-nuts] i can't use defer c.free to release the cgo.cstring memory when my func return the cstring

2020-11-17 Thread 杜仲
my go version is 1.13.
i used cgo.cstring in my func, and the func will return cstring.
i don't know when c complete work about the cstring memory.
if i used defer c.free to release the cstring memory, the cstring val will 
change and return a unexpected value, especially at often apply memory on 
low memory environment.
now i use a funccollect the pointer and release after 1 hour or later.
is there any other way to solve?

-- 
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/01f2da1c-23d5-41a8-a451-c6cc66478e19n%40googlegroups.com.


Re: [go-nuts] gollvm: Issues on Alpine linux. Tentative definition has type 'struct sigstack' that is never completed, in sysinfo.c

2020-11-17 Thread Ian Lance Taylor
On Tue, Nov 17, 2020 at 6:11 AM Than McIntosh  wrote:
>
> > /home/oceanfish81/workarea/llvm-project/llvm/tools/gollvm/gofrontend/libgo/sysinfo.c:462:1:
> >  error: tentative definition has type 'struct sigstack' that is never 
> > completed
> > SREF(sigstack);
> > ^
>
> I don't know why sysinfo.c has the line "SREF(sigstack)".  What
> happens if you just remove it?
>
> I agree, I would take it out and see what happens.
>
> The SREF(...) constructs in sysinfo.c are there to generate explicit 
> references to types mentioned in the C code from system header files, so as 
> to insure that DWARF gets generated for them (in case the C++ compiler being 
> used is clang, which does not support -fno-eliminate-unused-debug-types).  
> Looks like on Alpine (which is musl-based) there is no such type.   Not clear 
> whether it is actually needed at this point, so it is worth trying without it.

As far as I can tell we never use the sigstack type in libgo, so my
guess is that we don't need it.  The sigstack type (really struct
sigstack) was used for the old sigstack function, but that function
has been replaced by sigaltstack.

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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcWQvFfMsEKG8CgVc9N0ukBBxp-JnazEHqpfXu6FgnOn8A%40mail.gmail.com.


Re: [go-nuts] Making syscalls in the syscall package

2020-11-17 Thread Ian Lance Taylor
On Tue, Nov 17, 2020 at 8:20 AM Aidan Hahn  wrote:
>
> I am currently patching my local go runtime to fix a bug it has. I would like 
> to make the signal() syscall, or at least the sigaction() syscall from inside 
> the syscall package but it looks like those functions are defined as private 
> within the runtime package.
>
> I see that both SYS_SIGACTION and SYS_SIGNAL are defined in the 
> zsysnum_{os}_{arch}.go files, and it looks like these enumerations are meant 
> to be used with the RawSyscall, RawSyscall6, or rawSyscallNoError functions.
>
> My question is: how does a call to RawSyscall(SYS_SIGNAL, .) translate to 
> a call to signal(signum, handler)? Do I add the usual arguments to signal to 
> RawSyscall and then ignore the rest?

Without more information it sounds like are on a bad path.  It's
pretty hard to imagine a case where the right fix for a runtime bug is
going to be for the syscall package to call signal or sigaction.

That said, if you really do want to call them, you need to understand
how the C library makes those system calls, and you need to do the
same thing.  Often this is indeed what you suggest: simply pass the
arguments to Syscall or RawSyscall, after converting them to uintptr.
Pass 0 for the additional arguments.

For system calls like this you are going to run into the problem that
they expect a C function pointer and you only have a Go function
value.  A Go function value is not a C function pointer.  You can try
calling reflect.Value(f).Pointer() to get something like a C function
pointer, although only if f is a package-scope function.

But once you've done that you'll have the problem that the Go function
uses a different ABI than the C function, so it won't be able to
access any of the arguments.

At that point you're pretty much going to have to use the kind of
complex code that is already in the runtime package.

So I guess this seems to me like a bad path no matter how you approach it.

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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcVgY9vVB%2B9-DCQ%3DGYtqN51xLL%2Bj6YvTuKiiPLNE7Ed8NQ%40mail.gmail.com.


Re: [go-nuts] Minisign for x/crypto

2020-11-17 Thread Ian Lance Taylor
[ + Filippo ]

On Tue, Nov 17, 2020 at 12:56 PM 'Péter Szilágyi' via golang-nuts
 wrote:
>
> Hey all,
>
>   This is just a quick question whether the Go maintainers would be 
> interested in a package contribution to `x/crypto` to implement minisign? 
> https://jedisct1.github.io/minisign/
>
> Cheers,
>   Peter
>
> --
> 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/b74834d1-3db0-4027-81a7-faadcf884b06n%40googlegroups.com.

-- 
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/CAOyqgcUkCAVs-mJLeV-6%3DZCh4_6_Qk0E3CJTzoK1vjU8%2BhcreQ%40mail.gmail.com.


[go-nuts] Re: Not getting 1.15.5 as the latest Go version - getgo

2020-11-17 Thread Diego Medina
I entered https://github.com/golang/go/issues/42676 and I sent the related 
CL

On Tuesday, November 17, 2020 at 2:23:45 PM UTC-5 Diego Medina wrote:

> great, thanks! Then I'll see about raising an issue/PR with the project 
> that uses that url.
>
>
>
> On Tuesday, November 17, 2020 at 2:09:19 PM UTC-5 seank...@gmail.com 
> wrote:
>
>> VERSION reports the version the site is under, use 
>> https://golang.org/dl/?mode=json instead
>>
>> On Tuesday, November 17, 2020 at 5:21:43 PM UTC+1 fmpw...@gmail.com 
>> wrote:
>>
>>> Hi,
>>>
>>> Today I tried the getgo [1] binary but instead of providing Go 1.15.5, 
>>> it installed 1.15.4. I looked around the code and ended up in
>>>
>>> https://golang.org/VERSION?m=text
>>>
>>> which reports 1.15.4 as the latest. Is this the right place to report 
>>> this to get it fixed?
>>>
>>>
>>> [1] https://github.com/golang/tools/tree/master/cmd/getgo
>>>
>>>
>>> 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/b50a89f0-45eb-4cd7-8832-76b58a2c7544n%40googlegroups.com.


Re: [go-nuts] Ambiguous Method Promotion Bug?

2020-11-17 Thread 'Axel Wagner' via golang-nuts
"and so does zz.X.Fun", of course.

On Tue, Nov 17, 2020 at 10:14 PM Axel Wagner 
wrote:

> Hi,
>
> the relevant spec section is https://golang.org/ref/spec#Selectors
>
> A selector f may denote a field or method f of a type T, or it may refer
>> to a field or method f of a nested embedded field of T. The number of
>> embedded fields traversed to reach f is called its depth in T. The depth of
>> a field or method f declared in T is zero. The depth of a field or method f
>> declared in an embedded field A in T is the depth of f in A plus one.
>
>
> and
>
> For a value x of type T or *T where T is not a pointer or interface type,
>> x.f denotes the field or method at the shallowest depth in T where there is
>> such an f. If there is not exactly one f with shallowest depth, the
>> selector expression is illegal.
>
>
> In your example, zz.Fun refers to zz.Y.Fun, as that has a depth of 1,
> whereas zz.Q.Fun has a depth of 2 (Q has depth 1 and Fun has depth 1 within
> Q) and zz.X.Fun (X has depth 2 in Z and Fun has depth 0 in X).
>
> Note, in particular, that the check happens at the selector expression,
> not at the type-definition. This is intentional, as it means you can embed
> multiple types without it being an error if they have the same
> fields/methods.
>
> I agree that all of this makes not necessarily for the most readable code,
> but the rule that the shallowest depth must be unique is what makes the
> selector well-defined.
>
> On Tue, Nov 17, 2020 at 9:57 PM Michal Ostrowski 
> wrote:
>
>>
>> Here is a playground doc that demonstrates what seems to be strange
>> behavior regarding promotion of methods.
>>
>> https://play.golang.org/p/R9M1lAOd9CA
>>
>> It seems that I can generate a struct a have an ambiguous method by
>> adding a level of indirection in struct definitions.  Or there's something
>> in the language spec that I'm missing (and I'd appreciate a reference to
>> that in that case.)
>>
>>
>>
>> --
>> 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/cb606644-1b76-4db1-af8c-96b5efac1c20n%40googlegroups.com
>> 
>> .
>>
>

-- 
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/CAEkBMfFQkMhqdVZL8ydN69uV85uRhRE%2Bs%3DKJ6ECMNSwLoqhgUQ%40mail.gmail.com.


Re: [go-nuts] Ambiguous Method Promotion Bug?

2020-11-17 Thread 'Axel Wagner' via golang-nuts
Hi,

the relevant spec section is https://golang.org/ref/spec#Selectors

A selector f may denote a field or method f of a type T, or it may refer to
> a field or method f of a nested embedded field of T. The number of embedded
> fields traversed to reach f is called its depth in T. The depth of a field
> or method f declared in T is zero. The depth of a field or method f
> declared in an embedded field A in T is the depth of f in A plus one.


and

For a value x of type T or *T where T is not a pointer or interface type,
> x.f denotes the field or method at the shallowest depth in T where there is
> such an f. If there is not exactly one f with shallowest depth, the
> selector expression is illegal.


In your example, zz.Fun refers to zz.Y.Fun, as that has a depth of 1,
whereas zz.Q.Fun has a depth of 2 (Q has depth 1 and Fun has depth 1 within
Q) and zz.X.Fun (X has depth 2 in Z and Fun has depth 0 in X).

Note, in particular, that the check happens at the selector expression, not
at the type-definition. This is intentional, as it means you can embed
multiple types without it being an error if they have the same
fields/methods.

I agree that all of this makes not necessarily for the most readable code,
but the rule that the shallowest depth must be unique is what makes the
selector well-defined.

On Tue, Nov 17, 2020 at 9:57 PM Michal Ostrowski  wrote:

>
> Here is a playground doc that demonstrates what seems to be strange
> behavior regarding promotion of methods.
>
> https://play.golang.org/p/R9M1lAOd9CA
>
> It seems that I can generate a struct a have an ambiguous method by adding
> a level of indirection in struct definitions.  Or there's something in the
> language spec that I'm missing (and I'd appreciate a reference to that in
> that case.)
>
>
>
> --
> 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/cb606644-1b76-4db1-af8c-96b5efac1c20n%40googlegroups.com
> 
> .
>

-- 
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/CAEkBMfEkpAKtQo0zUrZ5hwEUa9wEYy%2BX4M_j17mniuap6R-uWw%40mail.gmail.com.


[go-nuts] Minisign for x/crypto

2020-11-17 Thread 'Péter Szilágyi' via golang-nuts
Hey all,

  This is just a quick question whether the Go maintainers would be 
interested in a package contribution to `x/crypto` to implement 
minisign? https://jedisct1.github.io/minisign/

Cheers,
  Peter

-- 
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/b74834d1-3db0-4027-81a7-faadcf884b06n%40googlegroups.com.


[go-nuts] Ambiguous Method Promotion Bug?

2020-11-17 Thread Michal Ostrowski

Here is a playground doc that demonstrates what seems to be strange 
behavior regarding promotion of methods.

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

It seems that I can generate a struct a have an ambiguous method by adding 
a level of indirection in struct definitions.  Or there's something in the 
language spec that I'm missing (and I'd appreciate a reference to that in 
that case.)



-- 
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/cb606644-1b76-4db1-af8c-96b5efac1c20n%40googlegroups.com.


Re: [go-nuts] How to detect HTTP client stop polling at the server side

2020-11-17 Thread Shulhan



> On 18 Nov 2020, at 01.06, Afriyie Abraham Kwabena  
> wrote:
> 
> Hi,
> 
> The UpdateData function is the HTTP handler for the route which matches the 
> URL and  is called after the mux.Router after receiving an incoming request 
> matches the incoming request
>  against the registered route. 

...

> var idtime = make(map[string]int64)
> 
> 
> func UpdateData(response http.ResponseWriter, request *http.Request) {
> 
> var (
> localVarHTTPMethod = http.MethodPatch
> patchItems model.PatchItem
> )
> 
> id := config.GetIdFromRequest(request)
> 
> if request.Method == localVarHTTPMethod {
> 
> err := json.NewDecoder(request.Body).Decode()
> if err != nil {
> common.WriteError(response, common.ErrBadRequest)
> return
> }
> 
> defer request.Body.Close()
> 
> idtime[id] = time.Now().Unix()
> 

We still may have data race here.

> 
> func worker() {
> mu.Lock()
> for keyid := range idtime {
> 
> d := time.Now().Unix() - idtime[keyid]
> if d >= 60 {
> 
> // delete resouce in database after 60 seconds
> _ = DeleteNFInstance(ctx, keyid)
> }
> }
> mu.Unlock()
> }
> 

...

> // main function
> func main() {
> r := NewRouter()
> 
> go worker()
> 
> 
> fmt.Println("Start listening")
> fmt.Println(http.ListenAndServe(":8080", r))
> }
> 
> I appreciate your help but am still not able to it work.
> 

Looks like your worker only loop once and then it finished.  Either you use 
time.Sleep() to repeat the loop inside loop or use time.Ticker [1].

[1] https://pkg.go.dev/time#Ticker

-- 
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/B0663F2A-D51D-43D5-8D63-95C73B51DF90%40gmail.com.


[go-nuts] Re: Not getting 1.15.5 as the latest Go version - getgo

2020-11-17 Thread Diego Medina
great, thanks! Then I'll see about raising an issue/PR with the project 
that uses that url.



On Tuesday, November 17, 2020 at 2:09:19 PM UTC-5 seank...@gmail.com wrote:

> VERSION reports the version the site is under, use 
> https://golang.org/dl/?mode=json instead
>
> On Tuesday, November 17, 2020 at 5:21:43 PM UTC+1 fmpw...@gmail.com wrote:
>
>> Hi,
>>
>> Today I tried the getgo [1] binary but instead of providing Go 1.15.5, it 
>> installed 1.15.4. I looked around the code and ended up in
>>
>> https://golang.org/VERSION?m=text
>>
>> which reports 1.15.4 as the latest. Is this the right place to report 
>> this to get it fixed?
>>
>>
>> [1] https://github.com/golang/tools/tree/master/cmd/getgo
>>
>>
>> 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/46ddb3aa-d2bd-4222-a788-1181dc1cc07cn%40googlegroups.com.


[go-nuts] Re: Not getting 1.15.5 as the latest Go version - getgo

2020-11-17 Thread seank...@gmail.com
VERSION reports the version the site is under, 
use https://golang.org/dl/?mode=json instead

On Tuesday, November 17, 2020 at 5:21:43 PM UTC+1 fmpw...@gmail.com wrote:

> Hi,
>
> Today I tried the getgo [1] binary but instead of providing Go 1.15.5, it 
> installed 1.15.4. I looked around the code and ended up in
>
> https://golang.org/VERSION?m=text
>
> which reports 1.15.4 as the latest. Is this the right place to report this 
> to get it fixed?
>
>
> [1] https://github.com/golang/tools/tree/master/cmd/getgo
>
>
> 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/edd0092c-0ae5-408e-9ec9-fbf5a6b86cb3n%40googlegroups.com.


Re: [go-nuts] How to detect HTTP client stop polling at the server side

2020-11-17 Thread Afriyie Abraham Kwabena
Hi,

The UpdateData function is the HTTP handler for the route which matches the 
URL and  is called after the mux.Router after receiving an incoming request 
matches the incoming request
 against the registered route. 

BR
Afriyie


On Tuesday, November 17, 2020 at 7:33:50 PM UTC+2 Afriyie Abraham Kwabena 
wrote:

> Hi,
>
> I have made changes according to the comments and also simply the main 
> function but am not sure if the worker go routine works. 
> This what i did:
>
> type Route struct {
> Namestring
> Method  string
> Pattern string
> HandlerFunc http.HandlerFunc
> }
>
> var idtime = make(map[string]int64)
>
>
> func UpdateData(response http.ResponseWriter, request *http.Request) {
>
> var (
> localVarHTTPMethod = http.MethodPatch
> patchItems model.PatchItem
> )
>
> id := config.GetIdFromRequest(request)
>
> if request.Method == localVarHTTPMethod {
>
> err := json.NewDecoder(request.Body).Decode()
> if err != nil {
> common.WriteError(response, common.ErrBadRequest)
> return
> }
>
> defer request.Body.Close()
>
> idtime[id] = time.Now().Unix()
>
>
> common.RespondWith3gppJsonPatchJson(response, 
> http.StatusNoContent, nil)
> } else {
> common.WriteError(response, common.ErrMethodNotAllowed)
> return
> }
> }
>
> var (
> mu  sync.Mutex
> ctx = context.Background()
> )
>
> func worker() {
> mu.Lock()
> for keyid := range idtime {
>
> d := time.Now().Unix() - idtime[keyid]
> if d >= 60 {
>
> // delete resouce in database after 60 seconds
> _ = DeleteNFInstance(ctx, keyid)
> }
> }
> mu.Unlock()
> }
>
> // Delete info
> func DeleteNFInstance(ctx context.Context, nfinstanceId string) bool {
> filter := bson.M{"_id": nfinstanceId}
> _, err := db.Collection(COLLECTION).DeleteOne(ctx, filter)
> if err != nil {
> return false
> }
> return true
> }
>
> type Routes []Route
>
> func NewRouter() *mux.Router {
> router := mux.NewRouter().StrictSlash(true)
> for _, route := range routes {
> var handler http.Handler
> handler = route.HandlerFunc
>
> router.
> Methods(route.Method).
> Path(route.Pattern).
> Name(route.Name).
> Handler(handler)
> }
>
> return router
> }
>
> var routes = Routes{
>
> Route{
> "UpdateData",
> strings.ToUpper("Patch"),
> "/users/{id}",
> UpdateData,
> },
> }
>
> // main function
> func main() {
> r := NewRouter()
>
> go worker()
>
>
> fmt.Println("Start listening")
> fmt.Println(http.ListenAndServe(":8080", r))
> }
>
> I appreciate your help but am still not able to it work.
>
>
> On Tuesday, November 17, 2020 at 3:48:44 PM UTC+2 Shulhan wrote:
>
>> Hi Afriyie, 
>>
>> Looks like you almost there ;) 
>>
>> > On 17 Nov 2020, at 20.11, Afriyie Abraham Kwabena  
>> wrote: 
>> > 
>> > HI, 
>> > 
>> > This is what I have tried so far but am not able to get the time 
>> difference in seconds. I mean the time differences between the time stored 
>> in the map[string]time.Time and 
>> > the current time in seconds. 
>> > 
>> > code: 
>> > 
>> > type Server struct { 
>> > idtime map[string]time.Time 
>> > } 
>> > 
>> > var my = Server{} 
>> > 
>> > func main() { 
>> > r := mux.NewRouter() 
>> > usersData := r.PathPrefix("/users").Subrouter() 
>> > 
>> usersData.Path("/{id}").Methods(http.MethodPatch).HandlerFunc(UpdateData) 
>> > 
>>
>> Based on my understanding (I have never use mux before), the UpdateDate 
>> function will be running concurrently as goroutine. Lets say that we have 
>> three PATCH requests at the same time, there will be three UpdateData 
>> running concurrently or in parallel. 
>>
>> > fmt.Println("Start listening") 
>> > fmt.Println(http.ListenAndServe(":8080", r)) 
>> > } 
>> > 
>> > func UpdateData(response http.ResponseWriter, request *http.Request) { 
>> > 
>> > var ( 
>> > localVarHTTPMethod = http.MethodPatch 
>> > patchItems model.PatchItem 
>> > ) 
>> > 
>> > id := config.GetIdFromRequest(request) 
>> > 
>> > if request.Method == localVarHTTPMethod { 
>> > 
>> > err := json.NewDecoder(request.Body).Decode() 
>> > if err != nil { 
>> > common.WriteError(response, common.ErrBadRequest) 
>> > return 
>> > } 
>> > 
>> > defer request.Body.Close() 
>> > 
>> > my.idtime = make(map[string]time.Time) 
>>
>> Since the UpdateData is running independently for each request, you 
>> should initialize this once, in the main, otherwise each UpdateData routine 
>> will reset the idtime variable. 
>>
>> > my.idtime[id] = time.Now() 
>> > 
>> > go func() { 
>> > for keyid, t := range my.idtime { 
>> > 
>> > ts := t.Format(time.RFC3339) 
>> > 
>> > v, err := time.Parse(time.RFC3339, ts) 
>> > if err != nil { 
>> > fmt.Println(err) 
>> > os.Exit(1) 
>> > } 
>> > 
>> > 

Re: [go-nuts] How to detect HTTP client stop polling at the server side

2020-11-17 Thread Afriyie Abraham Kwabena
Hi,

I have made changes according to the comments and also simply the main 
function but am not sure if the worker go routine works. 
This what i did:

type Route struct {
Namestring
Method  string
Pattern string
HandlerFunc http.HandlerFunc
}

var idtime = make(map[string]int64)

func UpdateData(response http.ResponseWriter, request *http.Request) {

var (
localVarHTTPMethod = http.MethodPatch
patchItems model.PatchItem
)

id := config.GetIdFromRequest(request)

if request.Method == localVarHTTPMethod {

err := json.NewDecoder(request.Body).Decode()
if err != nil {
common.WriteError(response, common.ErrBadRequest)
return
}

defer request.Body.Close()

idtime[id] = time.Now().Unix()

common.RespondWith3gppJsonPatchJson(response, http.StatusNoContent, 
nil)
} else {
common.WriteError(response, common.ErrMethodNotAllowed)
return
}
}

var (
mu  sync.Mutex
ctx = context.Background()
)

func worker() {
mu.Lock()
for keyid := range idtime {

d := time.Now().Unix() - idtime[keyid]
if d >= 60 {
// delete resouce in database after 60 seconds
_ = DeleteNFInstance(ctx, keyid)
}
}
mu.Unlock()
}

// Delete info
func DeleteNFInstance(ctx context.Context, nfinstanceId string) bool {
filter := bson.M{"_id": nfinstanceId}
_, err := db.Collection(COLLECTION).DeleteOne(ctx, filter)
if err != nil {
return false
}
return true
}

type Routes []Route

func NewRouter() *mux.Router {
router := mux.NewRouter().StrictSlash(true)
for _, route := range routes {
var handler http.Handler
handler = route.HandlerFunc

router.
Methods(route.Method).
Path(route.Pattern).
Name(route.Name).
Handler(handler)
}

return router
}

var routes = Routes{

Route{
"UpdateData",
strings.ToUpper("Patch"),
"/users/{id}",
UpdateData,
},
}

// main function
func main() {
r := NewRouter()

go worker()

fmt.Println("Start listening")
fmt.Println(http.ListenAndServe(":8080", r))
}

I appreciate your help but am still not able to it work.


On Tuesday, November 17, 2020 at 3:48:44 PM UTC+2 Shulhan wrote:

> Hi Afriyie,
>
> Looks like you almost there ;)
>
> > On 17 Nov 2020, at 20.11, Afriyie Abraham Kwabena  
> wrote:
> > 
> > HI,
> > 
> > This is what I have tried so far but am not able to get the time 
> difference in seconds. I mean the time differences between the time stored 
> in the map[string]time.Time and
> > the current time in seconds.
> > 
> > code:
> > 
> > type Server struct {
> > idtime map[string]time.Time
> > }
> > 
> > var my = Server{}
> > 
> > func main() {
> > r := mux.NewRouter()
> > usersData := r.PathPrefix("/users").Subrouter()
> > usersData.Path("/{id}").Methods(http.MethodPatch).HandlerFunc(UpdateData)
> > 
>
> Based on my understanding (I have never use mux before), the UpdateDate 
> function will be running concurrently as goroutine. Lets say that we have 
> three PATCH requests at the same time, there will be three UpdateData 
> running concurrently or in parallel.
>
> > fmt.Println("Start listening")
> > fmt.Println(http.ListenAndServe(":8080", r))
> > }
> > 
> > func UpdateData(response http.ResponseWriter, request *http.Request) {
> > 
> > var (
> > localVarHTTPMethod = http.MethodPatch
> > patchItems model.PatchItem
> > )
> > 
> > id := config.GetIdFromRequest(request)
> > 
> > if request.Method == localVarHTTPMethod {
> > 
> > err := json.NewDecoder(request.Body).Decode()
> > if err != nil {
> > common.WriteError(response, common.ErrBadRequest)
> > return
> > }
> > 
> > defer request.Body.Close()
> > 
> > my.idtime = make(map[string]time.Time)
>
> Since the UpdateData is running independently for each request, you should 
> initialize this once, in the main, otherwise each UpdateData routine will 
> reset the idtime variable.
>
> > my.idtime[id] = time.Now()
> > 
> > go func() {
> > for keyid, t := range my.idtime {
> > 
> > ts := t.Format(time.RFC3339)
> > 
> > v, err := time.Parse(time.RFC3339, ts)
> > if err != nil {
> > fmt.Println(err)
> > os.Exit(1)
> > }
> > 
> > timeRemaining := getTimeRemaining(v)
> > 
> > if timeRemaining.S >= 60 {
> > // delete resouce in database after 60 seconds
> > deleteResourceUsingIdkey(keyid)
> > }
> > }
> > }()
>
> Also, you should move the above goroutine to main, otherwise each call to 
> UpdateData will spawn a new goroutine.
>
> If I were you I will use the Unix time [1] instead of Time object, its 
> much simpler `time.Now().Unix() - my.idtime[keyid] >= 60`.
>
> BTW, beware of race condition. Test or build your program with "-race" 
> option to see it by yourself. Use sync.Mutex [2] to prevent the write 
> (updating the map) overlap with read (checking the elapsed seconds).
>
> 

[go-nuts] Not getting 1.15.5 as the latest Go version - getgo

2020-11-17 Thread Diego Medina
Hi,

Today I tried the getgo [1] binary but instead of providing Go 1.15.5, it 
installed 1.15.4. I looked around the code and ended up in

https://golang.org/VERSION?m=text

which reports 1.15.4 as the latest. Is this the right place to report this 
to get it fixed?


[1] https://github.com/golang/tools/tree/master/cmd/getgo


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/f8c33591-43eb-42cf-84c4-e8ea6008ec7cn%40googlegroups.com.


[go-nuts] Making syscalls in the syscall package

2020-11-17 Thread Aidan Hahn
Good Morning/Afternoon/Evening,

I am currently patching my local go runtime to fix a bug it has. I would 
like to make the signal() syscall, or at least the sigaction() syscall from 
inside the syscall package but it looks like those functions are defined as 
private within the runtime package. 

I see that both SYS_SIGACTION and SYS_SIGNAL are defined in the 
zsysnum_{os}_{arch}.go files, and it looks like these enumerations are 
meant to be used with the RawSyscall, RawSyscall6, or rawSyscallNoError 
functions.

My question is: how does a call to RawSyscall(SYS_SIGNAL, .) translate 
to a call to signal(signum, handler)? Do I add the usual arguments to 
signal to RawSyscall and then ignore the rest?

Thanks,
Aidan

-- 
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/7c8acd74-a4fb-4e79-ac3a-c6a09421b8cdn%40googlegroups.com.


Re: [go-nuts] Any general VPN(pptp, l2tp, openVPN, IPSec VPN) server implementation in go?

2020-11-17 Thread Sergey Matveev
Greetings!

*** Nathan [2020-11-17 02:33]:
>But I did a lot of research, it seems there is no go implementation for the 
>general VPN.

There is pure Go ESPv3/IKEv2 implementation: 
http://www.gostipsec.cypherpunks.ru/
It supports small subset of algorithms, but is ok for testing purposes.

-- 
Sergey Matveev (http://www.stargrave.org/)
OpenPGP: CF60 E89A 5923 1E76 E263  6422 AE1A 8109 E498 57EF

-- 
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/X7OunlgKEebbIdl8%40stargrave.org.


Re: [go-nuts] Any general VPN(pptp, l2tp, openVPN, IPSec VPN) server implementation in go?

2020-11-17 Thread Daniel Moch
> Hi, I want to use a general VPN protocols to comminucate with my server, we 
> cannot change the client to use other VPN protocols.
> But I did a lot of research, it seems there is no go implementation for the 
> general VPN.
> 
> I really want that I'm wrong, so do any guys can give me some suggestion? 
> Thanks in advance.

You might look at WireGuard[1].  It's a fairly new technology, but it
has a pure-Go implementation that I've used successfully.

[1] - https://www.wireguard.com/repositories/

-- 
Daniel Moch
https://djmo.ch

-- 
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/7DBE6CABFA1023202E5392974E8ADCA9%40ranger.org.


Re: [go-nuts] Re: How does the Golang compiler handle dependencies?

2020-11-17 Thread Haddock
Here is an article by Walter Bright that explains what the C++ compiler is 
doing: https://www.digitalmars.com/articles/b54.htm 
l Walter Bright is the 
creator of the first C++ compiler (if I remember right this was the Zortech 
C++ compiler, later acquired by Symantec).


aleksey...@gmail.com schrieb am Sonntag, 15. November 2020 um 20:12:49 
UTC+1:

> Yeah, that's a good point. A C unit that is using f() won't
> necessarily include f's implementation if it is defined somewhere
> else. It may create a (weak?) reference to f() and leave the rest to
> the linker. However to compile correctly it would *normally* include a
> header where f() is declared to at least check that f() is accessed
> using the correct interface, so f's declaration would normally be
> pulled into a unit.
>
> In C++ what to include into a unit and what not to include is a bit
> more complicated especially if templates are involved (which is
> usually the case), but perhaps such details are out of the scope of
> this mailing list.
>
> But yeah, i didn't realize that my email might be misleading in that
> regard, sorry about that.
>
> вс, 15 нояб. 2020 г. в 18:19, Robert Engels :
> >
> > Object files do not contain dependencies except for code that the 
> compiler inlines. It has linkage referees that are resolved during linking.
> >
> > On Nov 15, 2020, at 8:05 AM, kev kev  wrote:
> >
> > Reading Alekseys description, it does seem to be making a bit more 
> sense. The C/C++ compilers use a "file" as a compilation unit. A file is 
> converted to an object file which must contain all of its dependencies. So 
> the includes will need to copy all of the code that they are importing into 
> the file that is being compiled.
> >
> > In Golang, the object file is more of a blackbox which contains only the 
> necessary data that is needed. I'm assuming that "necessary" relates to 
> type checking and symbol resolution mostly.
> >
> > It seems that one key difference is that Golang uses a package as a 
> compilation unit, while C++ uses a file. If Golang used a file also and not 
> a module structure, then it seems that similar issues or a significant 
> decrease in performance would be observed. You would have more object files 
> for one and there would be more dependencies between files.
> >
> >
> >
> > On Saturday, 14 November 2020 at 05:57:27 UTC aleksey...@gmail.com 
> wrote:
> >>
> >> There is no direct relationship between headers and object files in C
> >> or C++. Compilation process is two stage:
> >>
> >> 1. Source files are compiled into object files
> >> 2. Object files are linked together into executable of sorts
> >>
> >> (Actually it's a three stage process, but i'm going to describe it
> >> using two stages).
> >>
> >> Stages are isolated from each other and to some extent autonomous.
> >> Object files are kind of intermediate representation of source code
> >> that is later used to produce machine code. I'm sure someone can
> >> correct me on this, but for the sake of simplicity, i think it's OK to
> >> think of them as of IR.
> >>
> >> When *compilation unit* is compiled into an object file, it is also
> >> separated from other units. To compile it separately from other units
> >> all relevant source code has to be pulled into the current unit and
> >> compiled. So `#include ` doesn't include just
> >> something.h, it includes something.h, then all includes that
> >> something.h includes and so on. This is a process similar to
> >> amalgamation of source code, everything is copied into one place and
> >> then compiled as a single unit. After all units are compiled, they
> >> might be joined together by a linker either into a static library,
> >> dynamic library or executable.
> >>
> >> This is actually more sophisticated than that, but it does allow you
> >> to do some cool stuff like you can compile your source code into
> >> objects, then ship object files and then link them elsewhere. In fact,
> >> static libraries are just a bunch of object files packed together, but
> >> headers are still required because you need symbol names to refer to
> >> on source code level, therefore libraries are shipped with headers:
> >> you compile with headers and then link with objects.
> >>
> >> Since it's the separate stages, you could, for instance, write your
> >> own headers for 3rd party objects, think open source headers for
> >> closed source DirectX SDK.
> >>
> >> This description is very superficial and doesn't cover a lot of what
> >> is really going on. The process is very flexible and allows to do all
> >> kinds of stuff in various combinations. Alas this process is also not
> >> very fast and requires some costly steps like you need to pull all
> >> required source code into a single unit to compile it.
> >>
> >> Modern C++ is also using a lot of templates, even if you're not
> >> writing templates, you're going to use templates from the standard
> >> library and to use 

Re: [go-nuts] Heap allocation found in function prolog

2020-11-17 Thread 'ju...@sqreen.com' via golang-nuts
Thanks for the hints, I could finally have a look at it and found that a 
uint64 value was escaping regardless of the actual function code path. I 
can reproduce it with this dummy function example: 

func foo(cond bool, v int) *int {
if cond {
return 
}
return nil
}

The compiled function prolog allocates the int value regardless of the fact 
it's not always needed.
I fixed it for now by declaring a new value in the condition block:

func foo(cond bool, v int) *int {
if cond {
v := v // new declaration in this scope to avoid using function 
scope
return 
}
return nil
}

Is it something expected?

Best
-- 
Julio Guerra

-- 
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/d6e14db3-6689-40d9-a400-ef76d6e01137n%40googlegroups.com.


[go-nuts] arangodb go-client and an interface field in the struct

2020-11-17 Thread sbezv...@cisco.com
Hello, 
I was wondering if somebody had experience storing a struct in arangodb 
using arangodb go client when the struct was carrying some fields as 
interfaces. Would it be sufficient to provide MarshalJSON/UnmarshalJSON 
dealing with the interface type field?
Appreciate any feedback
Thank you
Serguei

-- 
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/c5523799-cc69-47b8-894d-7e3589a86f43n%40googlegroups.com.


Re: [go-nuts] gollvm: Issues on Alpine linux. Tentative definition has type 'struct sigstack' that is never completed, in sysinfo.c

2020-11-17 Thread 'Than McIntosh' via golang-nuts
>
/home/oceanfish81/workarea/llvm-project/llvm/tools/gollvm/gofrontend/libgo/sysinfo.c:462:1:
error: tentative definition has type 'struct sigstack' that is never
completed
> SREF(sigstack);
> ^

I don't know why sysinfo.c has the line "SREF(sigstack)".  What
happens if you just remove it?

I agree, I would take it out and see what happens.

The SREF(...) constructs in sysinfo.c are there to generate explicit
references to types mentioned in the C code from system header files, so as
to insure that DWARF gets generated for them (in case the C++ compiler
being used is clang, which does not
support -fno-eliminate-unused-debug-types).  Looks like on Alpine (which is
musl-based) there is no such type.   Not clear whether it is
actually needed at this point, so it is worth trying without it.

Thanks, Than



On Sun, Nov 15, 2020 at 11:51 AM Ian Lance Taylor  wrote:

> On Sun, Nov 15, 2020 at 7:25 AM Ivan Serdyuk
>  wrote:
> >
> > I was trying to check what is required to build gollvm on Alpine linux
> (it has musl instead of glibc).
> >
> > Look like recently revealed set of minimal requirements allowed to build
> the configuration file (for Ninja).
> >
> > heading to check whether Ninja would compile.
> > I wasn't able to find a pre-compiled Clang 11, for Alpine - but Clang 10
> was available, which was pre-compiled against musl (C++ standard library
> has to rely on musl, instead of glibc - as I suppose).
> >
> > Maybe I would recompile Clang 11, for Alpine distro - but not today.
> >
> > Must admit that CMake worked much faster, compared to Ubuntu.
> >
> > Comments would be much appreciated.
> >
> > So, I am stuck:
> >
> > [1/1084] Building sysinfo.o
> > FAILED: tools/gollvm/libgo/sysinfo.o
> > cd /home/oceanfish81/workarea/build_release/tools/gollvm/libgo &&
> /usr/bin/clang -g3 -c -fno-eliminate-unused-debug-types
> /home/oceanfish81/workarea/llvm-project/llvm/tools/gollvm/gofrontend/libgo/sysinfo.c
> -o /home/oceanfish81/workarea/build_release/tools/gollvm/libgo/sysinfo.o
> -D_GNU_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
> -I/home/oceanfish81/workarea/build_release/tools/gollvm/libgo
> -I/home/oceanfish81/workarea/build_release/tools/gollvm/libgo/runtime
> >
> /home/oceanfish81/workarea/llvm-project/llvm/tools/gollvm/gofrontend/libgo/sysinfo.c:462:1:
> error: tentative definition has type 'struct sigstack' that is never
> completed
> > SREF(sigstack);
> > ^
>
> I don't know why sysinfo.c has the line "SREF(sigstack)".  What
> happens if you just remove it?
>
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/CAOyqgcX3XtC4mr_atXaj8%2BBeicqsbOKZmw8kzKU9DYXaXAP9mw%40mail.gmail.com
> .
>

-- 
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/CA%2BUr55FtzED%3Das9TaExL2%3D3oMxCn7oeFparj_DQOUCyGSKeyzQ%40mail.gmail.com.


Re: [go-nuts] How to detect HTTP client stop polling at the server side

2020-11-17 Thread Shulhan
Hi Afriyie,

Looks like you almost there ;)

> On 17 Nov 2020, at 20.11, Afriyie Abraham Kwabena  
> wrote:
> 
> HI,
> 
> This is what I have tried so far but am not able to get the time difference 
> in seconds. I mean the time differences between the time stored in the 
> map[string]time.Time and
> the current time in seconds.
> 
> code:
> 
> type Server struct {
> idtime map[string]time.Time
> }
> 
> var my = Server{}
> 
> func main() {
> r := mux.NewRouter()
> usersData := r.PathPrefix("/users").Subrouter()
> usersData.Path("/{id}").Methods(http.MethodPatch).HandlerFunc(UpdateData)
> 

Based on my understanding (I have never use mux before), the UpdateDate 
function will be running concurrently as goroutine. Lets say that we have three 
PATCH requests at the same time, there will be three UpdateData running 
concurrently or in parallel.

> fmt.Println("Start listening")
> fmt.Println(http.ListenAndServe(":8080", r))
> }
> 
> func UpdateData(response http.ResponseWriter, request *http.Request) {
> 
> var (
> localVarHTTPMethod = http.MethodPatch
> patchItems model.PatchItem
> )
> 
> id := config.GetIdFromRequest(request)
> 
> if request.Method == localVarHTTPMethod {
> 
> err := json.NewDecoder(request.Body).Decode()
> if err != nil {
> common.WriteError(response, common.ErrBadRequest)
> return
> }
> 
> defer request.Body.Close()
> 
> my.idtime = make(map[string]time.Time)

Since the UpdateData is running independently for each request, you should 
initialize this once, in the main, otherwise each UpdateData routine will reset 
the idtime variable.

> my.idtime[id] = time.Now()
> 
> go func() {
> for keyid, t := range my.idtime {
> 
> ts := t.Format(time.RFC3339)
> 
> v, err := time.Parse(time.RFC3339, ts)
> if err != nil {
> fmt.Println(err)
> os.Exit(1)
> }
> 
> timeRemaining := getTimeRemaining(v)
> 
> if timeRemaining.S >= 60 {
> // delete resouce in database after 60 seconds
> deleteResourceUsingIdkey(keyid)
> }
> }
> }()

Also, you should move the above goroutine to main, otherwise each call to 
UpdateData will spawn a new goroutine.

If I were you I will use the Unix time [1] instead of Time object, its much 
simpler `time.Now().Unix() - my.idtime[keyid] >= 60`.

BTW, beware of race condition. Test or build your program with "-race" option 
to see it by yourself. Use sync.Mutex [2] to prevent the write (updating the 
map) overlap with read (checking the elapsed seconds).

[1] https://pkg.go.dev/time#Time.Unix
[2] https://pkg.go.dev/sync#Mutex

> 
> common.RespondWith3gppJsonPatchJson(response, http.StatusNoContent, 
> nil)
> } else {
> 
> common.WriteError(response, common.ErrMethodNotAllowed)
> return
> }

Another things that I can't not comment, you can simplify the code by 
returning-first, which minimize code identation.

> }
> 
> type count struct {
> S int
> }
> 
> func getTimeRemaining(t time.Time) count {
> currentTime := time.Now()
> difference := t.Sub(currentTime)
> 
> seconds := int(difference.Seconds())
> 
> return count{
> S: seconds,
> }
> }
> 
> func deleteResourceUsingIdkey(idkey string) {
> // do delete here
> }
> 
> Any help.
> 

-- 
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/3F1FDD40-AD43-413C-BE21-0BE7EB327F32%40gmail.com.


Re: [go-nuts] How to detect HTTP client stop polling at the server side

2020-11-17 Thread Afriyie Abraham Kwabena
HI,

This is what I have tried so far but am not able to get the time difference 
in seconds. I mean the time differences between the time stored in the 
map[string]time.Time and
the current time in seconds.

code:

type Server struct {
idtime map[string]time.Time
}

var my = Server{}

func main() {
r := mux.NewRouter()
usersData := r.PathPrefix("/users").Subrouter()
   
 usersData.Path("/{id}").Methods(http.MethodPatch).HandlerFunc(UpdateData)

fmt.Println("Start listening")
fmt.Println(http.ListenAndServe(":8080", r))
}

func UpdateData(response http.ResponseWriter, request *http.Request) {

var (
localVarHTTPMethod = http.MethodPatch
patchItems model.PatchItem
)

id := config.GetIdFromRequest(request)

if request.Method == localVarHTTPMethod {

err := json.NewDecoder(request.Body).Decode()
if err != nil {
common.WriteError(response, common.ErrBadRequest)
return
}

defer request.Body.Close()

my.idtime = make(map[string]time.Time)
my.idtime[id] = time.Now()

go func() {
for keyid, t := range my.idtime {

ts := t.Format(time.RFC3339)

v, err := time.Parse(time.RFC3339, ts)
if err != nil {
fmt.Println(err)
os.Exit(1)
}

timeRemaining := getTimeRemaining(v)

if timeRemaining.S >= 60 {
// delete resouce in database after 60 seconds
deleteResourceUsingIdkey(keyid)
}
}
}()

common.RespondWith3gppJsonPatchJson(response, http.StatusNoContent, 
nil)
} else {

common.WriteError(response, common.ErrMethodNotAllowed)
return
}
}

type count struct {
S int
}

func getTimeRemaining(t time.Time) count {
currentTime := time.Now()
difference := t.Sub(currentTime)

seconds := int(difference.Seconds())

return count{
S: seconds,
}
}

func deleteResourceUsingIdkey(idkey string) {
// do delete here
}

Any help.


On Tuesday, November 17, 2020 at 10:34:39 AM UTC+2 Anderson Queiroz wrote:

> Just one thing to keep in mind. Likely you have more than one serve 
> instance running to process the requests. Thus it might happen the client 
> will poll a different server on every request. Just imagine you have 
> servers A, B, C behind a load balance and the domain example.com. As the 
> client is pooling example.com, the first request might reach A, the 
> second B and the third C. Now you have the 3 servers tracking the same 
> client. It might happen server A doesn't receive any request from the 
> client for a while, but not because the client isn't pooling any more, but 
> because all requests are being directed to either B or C.
>
> On Tuesday, 17 November 2020 at 07:12:18 UTC+1 Shulhan wrote:
>
>>
>>
>> > On 16 Nov 2020, at 16.24, Afriyie Abraham Kwabena  
>> wrote: 
>> > 
>> > Hi , 
>> > 
>> > You are right but am new to programming and currently this what i have 
>> done. 
>> > I have an http server handler that receives the PATCH request and 
>> stores the id and the current time stamp of the request. 
>> > But my problem is how to write the worker function to do the clean up 
>> every X seconds. 
>> > 
>> > Code: 
>> > func UpdateData(response http.ResponseWriter, request *http.Request) { 
>> > 
>> > var ( 
>> > localVarHTTPMethod = http.MethodPatch 
>> > patchItems model.PatchItem 
>> > ) 
>> > 
>> > id := config.GetIdFromRequest(request) 
>> > 
>> > if request.Method == localVarHTTPMethod { 
>> > 
>> > err := json.NewDecoder(request.Body).Decode() 
>> > if err != nil { 
>> > common.WriteError(response, common.ErrBadRequest) 
>> > return 
>> > } 
>> > 
>> > defer request.Body.Close() 
>> > 
>> > var idtime = make(map[string]string) 
>> > 
>> > delete(idtime, id) // delete if already exist 
>> > idtime[id] = time.Now() // store id and time stamp in map 
>>
>> You should store idtime inside the server/service type (the one that have 
>> HTTP handlers). For example, 
>>
>>  
>> type Server struct { 
>> idtime map[string]string 
>> } 
>>
>> func (my *Server) UpdateData(...) { 
>> ... 
>> my.idtime[id] = time.Now() 
>> ... 
>> } 
>>  
>>
>> > 
>> > // how do i write a worker to the clean up after every X seconds? 
>> > 
>>
>> Create a function that loop forever and loop the map to check the time, 
>> then run the function using goroutine before you start your HTTP server. 
>>
>> > } else { 
>> > common.WriteError(response, common.ErrMethodNotAllowed) 
>> > return 
>> > } 
>> > } 
>> > 
>>
>>
>>
>>

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

Re: [go-nuts] Any general VPN(pptp, l2tp, openVPN, IPSec VPN) server implementation in go?

2020-11-17 Thread Mohamed Yousif
How about wireguard[1]?

[1]: https://git.zx2c4.com/wireguard-go/about/

On Tue, 17 Nov 2020, 12:34 pm Nathan,  wrote:

> Hi, I want to use a general VPN protocols to comminucate with my server,
> we cannot change the client to use other VPN protocols.
> But I did a lot of research, it seems there is no go implementation for
> the general VPN.
>
> I really want that I'm wrong, so do any guys can give me some suggestion?
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/86cecadb-81c2-46eb-8025-332cb456d9fan%40googlegroups.com
> 
> .
>

-- 
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/CAHrL7wHk8YoY4nvOe%3D%3DYEPp83uf2X4b_cDgD_%2BRM%3DiN%2BoawrEA%40mail.gmail.com.


[go-nuts] Any general VPN(pptp, l2tp, openVPN, IPSec VPN) server implementation in go?

2020-11-17 Thread Nathan
Hi, I want to use a general VPN protocols to comminucate with my server, we 
cannot change the client to use other VPN protocols.
But I did a lot of research, it seems there is no go implementation for the 
general VPN.

I really want that I'm wrong, so do any guys can give me some suggestion? 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/86cecadb-81c2-46eb-8025-332cb456d9fan%40googlegroups.com.


[go-nuts] gopls reports "Error loading workspace folders" for every project I have

2020-11-17 Thread Johann Höchtl

I updated to gopls version golang.org/x/tools/gopls v0.5.3 
golang.org/x/tools/gopls@v0.5.3 
h1:C8QSrqjqaVzlVoHL1R9yWbROoOApRgI8gN1G+cHlPuw=

Since then my vim-go plugin but also if I disable vim-go and use vims 
native lsp-configuration reports


Error loading workspace folders (expected 1, got 0) 
failed to load view for 
file:///home/john/src/gocode/src/github.com/the42/woctoa 
pi: failed to get workspace configuration from client 
(file:///home/john/src/goc 
ode/src/github.com/the42/woctoapi): MethodNotFound 

I get this for module-enabled projects and those without a go.mod file.

All my projects are within GOPATH though.

What's the issue?

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/dd81970c-aa9f-4edf-81c4-538a8e6b1d39n%40googlegroups.com.


[go-nuts] WebAssembly and Goroutines

2020-11-17 Thread W. Michael Petullo
I am having trouble understanding the model for Goroutines within
WebAssembly.

I have a "click" callback with the following form:

errChan := make(chan error, 1)

go func() {
// Call http.PostForm and read response.

if err != nil {
errChan <- err
return
}

// ...
}()

select {
case err := <-errChan:
if err != nil {
// Handle error.
}
case <-time.After(timeout):
// Handle timeout.
}

I had expected http.PostForm to proceed, with the timeout expiring only
if http.PostForm took too long. Yet it seems that http.PostForm blocks
until after the timeout expires. Indeed, the http.PostForm call will not
return until the timer expires, no matter what value I set the timer to.

I setup the above callback (named fork) using:

wasm.AddEventListener(link, "click", js.FuncOf(
func(this js.Value, args []js.Value) interface{} {
return js.FuncOf(fork).Invoke(file)
}))

Does anyone have any recommended reading for performing HTTP requests
from WebAssembly callbacks?

-- 
Mike

:wq

-- 
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/20201117083647.GA254219%40imp.flyn.org.


Re: [go-nuts] How to detect HTTP client stop polling at the server side

2020-11-17 Thread Anderson Queiroz
Just one thing to keep in mind. Likely you have more than one serve 
instance running to process the requests. Thus it might happen the client 
will poll a different server on every request. Just imagine you have 
servers A, B, C behind a load balance and the domain example.com. As the 
client is pooling example.com, the first request might reach A, the second 
B and the third C. Now you have the 3 servers tracking the same client. It 
might happen server A doesn't receive any request from the client for a 
while, but not because the client isn't pooling any more, but because all 
requests are being directed to either B or C.

On Tuesday, 17 November 2020 at 07:12:18 UTC+1 Shulhan wrote:

>
>
> > On 16 Nov 2020, at 16.24, Afriyie Abraham Kwabena  
> wrote:
> > 
> > Hi ,
> > 
> > You are right but am new to programming and currently this what i have 
> done.
> > I have an http server handler that receives the PATCH request and stores 
> the id and the current time stamp of the request.
> > But my problem is how to write the worker function to do the clean up 
> every X seconds.
> > 
> > Code:
> > func UpdateData(response http.ResponseWriter, request *http.Request) {
> > 
> > var (
> > localVarHTTPMethod = http.MethodPatch
> > patchItems model.PatchItem
> > )
> > 
> > id := config.GetIdFromRequest(request)
> > 
> > if request.Method == localVarHTTPMethod {
> > 
> > err := json.NewDecoder(request.Body).Decode()
> > if err != nil {
> > common.WriteError(response, common.ErrBadRequest)
> > return
> > }
> > 
> > defer request.Body.Close()
> > 
> > var idtime = make(map[string]string)
> > 
> > delete(idtime, id) // delete if already exist 
> > idtime[id] = time.Now() // store id and time stamp in map 
>
> You should store idtime inside the server/service type (the one that have 
> HTTP handlers). For example,
>
> 
> type Server struct {
> idtime map[string]string
> }
>
> func (my *Server) UpdateData(...) {
> ...
> my.idtime[id] = time.Now()
> ...
> }
> 
>
> > 
> > // how do i write a worker to the clean up after every X seconds? 
> > 
>
> Create a function that loop forever and loop the map to check the time, 
> then run the function using goroutine before you start your HTTP server.
>
> > } else {
> > common.WriteError(response, common.ErrMethodNotAllowed)
> > return
> > }
> > }
> > 
>
>
>
>

-- 
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/75e53871-6821-4ef6-8eb5-a7cb9062fb53n%40googlegroups.com.