Re: [go-nuts] missing $GOPATH

2019-09-26 Thread Dan Kortschak
Looking into it it appears that there's active work in
go/build.defaultGOPATH that makes returning an informative error
message impossible.

This made sense when it was done in 428df5e39c0[1], but since then
57568958774[2] has gone in which changes the message from something
that was useful to something that is now almost devoid of information.

was:
```
go install: no install location for directory
/home/user/src/path.org/to/package outside GOPATH
For more details see: 'go help gopath'
```

now:
```
missing $GOPATH
```

ISTM that the warning provided before 428df5e39c0 is now the better
option in terms of confusion. Perhaps that warning could be an error so
that functional behaviour that exists now would remain, but with an
actual explanation. Stopping with this error would be helpful:

```
warning: GOPATH set to GOROOT (/home/user/go) has no effect
```


[1]https://go-review.googlesource.com/c/go/+/33105/
[2]https://go-review.googlesource.com/c/go/+/118095/


On Fri, 2019-09-27 at 12:51 +0930, Dan Kortschak wrote:
> Yes, that explains it. Perhaps the error could be more informative.
> 
> On Thu, 2019-09-26 at 20:19 -0700, Ian Lance Taylor wrote:
> > On Thu, Sep 26, 2019 at 7:36 PM Dan Kortschak 
> > wrote:
> > > 
> > > I am looking at some changes we have made to make code generation
> > > independent of GOPATH since from the SettingGOPATH page of the
> > > wiki
> > > says "If no GOPATH is set, it is assumed to be $HOME/go on Unix
> > > systems
> > > and %USERPROFILE%\go on Windows."
> > > 
> > > However, when I run `go env` I see `missing $GOPATH` in response.
> > > 
> > > ```
> > > ~ $ go env
> > > GO111MODULE="on"
> > > GOARCH="amd64"
> > > GOBIN="/home/user/bin"
> > > GOCACHE="/home/user/.cache/go-build"
> > > GOENV="/home/user/.config/go/env"
> > > GOEXE=""
> > > GOFLAGS=""
> > > GOHOSTARCH="amd64"
> > > GOHOSTOS="linux"
> > > GONOPROXY=""
> > > GONOSUMDB=""
> > > GOOS="linux"
> > > GOPATH="/home/user"
> > > GOPRIVATE=""
> > > GOPROXY="https://proxy.golang.org,direct";
> > > GOROOT="/home/user/go"
> > > GOSUMDB="sum.golang.org"
> > > GOTMPDIR=""
> > > GOTOOLDIR="/home/user/go/pkg/tool/linux_amd64"
> > > GCCGO="gccgo"
> > > AR="ar"
> > > CC="gcc"
> > > CXX="g++"
> > > CGO_ENABLED="1"
> > > GOMOD="/dev/null"
> > > CGO_CFLAGS="-g -O2"
> > > CGO_CPPFLAGS=""
> > > CGO_CXXFLAGS="-g -O2"
> > > CGO_FFLAGS="-g -O2"
> > > CGO_LDFLAGS="-g -O2"
> > > PKG_CONFIG="pkg-config"
> > > GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-
> > > prefix-
> > > map=/tmp/go-build038144482=/tmp/go-build -gno-record-gcc-
> > > switches"
> > > ~ $ unset GOPATH
> > > ~ $ go env
> > > missing $GOPATH
> > > ```
> > > 
> > > Is this expected now?
> > 
> > The problem you are encountering is that /home/user/go is already
> > being used for GOROOT, so it can't be used for GOPATH.  If the
> > default
> > location is unavailable, there is no fallback, so you get "missing
> > $GOPATH".
> > 
> > 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/9e977076b90f6d1f0477f9dbc3ac48dc74bb9e69.camel%40kortschak.io.


Re: [go-nuts] gnet: a high-performance, lightweight, nonblocking, event-loop networking library written in pure Go

2019-09-26 Thread Seth Bunce
Really interesting work.

(observation)
The goroutine approach uses coroutines and abstracts i/o muxing in the
language. The downside is having a bunch of coroutines (stacks sitting in
memory) waiting for i/o completion. Directly dealing with the i/o muxing
system calls requires communicating between an i/o thread and a worker
thread (the reactor pattern). Bolting a thread pool to that for i/o
completions (the proactor pattern, which is what I believe this package
implements) implies that workers processing i/o completions must avoid
blocking, which implies complexity. The go approach seems to be a memory
for complexity tradeoff. I suspect that it's not worth bypassing the
goroutine abstraction for "almost" all applications.

(opinion)
The gnet package seems less appealing in the context of go because the
goroutine abstraction scales quite high and abstracts away complexity. I
think that there are levels of performance that go cannot achieve without
direct use of i/o muxer system calls. I think that achieving these levels
of performance requires removing the abstraction between i/o muxing an
application logic which is a very heavy cost. If the gnet package is
successful it'll be because it's a dependency of a project that cannot
achieve competitive performance without it. I suspect those use cases exist.

Seth

On Thu, Sep 26, 2019 at 7:19 PM  wrote:

> Github Page:
>
> https://github.com/panjf2000/gnet
>
> gnet is an Event-Loop networking framework that is fast and small. It
> makes direct epoll  and kqueue
>  syscalls rather than using the
> standard Go net  package, and works in a
> similar manner as libuv  and libevent
> .
>
> gnet sells itself as a high-performance, lightweight, nonblocking network
> library written in pure Go which works on transport layer with
> TCP/UDP/Unix-Socket protocols, so it allows developers to implement their
> own protocols of application layer upon gnet for building diversified
> network applications, for instance, you get a HTTP Server or Web Framework
> if you implement HTTP protocol upon gnet while you have a Redis Server
> done with the implementation of Redis protocol upon gnet and so on.
>
> gnet derives from project evio while having higher performance.
>
> --
> 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/4c09ec23-0c1f-4224-99c0-d69baa9cf145%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/CAAqY8EgJa%2Bdfj4mq1LdMyumKkUbMJHyOyXqS3dRZrYO_ABM36Q%40mail.gmail.com.


Re: [go-nuts] missing $GOPATH

2019-09-26 Thread Dan Kortschak
Yes, that explains it. Perhaps the error could be more informative.

On Thu, 2019-09-26 at 20:19 -0700, Ian Lance Taylor wrote:
> On Thu, Sep 26, 2019 at 7:36 PM Dan Kortschak 
> wrote:
> > 
> > I am looking at some changes we have made to make code generation
> > independent of GOPATH since from the SettingGOPATH page of the wiki
> > says "If no GOPATH is set, it is assumed to be $HOME/go on Unix
> > systems
> > and %USERPROFILE%\go on Windows."
> > 
> > However, when I run `go env` I see `missing $GOPATH` in response.
> > 
> > ```
> > ~ $ go env
> > GO111MODULE="on"
> > GOARCH="amd64"
> > GOBIN="/home/user/bin"
> > GOCACHE="/home/user/.cache/go-build"
> > GOENV="/home/user/.config/go/env"
> > GOEXE=""
> > GOFLAGS=""
> > GOHOSTARCH="amd64"
> > GOHOSTOS="linux"
> > GONOPROXY=""
> > GONOSUMDB=""
> > GOOS="linux"
> > GOPATH="/home/user"
> > GOPRIVATE=""
> > GOPROXY="https://proxy.golang.org,direct";
> > GOROOT="/home/user/go"
> > GOSUMDB="sum.golang.org"
> > GOTMPDIR=""
> > GOTOOLDIR="/home/user/go/pkg/tool/linux_amd64"
> > GCCGO="gccgo"
> > AR="ar"
> > CC="gcc"
> > CXX="g++"
> > CGO_ENABLED="1"
> > GOMOD="/dev/null"
> > CGO_CFLAGS="-g -O2"
> > CGO_CPPFLAGS=""
> > CGO_CXXFLAGS="-g -O2"
> > CGO_FFLAGS="-g -O2"
> > CGO_LDFLAGS="-g -O2"
> > PKG_CONFIG="pkg-config"
> > GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-
> > map=/tmp/go-build038144482=/tmp/go-build -gno-record-gcc-switches"
> > ~ $ unset GOPATH
> > ~ $ go env
> > missing $GOPATH
> > ```
> > 
> > Is this expected now?
> 
> The problem you are encountering is that /home/user/go is already
> being used for GOROOT, so it can't be used for GOPATH.  If the
> default
> location is unavailable, there is no fallback, so you get "missing
> $GOPATH".
> 
> 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/ba564b7a07a05c703cca949c7c807cd9aa0c0bb7.camel%40kortschak.io.


Re: [go-nuts] missing $GOPATH

2019-09-26 Thread Ian Lance Taylor
On Thu, Sep 26, 2019 at 7:36 PM Dan Kortschak  wrote:
>
> I am looking at some changes we have made to make code generation
> independent of GOPATH since from the SettingGOPATH page of the wiki
> says "If no GOPATH is set, it is assumed to be $HOME/go on Unix systems
> and %USERPROFILE%\go on Windows."
>
> However, when I run `go env` I see `missing $GOPATH` in response.
>
> ```
> ~ $ go env
> GO111MODULE="on"
> GOARCH="amd64"
> GOBIN="/home/user/bin"
> GOCACHE="/home/user/.cache/go-build"
> GOENV="/home/user/.config/go/env"
> GOEXE=""
> GOFLAGS=""
> GOHOSTARCH="amd64"
> GOHOSTOS="linux"
> GONOPROXY=""
> GONOSUMDB=""
> GOOS="linux"
> GOPATH="/home/user"
> GOPRIVATE=""
> GOPROXY="https://proxy.golang.org,direct";
> GOROOT="/home/user/go"
> GOSUMDB="sum.golang.org"
> GOTMPDIR=""
> GOTOOLDIR="/home/user/go/pkg/tool/linux_amd64"
> GCCGO="gccgo"
> AR="ar"
> CC="gcc"
> CXX="g++"
> CGO_ENABLED="1"
> GOMOD="/dev/null"
> CGO_CFLAGS="-g -O2"
> CGO_CPPFLAGS=""
> CGO_CXXFLAGS="-g -O2"
> CGO_FFLAGS="-g -O2"
> CGO_LDFLAGS="-g -O2"
> PKG_CONFIG="pkg-config"
> GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-
> map=/tmp/go-build038144482=/tmp/go-build -gno-record-gcc-switches"
> ~ $ unset GOPATH
> ~ $ go env
> missing $GOPATH
> ```
>
> Is this expected now?

The problem you are encountering is that /home/user/go is already
being used for GOROOT, so it can't be used for GOPATH.  If the default
location is unavailable, there is no fallback, so you get "missing
$GOPATH".

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/CAOyqgcXj-DG3XwjmvN9s53s7gzxjextQHmW-y4xi7iSTqNATzg%40mail.gmail.com.


[go-nuts] missing $GOPATH

2019-09-26 Thread Dan Kortschak
I am looking at some changes we have made to make code generation
independent of GOPATH since from the SettingGOPATH page of the wiki
says "If no GOPATH is set, it is assumed to be $HOME/go on Unix systems
and %USERPROFILE%\go on Windows."

However, when I run `go env` I see `missing $GOPATH` in response.

```
~ $ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN="/home/user/bin"
GOCACHE="/home/user/.cache/go-build"
GOENV="/home/user/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/user"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct";
GOROOT="/home/user/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/user/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-
map=/tmp/go-build038144482=/tmp/go-build -gno-record-gcc-switches"
~ $ unset GOPATH
~ $ go env
missing $GOPATH
```

Is this expected now?

-- 
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/7536d03f16ae4e8fbac04aec18c1f9c7bb5d369e.camel%40kortschak.io.


[go-nuts] gnet: a high-performance, lightweight, nonblocking, event-loop networking library written in pure Go

2019-09-26 Thread panjf2000


Github Page:

https://github.com/panjf2000/gnet

gnet is an Event-Loop networking framework that is fast and small. It makes 
direct epoll  and kqueue 
 syscalls rather than using the 
standard Go net  package, and works in a 
similar manner as libuv  and libevent 
.

gnet sells itself as a high-performance, lightweight, nonblocking network 
library written in pure Go which works on transport layer with 
TCP/UDP/Unix-Socket protocols, so it allows developers to implement their 
own protocols of application layer upon gnet for building diversified 
network applications, for instance, you get a HTTP Server or Web Framework 
if you implement HTTP protocol upon gnet while you have a Redis Server done 
with the implementation of Redis protocol upon gnet and so on.

gnet derives from project evio while having higher performance.

-- 
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/4c09ec23-0c1f-4224-99c0-d69baa9cf145%40googlegroups.com.


[go-nuts] Re: [security] Go 1.13.1 and Go 1.12.10 are released

2019-09-26 Thread kddavidson722
You can find them at:

https://go.googlesource.com/go/+/refs/heads/release-branch.go1.13-security
https://github.com/golang/go/commits/release-branch.go1.13-security

https://github.com/golang/go/commits/release-branch.go1.12-security
https://go.googlesource.com/go/+/refs/heads/release-branch.go1.12-security

-- 
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/f4a050ef-91e9-4179-bfc2-89324621e425%40googlegroups.com.


Re: [go-nuts] Watches / Data breakpoints

2019-09-26 Thread David Finkel
On Thu, Sep 26, 2019 at 3:58 AM Stephen Illingworth <
stephen.t.illingwo...@gmail.com> wrote:

> Hi all,
>
> I have an awkward bug I'm trying to understand and I'm missing something
> in my toolbox. Is there any way of monitoring a variable for changes made
> to it? For example, I have a pointer type and I want a debugger to break
> whenever its value (ie. what it points to) changes.
>
> I call this a "watch" but I believe it's sometimes referred to as a "data
> breakpoint".
>
> I've looked at delve and can't see anything like it. I've had a quick look
> at VSCode and Goland and I can't see anything there either. Is there
> anything I've missed?
>
I don't see anything in Delve's docs either.
I'm pretty sure VSCode and Goland use Delve, so they won't work if Delve
doesn't.

With that said, I think gdb works to some extent with Go, and it supports
"watchpoints":
https://sourceware.org/gdb/current/onlinedocs/gdb/Set-Watchpoints.html#Set-Watchpoints
(Note: I haven't tried debugging a go binary with gdb, so I can't do much
more than point you at the manual)

>
> Help
>
> Stephen Illingworth.
>
> --
> 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/CAPmHGLPa0sgU9NkewBmZKhqVV-fZaaAni8Uaq%2BY_aUQstSEeYA%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/CANrC0BiHEFJ78n7UZ6fffPq8FChH9NiFscuz-c_XpuDo%3Dhi6DQ%40mail.gmail.com.


[go-nuts] Golang library for - ORM & Schema Migration

2019-09-26 Thread b ram
Hi,

Can you pls suggest libs for  ORM & Schema Migration.

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/CAB9V516cRxPc8xuQcXQyBGXZWenv0o9ned%2BFDq2WmXyhBNm2Sg%40mail.gmail.com.


[go-nuts] Re: Clarification on unsafe conversion between string <-> []byte

2019-09-26 Thread Serhat Şevki Dinçer
Hi,

I wrote a string utility library  with many 
tests to ensure the conversion assumptions are correct. It could be helpful.

Cheers..

On Wednesday, September 18, 2019 at 12:42:31 PM UTC+3, Francis wrote:
>
> I am looking at the correct way to convert from a byte slice to a string 
> and back with no allocations. All very unsafe.
>
> I think these two cases are fairly symmetrical. So to simplify the 
> discussion below I will only talk about converting from a string to []byte.
>
> func StringToBytes(s string) (b []byte)
>
> From what I have read it is currently not clear how to perform this 
> correctly.
>
> When I say correctly I mean that the function returns a `[]byte` which 
> contains all of and only the bytes in the string and never confuses the 
> garbage collector. We fully expect that the `[]byte` returned will contain 
> the same underlying memory as the string and modifying its contents will 
> modify the string, making the string dangerously mutable. We are 
> comfortable with the dangerously mutable string.
>
> Following the directions in unsafe you _might_ think that this would be a 
> good solution.
>
> func StringToBytes(s string) []byte {
> return *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{
> Data: (*(*reflect.StringHeader)(unsafe.Pointer(&s))).Data,
> Len:  len(s),
> Cap:  len(s),
> }))
> }
>
> The line
>
> Data: (*(*reflect.StringHeader)(unsafe.Pointer(&s))).Data,
>
> here is a really carefully commented example of this approach from github
>
> seems to satisfy unsafe  rule 5 about 
> converting uintptr to and from unsafe.Pointer in a singe expression.
>
> However, it clearly violates rule 6 which states `...SliceHeader and 
> StringHeader are only valid when interpreting the content of an actual 
> slice or string value.`. The `[]byte` we are returning here is built from a 
> `&reflect.SliceHeader` and not based on an existing `[]byte`.
>
> So we can switch to
>
> func StringToBytes(s string) (b []byte) {
> stringHeader := (*reflect.StringHeader)(unsafe.Pointer(&s))
> sliceHeader := (*reflect.SliceHeader)(unsafe.Pointer(&bytes))
> sliceHeader.Data = stringHeader.Data
> sliceHeader.Len = stringHeader.Len
> sliceHeader.Cap = stringHeader.Len
> return b
> }
>
> Now we are using an existing []byte to build `sliceHeader` which is good. 
> But we end up with a new problem. sliceHeader.Data and stringHeader.Data 
> are both uintptr. So by creating them in one expression and then writing 
> them in another expression we violate the rule that `uintptr cannot be 
> stored in variable`.
>
> There is a possible sense that we are protected because both of our 
> `uinptr`s are actually real pointers inside a real string and []byte. This 
> seems to be indicated by the line `In this usage hdr.Data is really an 
> alternate way to refer to the underlying pointer in the string header, not 
> a uintptr variable itself.`
>
> This feels very unclear to me.
>
> In particular the code example in the unsafe package
>
> var s string
> hdr := (*reflect.StringHeader)(unsafe.Pointer(&s)) // case 1
> hdr.Data = uintptr(unsafe.Pointer(p))  // case 6 (this case)
> hdr.Len = n
>
>
> is not the same as the case we are dealing with here. Specifically in the 
> unsafe package documentation we are writing from a uintpr stored in a 
> separate variable to another uinptr. They are probably very similar in 
> practice, but it isn't obvious and in my experience subtly incorrect code 
> often comes from relying on vague understandings of important documents.
>
> If we assume that our uinptrs are safe because they are backed by real 
> pointers then there is another issue with our string being garbage 
> collected.
>
> func StringToBytes(s string) (b []byte) {
> stringHeader := (*reflect.StringHeader)(unsafe.Pointer(&s))
> // Our string is no longer referenced anywhere and could 
> potentially be garbage collected
> sliceHeader := (*reflect.SliceHeader)(unsafe.Pointer(&bytes))
> sliceHeader.Data = stringHeader.Data
> sliceHeader.Len = stringHeader.Len
> sliceHeader.Cap = stringHeader.Len
> return b
> }
>
>
> There is a discussion where this potential problem is raised
>
> https://github.com/golang/go/issues/25484
>
> we also see this issue mentioned in
>
> https://groups.google.com/forum/#!msg/golang-nuts/dcjzJy-bSpw/tcZYBzQqAQAJ
>
> The solution of 
>
> func StringToBytes(s string) (b []byte) {
> stringHeader := (*reflect.StringHeader)(unsafe.Pointer(&s))
> // Our string is no longer referenced anywhere and could 
> potentially be garbage collected
> sliceHeader := (*reflect.SliceHeader)(unsafe.Pointer(&bytes))
> sliceHeader.Data = stringHeader.Data
> sliceHeader.Len = stringHeader.Len
> sliceHeader.Cap = stringHeader.Len
>   

Re: [go-nuts] Why not put contexts in structs?

2019-09-26 Thread Caleb Spare
You can read some more discussion about this recommendation at
https://github.com/golang/go/issues/22602. (That's where I propose
relaxing it somewhat, since I think the current phrasing is too
strict.)

On Tue, Sep 24, 2019 at 7:42 PM  wrote:
>
> I've read the documentation recommended never to store a context in a struct. 
>  I'm curious to know why that's a bad thing.  Is it just because context is 
> request-scoped, and the struct may not be?  Or is there more to it than that? 
>  In other words, what can go wrong if you store a context in a struct?
>
>
> (And what do we actually mean by request-scoped? Do we specifically mean "a 
> chain of function calls" or do we mean something more conceptual, like a 
> "request" received by a server?)
>
> --
> 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/dad8b56c-add0-49bc-b53e-f4238f19ae4f%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/CAGeFq%2BkzVWRW8%2BVCsPVSC7sRQqw%2Bh2zwA0bo0jL349HBuFx3MQ%40mail.gmail.com.


Re: [go-nuts] JWT validation only in Middleware

2019-09-26 Thread burak serdar
On Thu, Sep 26, 2019 at 1:14 PM Martin Palma  wrote:
>
> Hello,
>
> I'm in the process of writing an HTTP API with Go. I use a middleware for 
> generating and validating JWT tokens. On any incoming request the middleware 
> checks the JWT and validates it. If valid it adds it to the request header 
> and calls the next handler.
>
> Is it save to use the JWT in the next handler without validating it again and 
> using the claims?

If you make sure you have those two handlers in that order, then the
answer is yes.

Another approach is to validate the JWT in the first handler, and put
the claims into the request context for the next handler, so the next
handler doesn't even deal with the JWT, and gets the claims from the
context. This assumes the second handler won't be called if JWT
doesn't validate.

>
> Best,
> Martin
>
> --
> 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/69d031e5-2a11-4904-84d6-1e67c0bc85a9%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/CAMV2RqqOm-gMTzBp3tn796R5HmM8Lm6Cpg%3D4giZAViZzn4Nn1A%40mail.gmail.com.


[go-nuts] Re: Why not put contexts in structs?

2019-09-26 Thread anderson . queiroz
Well, one of the reasons is convention. The context should be passes as 
paramter and be the first paramter as is stated in the package 
documentation.
For sure following the convention it's easier to know where the context 
came from, when it's available.
Inside a struct it's somehow hidden, might not obivious there is a context 
there, or end up being replaced rather than updated.

It's what I have in my mind.



On Wednesday, 25 September 2019 04:43:17 UTC+2, john...@gmail.com wrote:
>
> I've read the documentation recommended never to store a context in a 
> struct.  I'm curious to know why that's a bad thing.  Is it just because 
> context is request-scoped, and the struct may not be?  Or is there more to 
> it than that?  In other words, what can go wrong if you store a context in 
> a struct?
>
>
> (And what do we actually mean by request-scoped? Do we specifically mean 
> "a chain of function calls" or do we mean something more conceptual, like a 
> "request" received by a server?)
>

-- 
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/6e687648-2aa6-4da3-9387-685705ff3fc9%40googlegroups.com.


[go-nuts] JWT validation only in Middleware

2019-09-26 Thread Martin Palma
Hello,

I'm in the process of writing an HTTP API with Go. I use a middleware for 
generating and validating JWT tokens. On any incoming request the 
middleware checks the JWT and validates it. If valid it adds it to the 
request header and calls the next handler. 

Is it save to use the JWT in the next handler without validating it again 
and using the claims?

Best,
Martin

-- 
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/69d031e5-2a11-4904-84d6-1e67c0bc85a9%40googlegroups.com.


[go-nuts] Re: go 1.13 won't compile

2019-09-26 Thread Robert Solomon
Should I file an 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/b341bb68-818c-4f7c-a4c9-8de4910358a9%40googlegroups.com.


[go-nuts] Re: nil map assignment panics. can we do better?

2019-09-26 Thread abuchanan via golang-nuts
Changing how people use maps, or how the language defines/implements maps, 
feels like a dead end.

I tried the nil-map-assignment static analysis provided by staticcheck.io, 
but it didn't find our most bug unfortunately. So maybe we need to think 
about how to implement better static analysis for this.

-- 
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/65e2183d-27bd-4430-b88d-cea98d53c277%40googlegroups.com.


[go-nuts] Re: Go Time #100 with Robert Griesemer and myself

2019-09-26 Thread B Carr
This was interesting. Thank you!

On Wednesday, September 25, 2019 at 5:14:51 PM UTC-6, Rob 'Commander' Pike 
wrote:
>
> It's now live: https://changelog.com/gotime/100 
> 
>
> -rob
>
>

-- 
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/8b009699-d0c2-40de-92d8-9d1fb44f47e2%40googlegroups.com.


[go-nuts] InfluxData is hiring remote Go engineers

2019-09-26 Thread mark
InfluxData is the leading open source time series database, purpose built 
for
monitoring metrics and events. We are expanding our talented engineering
organization, and we are hiring for a lot of positions that primarily 
include
programming in Go.

I am personally one of Influx's first engineering hires from nearly five 
years
ago, and now our engineering department has grown to around 60 engineers. 
If I
can answer any questions about any of the below positions, please reach out 
to
me at my first name @influxdata.com.

All of the below positions are remote. We are currently hiring in the UK,
Germany, Italy, and the following US states: AZ, CA, CO, CT, GA, ID, IL, MA,
MN, NC, NJ, NY, OH, OR, TX, UT, VA, and WA.

Database Engineer, Query Engines (https://grnh.se/2b5fee851)

Engineers on this team build our open source query engine, Flux:
https://github.com/influxdata/flux

We are looking for people with experience building query processors, query
engines, query optimizers, or stream processing systems.

Principal Database Engineer (https://grnh.se/542136e21)
===
This is a senior position on the team that builds the core storage engine 
for
influxdb.

Senior Software Engineer, Telegraf (https://grnh.se/37a885101)
==
This is a senior position on the team building out the Telegraf agent for
collecting and reporting many metrics.

Telegraf (https://github.com/influxdata/telegraf) is a large open source
project that interfaces with a considerable number of external systems and
libraries. Engineers on this team very frequently interact with the OSS
community on GitHub.

Senior Kubernetes / Continuous Delivery Engineer (https://grnh.se/e15748de1)

We are looking for engineers with experience guiding engineering 
organizations
towards continuous delivery patterns, efficiently deploying software to
multiple Kubernetes clusters running in multiple cloud providers. We are 
always
looking to improve our CI/CD pipeline as well. If you have experience in 
this
domain and are opinionated, I would love to hear from you as this is the 
team I
am personally leading right now.

Senior Software Engineer, Backend (https://grnh.se/527323fe1)
=
This is a senior position on the team responsible for the backend APIs (both
REST and gRPC) of our cloud services.

Please see https://grnh.se/ygda3s for a full list of open positions, 
including
other engineering roles such as:
- Security Engineer
- Site Reliability Engineer
- Engineering, Ecommerce (using Elixir and JavaScript)
- User Interface Engineer (using TypeScript and React)

and some non-engineering roles too, such as customer success, marketing, and
technical writing.

If nothing above looks like the right fit, but you feel like you would be a
good fit for the company, feel free to apply to the Talent Community link:
https://grnh.se/7a623e4b1

-- 
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/a07913be-9ded-463f-840f-eb1624f2cd7d%40googlegroups.com.


[go-nuts] WAIT_TIMEOUT inconsistency in golang.org/x/sys/windows

2019-09-26 Thread Marvin Renich
In golang.org/x/sys/windows, the WAIT_* return codes from
WaitForSingleObject and WaitForMultipleObjects are defined as untyped
integer constants except for WAIT_TIMEOUT, which is a syscall.Errno.

All the other syscall.Errno values less than 1700 (the first RPC_ error)
begin with ERROR_.

The WaitFor* functions above return WAIT_TIMEOUT as a uint32, not as an
error.  WAIT_TIMEOUT being an Errno makes using these functions slightly
more complicated.

I think the syscall.Errno should have been named ERROR_WAIT_TIMEOUT and
WAIT_TIMEOUT should have been an untyped constant.

The worst part about this situation is not that a type conversion is
required on the WAIT_TIMEOUT constant to make it useful, but the
cognitive load required to arrive at that solution.  Whether you realize
when first writing the code that WAIT_TIMEOUT is differently typed than
WAIT_OBJECT_0 and WAIT_ABANDONED or you find out the first time you
compile, you must then realize that windows.Errno is a type alias for
syscall.Errno, which is a uintptr, and the value for WAIT_TIMEOUT is
small enough to be safely converted to uint32 to match the return type
of the WaitFor* functions.

Even if you are already familiar with Errno, this is a moderate and
completely unnecessary cognitive load.  If you are not familiar, you
must read documentation or source code for both x/sys/windows and
syscall to resolve the issue.

To make things worse, syscall got it right!  syscall.WAIT_TIMEOUT is an
untyped integer constant.

Are there any other Windows API functions other than WaitFor*Object*
that use or return WAIT_TIMEOUT?  As far as I can tell, WAIT_TIMEOUT is
only used in a context where WAIT_OBJECT_0 and WAIT_ABANDONED are also
used.

Normally, I would hesitate to encourage changing this, but golang.org/x
is explicitly excluded from the compatibility guarantee to allow
incompatible changes that improve its usefulness, which I think this
change would do.  Anyone currently using WAIT_TIMEOUT would have the
choice of using gofmt (or their favorite editor) to rename it to
ERROR_WAIT_TIMEOUT or vendoring golang.org/x/sys.

I suspect many current uses of WAIT_TIMEOUT are in a switch statement as
uint32(windows.WAIT_TIMEOUT), which would compile just fine with the
change.

Thoughts?

...Marvin

-- 
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/20190926152241.pmhewuprsol465rk%40basil.wdw.


[go-nuts] Chimithèque v2 released

2019-09-26 Thread Thomas Bellembois
Hello Gophers,

I have released a chemical products management application for schools
and universities (or others).

https://github.com/tbellembois/gochimitheque

This is a project started in 2015 that has been rewritten in Go.

This may interest chemical engineers or teachers.

Regards,

Thomas

-- 
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/00edaad62ed71edd9939093c2b53298c5726f3de.camel%40gmail.com.


[go-nuts] How to search for string value in array

2019-09-26 Thread afriyie . abraham


I have trying to write a function that will accept a string as an input and 
return another string in a slice but it not working. I have function that 
unmarshal udp response to a type AuthVectors and then append the type 
struct data into an array authVecSlice. Below is the code

type AuthVectors struct {

MessageType string `json:"message_type"`

IMSIstring `json:"IMSI"`

RANDstring `json:"RAND"`

XRESstring `json:"XRES"`

AUTNstring `json:"AUTN"`

}

var imsistr = "2443411" 

var authVecSlice = make([]AuthVectors, 10)


func getAuthVec() {

hostName := "localhost"

portNum := "4343"

service := hostName + ":" + portNum

RemoteAddr, err := net.ResolveUDPAddr("udp", service)

conn, err := net.DialUDP("udp", nil, RemoteAddr)

if err != nil {

log.Fatal(err)

}

defer conn.Close()

// write a message to server

_, err = conn.Write([]byte(imsistr))

if err != nil {

log.Println(err)

}

// receive message from server

buffer := make([]byte, 1024)

i, _, err := conn.ReadFromUDP(buffer)

checkError(err)


err = json.Unmarshal(buffer[:i], &avs)

if err != nil {

panic(err)

}

authVecSlice = append(authVecSlice, avs)

fmt.Println(authVecSlice)

}

The array out put is as follows

[{AUTN_PARAM 2443411 C98FC7C6DE9E1351A397D0AF99B6E890 
D857E39D57E5E6BE 8000...} {AUTN_PARAM 2443411 
211B025CB1CC8EE9CBB5FC7F56C1506B C9396A5AC7E68D62 31D...} {AUTN_PARAM 
2443411 7D2A8C6E6B5CA243278987DFAF7FC829 C9EE960D0F5A501A 7E8..} 
...]

I would like to use the field RAND to search and return the corresponding 
XRES in the array. For example in the array is

{AUTN_PARAM 2443411 C98FC7C6DE9E1351A397D0AF99B6E890 
D857E39D57E5E6BE 8000...}

I would like to use the RAND value for example 
C98FC7C6DE9E1351A397D0AF99B6E890 as a search string and return its 
corresponding XRES D857E39D57E5E6BE.

func getXRES(a []AuthVectors, x interface{}) (xres string) {

for _, v := range a {

if x == v {

xres := v.XRES

return xres

}

}

return "Item not found"

}

The problem for me is that the array value do not have key to be use to 
perform the search. All example I found involves the use of key to fetch 
the values. 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/ca9a0f00-9fdc-4383-b58a-31780d0ae45d%40googlegroups.com.


[go-nuts] How to search for string value in array

2019-09-26 Thread afriyie . abraham


I have trying to write a function that will accept a string as an input and 
return another string in a slice but it not working. I have function that 
unmarshal udp response to a type AuthVectors and then append the type 
struct data into an array authVecSlice. Below is the code

type AuthVectors struct {

MessageType string `json:"message_type"`

IMSIstring `json:"IMSI"`

RANDstring `json:"RAND"`

XRESstring `json:"XRES"`

AUTNstring `json:"AUTN"`

}

var imsistr = "2443411" 

var authVecSlice = make([]AuthVectors, 10)


func getAuthVec() {

hostName := "localhost"

portNum := "4343"

service := hostName + ":" + portNum

RemoteAddr, err := net.ResolveUDPAddr("udp", service)

conn, err := net.DialUDP("udp", nil, RemoteAddr)

if err != nil {

log.Fatal(err)

}

defer conn.Close()

// write a message to server

_, err = conn.Write([]byte(imsistr))

if err != nil {

log.Println(err)

}

// receive message from server

buffer := make([]byte, 1024)

i, _, err := conn.ReadFromUDP(buffer)

checkError(err)

err = json.Unmarshal(buffer[:i], &avs)

if err != nil {

panic(err)

}

authVecSlice = append(authVecSlice, avs)

fmt.Println(authVecSlice)

}

The array out put is as follows

[{AUTN_PARAM 2443411 C98FC7C6DE9E1351A397D0AF99B6E890 
D857E39D57E5E6BE 8000...} {AUTN_PARAM 2443411 
211B025CB1CC8EE9CBB5FC7F56C1506B C9396A5AC7E68D62 31D...} {AUTN_PARAM 
2443411 7D2A8C6E6B5CA243278987DFAF7FC829 C9EE960D0F5A501A 7E8..} 
...]

I would like to use the field RAND to search and return the corresponding 
XRES in the array. For example in the array is

{AUTN_PARAM 2443411 C98FC7C6DE9E1351A397D0AF99B6E890 
D857E39D57E5E6BE 8000...}

I would like to use the RAND value for example 
C98FC7C6DE9E1351A397D0AF99B6E890 as a search string and return its 
corresponding XRES D857E39D57E5E6BE.

func getXRES(a []AuthVectors, x interface{}) (xres string) {

for _, v := range a {

if x == v {

xres := v.XRES

return xres

}

}

return "Item not found"

}

The problem for me is that the array value do not have key to be use to 
perform the search. All example I found involves the use of key to fetch 
the values. 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/42adcb63-ca63-4bc1-ad6f-5eeb64542d46%40googlegroups.com.


[go-nuts] How to search for string value in array

2019-09-26 Thread afriyie . abraham


I have trying to write a function that will accept a string as an input and 
return another string in a slice but it not working. I have function that 
unmarshal udp response to a type AuthVectors and then append the type 
struct data into an array authVecSlice. Below is the code

type AuthVectors struct {

MessageType string `json:"message_type"`

IMSIstring `json:"IMSI"`

RANDstring `json:"RAND"`

XRESstring `json:"XRES"`

AUTNstring `json:"AUTN"`

}

var imsistr = "2443411" 

var authVecSlice = make([]AuthVectors, 10)


func getAuthVec() {

hostName := "localhost"

portNum := "4343"

service := hostName + ":" + portNum

RemoteAddr, err := net.ResolveUDPAddr("udp", service)

conn, err := net.DialUDP("udp", nil, RemoteAddr)

if err != nil {

log.Fatal(err)

}

defer conn.Close()

// write a message to server

_, err = conn.Write([]byte(imsistr))

if err != nil {

log.Println(err)

}

// receive message from server

buffer := make([]byte, 1024)

i, _, err := conn.ReadFromUDP(buffer)

checkError(err)

err = json.Unmarshal(buffer[:i], &avs)

if err != nil {

panic(err)

}

authVecSlice = append(authVecSlice, avs)

fmt.Println(authVecSlice)

}

The array out put is as follows

[{AUTN_PARAM 2443411 C98FC7C6DE9E1351A397D0AF99B6E890 
D857E39D57E5E6BE 8000...} {AUTN_PARAM 2443411 
211B025CB1CC8EE9CBB5FC7F56C1506B C9396A5AC7E68D62 31D...} {AUTN_PARAM 
2443411 7D2A8C6E6B5CA243278987DFAF7FC829 C9EE960D0F5A501A 7E8..} 
...]

I would like to use the field RAND to search and return the corresponding 
XRES in the array. For example in the array is

{AUTN_PARAM 2443411 C98FC7C6DE9E1351A397D0AF99B6E890 
D857E39D57E5E6BE 8000...}

I would like to use the RAND value for example 
C98FC7C6DE9E1351A397D0AF99B6E890 as a search string and return its 
corresponding XRES D857E39D57E5E6BE.

func getXRES(a []AuthVectors, x interface{}) (xres string) {

for _, v := range a {

if x == v {

xres := v.XRES

return xres

}

}

return "Item not found"

}

The problem for me is that the array value do not have key to be use to 
perform the search. All example I found involves the use of key to fetch 
the values. 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/5ca278a8-e5ec-45ff-a056-018e57fa2d49%40googlegroups.com.


[go-nuts] How to search for string value in array

2019-09-26 Thread afriyie . abraham


I have trying to write a function that will accept a string as an input and 
return another string in a slice but it not working. I have function that 
unmarshal udp response to a type AuthVectors and then append the type 
struct data into an array authVecSlice. Below is the code

type AuthVectors struct {

MessageType string `json:"message_type"`

IMSIstring `json:"IMSI"`

RANDstring `json:"RAND"`

XRESstring `json:"XRES"`

AUTNstring `json:"AUTN"`

}

var imsistr = "2443411" 

var authVecSlice = make([]AuthVectors, 10)


func getAuthVec() {

hostName := "localhost"

portNum := "4343"

service := hostName + ":" + portNum

RemoteAddr, err := net.ResolveUDPAddr("udp", service)

conn, err := net.DialUDP("udp", nil, RemoteAddr)

if err != nil {

log.Fatal(err)

}

defer conn.Close()

// write a message to server

_, err = conn.Write([]byte(imsistr))

if err != nil {

log.Println(err)

}

// receive message from server

buffer := make([]byte, 1024)

i, _, err := conn.ReadFromUDP(buffer)

checkError(err)

err = json.Unmarshal(buffer[:i], &avs)

if err != nil {

panic(err)

}

authVecSlice = append(authVecSlice, avs)

fmt.Println(authVecSlice)

}

The array out put is as follows

[{AUTN_PARAM 2443411 C98FC7C6DE9E1351A397D0AF99B6E890 
D857E39D57E5E6BE 8000...} {AUTN_PARAM 2443411 
211B025CB1CC8EE9CBB5FC7F56C1506B C9396A5AC7E68D62 31D...} {AUTN_PARAM 
2443411 7D2A8C6E6B5CA243278987DFAF7FC829 C9EE960D0F5A501A 7E8..} 
...]

I would like to use the field RAND to search and return the corresponding 
XRES in the array. For example in the array is

{AUTN_PARAM 2443411 C98FC7C6DE9E1351A397D0AF99B6E890 
D857E39D57E5E6BE 8000...}

I would like to use the RAND value for example 
C98FC7C6DE9E1351A397D0AF99B6E890 as a search string and return its 
corresponding XRES D857E39D57E5E6BE.

func getXRES(a []AuthVectors, x interface{}) (xres string) {

for _, v := range a {

if x == v {

xres := v.XRES

return xres

}

}

return "Item not found"

}

The problem for me is that the array value do not have key to be use to 
perform the search. All example I found involves the use of key to fetch 
the values. 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/a2f7571c-7742-4586-840c-0c52db839a45%40googlegroups.com.


[go-nuts] How to search for string value in array

2019-09-26 Thread afriyie . abraham


I have trying to write a function that will accept a string as an input and 
return another string in a slice but it not working. I have function that 
unmarshal udp response to a type AuthVectors and then append the type 
struct data into an array authVecSlice. Below is the code

type AuthVectors struct {

MessageType string `json:"message_type"`

IMSIstring `json:"IMSI"`

RANDstring `json:"RAND"`

XRESstring `json:"XRES"`

AUTNstring `json:"AUTN"`

}

var imsistr = "2443411" 

var authVecSlice = make([]AuthVectors, 10)


func getAuthVec() {

hostName := "localhost"

portNum := "4343"

service := hostName + ":" + portNum

RemoteAddr, err := net.ResolveUDPAddr("udp", service)

conn, err := net.DialUDP("udp", nil, RemoteAddr)

if err != nil {

log.Fatal(err)

}

defer conn.Close()

// write a message to server

_, err = conn.Write([]byte(imsistr))

if err != nil {

log.Println(err)

}

// receive message from server

buffer := make([]byte, 1024)

i, _, err := conn.ReadFromUDP(buffer)

checkError(err)

err = json.Unmarshal(buffer[:i], &avs)

if err != nil {

panic(err)

}

authVecSlice = append(authVecSlice, avs)

fmt.Println(authVecSlice)

}

The array out put is as follows

[{AUTN_PARAM 2443411 C98FC7C6DE9E1351A397D0AF99B6E890 
D857E39D57E5E6BE 8000...} {AUTN_PARAM 2443411 
211B025CB1CC8EE9CBB5FC7F56C1506B C9396A5AC7E68D62 31D...} {AUTN_PARAM 
2443411 7D2A8C6E6B5CA243278987DFAF7FC829 C9EE960D0F5A501A 7E8..} 
...]

I would like to use the field RAND to search and return the corresponding 
XRES in the array. For example in the array is

{AUTN_PARAM 2443411 C98FC7C6DE9E1351A397D0AF99B6E890 
D857E39D57E5E6BE 8000...}

I would like to use the RAND value for example 
C98FC7C6DE9E1351A397D0AF99B6E890 as a search string and return its 
corresponding XRES D857E39D57E5E6BE.

func getXRES(a []AuthVectors, x interface{}) (xres string) {

for _, v := range a {

if x == v {

xres := v.XRES

return xres

}

}

return "Item not found"

}

The problem for me is that the array value do not have key to be use to 
perform the search. All example I found involves the use of key to fetch 
the values. 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/729f0972-5637-4a0e-8a7a-283bd8541d71%40googlegroups.com.


[go-nuts] How to search for string value in array

2019-09-26 Thread afriyie . abraham


I have trying to write a function that will accept a string as an input and 
return another string in a slice but it not working. I have function that 
unmarshal udp response to a type AuthVectors and then append the type 
struct data into an array authVecSlice. Below is the code

type AuthVectors struct {

MessageType string `json:"message_type"`

IMSIstring `json:"IMSI"`

RANDstring `json:"RAND"`

XRESstring `json:"XRES"`

AUTNstring `json:"AUTN"`

}

var imsistr = "2443411" 

var authVecSlice = make([]AuthVectors, 10)


func getAuthVec() {

hostName := "localhost"

portNum := "4343"

service := hostName + ":" + portNum

RemoteAddr, err := net.ResolveUDPAddr("udp", service)

conn, err := net.DialUDP("udp", nil, RemoteAddr)

if err != nil {

log.Fatal(err)

}

defer conn.Close()

// write a message to server

_, err = conn.Write([]byte(imsistr))

if err != nil {

log.Println(err)

}

// receive message from server

buffer := make([]byte, 1024)

i, _, err := conn.ReadFromUDP(buffer)

checkError(err)

err = json.Unmarshal(buffer[:i], &avs)

if err != nil {

panic(err)

}

authVecSlice = append(authVecSlice, avs)

fmt.Println(authVecSlice)

}

The array out put is as follows

[{AUTN_PARAM 2443411 C98FC7C6DE9E1351A397D0AF99B6E890 
D857E39D57E5E6BE 8000...} {AUTN_PARAM 2443411 
211B025CB1CC8EE9CBB5FC7F56C1506B C9396A5AC7E68D62 31D...} {AUTN_PARAM 
2443411 7D2A8C6E6B5CA243278987DFAF7FC829 C9EE960D0F5A501A 7E8..} 
...]

I would like to use the field RAND to search and return the corresponding 
XRES in the array. For example in the array is

{AUTN_PARAM 2443411 C98FC7C6DE9E1351A397D0AF99B6E890 
D857E39D57E5E6BE 8000...}

I would like to use the RAND value for example 
C98FC7C6DE9E1351A397D0AF99B6E890 as a search string and return its 
corresponding XRES D857E39D57E5E6BE.

func getXRES(a []AuthVectors, x interface{}) (xres string) {

for _, v := range a {

if x == v {

xres := v.XRES

return xres

}

}

return "Item not found"

}

The problem for me is that the array value do not have key to be use to 
perform the search. All example I found involves the use of key to fetch 
the values. 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/f458b87c-0611-4270-8ee0-ac20019d731c%40googlegroups.com.


[go-nuts] How to search for string value in array

2019-09-26 Thread afriyie . abraham


I have trying to write a function that will accept a string as an input and 
return another string in a slice but it not working. I have function that 
unmarshal udp response to a type AuthVectors and then append the type 
struct data into an array authVecSlice. Below is the code

type AuthVectors struct {

MessageType string `json:"message_type"`

IMSIstring `json:"IMSI"`

RANDstring `json:"RAND"`

XRESstring `json:"XRES"`

AUTNstring `json:"AUTN"`

}

var imsistr = "2443411" 

var authVecSlice = make([]AuthVectors, 10)


func getAuthVec() {

hostName := "localhost"

portNum := "4343"

service := hostName + ":" + portNum

RemoteAddr, err := net.ResolveUDPAddr("udp", service)

conn, err := net.DialUDP("udp", nil, RemoteAddr)

if err != nil {

log.Fatal(err)

}

defer conn.Close()

// write a message to server

_, err = conn.Write([]byte(imsistr))

if err != nil {

log.Println(err)

}

// receive message from server

buffer := make([]byte, 1024)

i, _, err := conn.ReadFromUDP(buffer)

checkError(err)

err = json.Unmarshal(buffer[:i], &avs)

if err != nil {

panic(err)

}

authVecSlice = append(authVecSlice, avs)

fmt.Println(authVecSlice)

}

The array out put is as follows

[{AUTN_PARAM 2443411 C98FC7C6DE9E1351A397D0AF99B6E890 
D857E39D57E5E6BE 8000...} {AUTN_PARAM 2443411 
211B025CB1CC8EE9CBB5FC7F56C1506B C9396A5AC7E68D62 31D...} {AUTN_PARAM 
2443411 7D2A8C6E6B5CA243278987DFAF7FC829 C9EE960D0F5A501A 7E8..} 
...]

I would like to use the field RAND to search and return the corresponding 
XRES in the array. For example in the array is

{AUTN_PARAM 2443411 C98FC7C6DE9E1351A397D0AF99B6E890 
D857E39D57E5E6BE 8000...}

I would like to use the RAND value for example 
C98FC7C6DE9E1351A397D0AF99B6E890 as a search string and return its 
corresponding XRES D857E39D57E5E6BE.

func getXRES(a []AuthVectors, x interface{}) (xres string) {

for _, v := range a {

if x == v {

xres := v.XRES

return xres

}

}

return "Item not found"

}

The problem for me is that the array value do not have key to be use to 
perform the search. All example I found involves the use of key to fetch 
the values. 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/c07c7b2b-7aac-41cd-ab83-1db3cc7435c6%40googlegroups.com.


[go-nuts] How to search for string value in array

2019-09-26 Thread afriyie . abraham


I have trying to write a function that will accept a string as an input and 
return another string in a slice but it not working. I have function that 
unmarshal udp response to a type AuthVectors and then append the type 
struct data into an array authVecSlice. Below is the code

type AuthVectors struct {

MessageType string `json:"message_type"`

IMSIstring `json:"IMSI"`

RANDstring `json:"RAND"`

XRESstring `json:"XRES"`

AUTNstring `json:"AUTN"`

}

var imsistr = "2443411" 

var authVecSlice = make([]AuthVectors, 10)


func getAuthVec() {

hostName := "localhost"

portNum := "4343"

service := hostName + ":" + portNum

RemoteAddr, err := net.ResolveUDPAddr("udp", service)

conn, err := net.DialUDP("udp", nil, RemoteAddr)

if err != nil {

log.Fatal(err)

}

defer conn.Close()

// write a message to server

_, err = conn.Write([]byte(imsistr))

if err != nil {

log.Println(err)

}

// receive message from server

buffer := make([]byte, 1024)

i, _, err := conn.ReadFromUDP(buffer)

checkError(err)

err = json.Unmarshal(buffer[:i], &avs)

if err != nil {

panic(err)

}

authVecSlice = append(authVecSlice, avs)

fmt.Println(authVecSlice)

}

The array out put is as follows

[{AUTN_PARAM 2443411 C98FC7C6DE9E1351A397D0AF99B6E890 
D857E39D57E5E6BE 8000...} {AUTN_PARAM 2443411 
211B025CB1CC8EE9CBB5FC7F56C1506B C9396A5AC7E68D62 31D...} {AUTN_PARAM 
2443411 7D2A8C6E6B5CA243278987DFAF7FC829 C9EE960D0F5A501A 7E8..} 
...]

I would like to use the field RAND to search and return the corresponding 
XRES in the array. For example in the array is

{AUTN_PARAM 2443411 C98FC7C6DE9E1351A397D0AF99B6E890 
D857E39D57E5E6BE 8000...}

I would like to use the RAND value for example 
C98FC7C6DE9E1351A397D0AF99B6E890 as a search string and return its 
corresponding XRES D857E39D57E5E6BE.

func getXRES(a []AuthVectors, x interface{}) (xres string) {

for _, v := range a {

if x == v {

xres := v.XRES

return xres

}

}

return "Item not found"

}

The problem for me is that the array value do not have key to be use to 
perform the search. All example I found involves the use of key to fetch 
the values. 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/b653494b-83c3-438c-bf42-170f526bd369%40googlegroups.com.


[go-nuts] Watches / Data breakpoints

2019-09-26 Thread Stephen Illingworth
Hi all,

I have an awkward bug I'm trying to understand and I'm missing something in
my toolbox. Is there any way of monitoring a variable for changes made to
it? For example, I have a pointer type and I want a debugger to break
whenever its value (ie. what it points to) changes.

I call this a "watch" but I believe it's sometimes referred to as a "data
breakpoint".

I've looked at delve and can't see anything like it. I've had a quick look
at VSCode and Goland and I can't see anything there either. Is there
anything I've missed?

Help

Stephen Illingworth.

-- 
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/CAPmHGLPa0sgU9NkewBmZKhqVV-fZaaAni8Uaq%2BY_aUQstSEeYA%40mail.gmail.com.