[go-nuts] Re: help- i cant run program

2019-01-17 Thread Subramanian Sridharan
I think your GOROOT and GOPATH is causing the issue.

"fmt" package is present inside {go_installation_dir}\src and not 
{go_installation_dir}\bin\src.

Unset the GOROOT and GOPATH environment variables using the following 
commands to unset the GOROOT and GOPATH environment variables temporarily:

set GOROOT=
set GOPATH=

and then try running or building your code again.

If it works, unset your GOROOT and GOPATH environment variables permanently.

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


Re: [go-nuts] saving files on google app engine

2019-01-17 Thread Robert Engels
There are some options to increase the local storage on an instance, but 
compute engine is probably a better solution for something like that. 

> On Jan 17, 2019, at 7:16 PM, Chris FractalBach  wrote:
> 
> So I noticed this post: https://blog.golang.org/appengine-go111
> 
> And especially noticed this part:
>> Furthermore, the application code is completely portable—there are no ties 
>> to the infrastructure that your application is deployed on.
> 
> 
> 
> So I wanted to try it out! Just to keep things simple, I revisited 
> https://golang.org/doc/articles/wiki/ just to get back to basics.
> I attempted to make really simple highscores for a game:  
> 1 json file,POST score, GET summary
> 
> But once I ioutil.WriteFile gets called...
> SaveAs :: unable to save scoreboard to file :: open first.json: read-only 
> file system
>  
> and then I realized...
>> The runtime includes a writable /tmp directory, with all other directories 
>> having read-only access. Writing to /tmp takes up system memory.  
> 
>> https://cloud.google.com/appengine/docs/standard/go111/runtime
> 
> 
> 
> So that explains the writing-file issue.
> Perhaps I'm attempting to use app engine for something it wasn't designed for?
> 
> seems like overkill to use a VM instance or a database for something this 
> simple.
> 
> Anybody got some advice?
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

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


Re: [go-nuts] help- i cant run program

2019-01-17 Thread Ian Lance Taylor
On Thu, Jan 17, 2019 at 5:41 PM  wrote:
>
> hay
> Help, while I'm running and getting this error
>
>
> cannot find package "fmt" in any of: C:\Go\bin\src\fmt (from $GOROOT) 
> C:\Users\HP\go\src\fmt (from $GOPATH) package . imports runtime: cannot find 
> package "runtime" in any of: C:\Go\bin\src\runtime (from $GOROOT) 
> C:\Users\HP\go\src\runtime (from $GOPATH)
>
> I think it has to do with the definition of an "environment variable"
> I'd be happy to get help with this

Something is wrong with your Go installation.  Exactly how did you
install Go?  Is GOROOT set in your environment (it shouldn't be)?

Ian

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


[go-nuts] multiple binaries from a single directory with go modules?

2019-01-17 Thread Tycho Andersen
Hi everyone,

I'm trying to get an existing project which outputs multiple binaries
to work with go modules. The package follows roughly the recommended
layout: https://github.com/golang-standards/project-layout

That is, it looks like

/go.mod
/go.sum
/code.go
/cmd/foo/main.go
/cmd/bar/main.go

I have a top level make file that looks roughly like:

all: foo bar

foo: ...
go build -o foo ./cmd/foo/...

bar: ...
go build -o bar ./cmd/bar/...

When I type "make", it seems like go.sum and go.mod end up with only
bar's dependencies, because the last go invocation prunes the "unused"
dependencies from the module files. I've tried various ways of using
mutiple go.mod and go.sum files (one in each binary directory), but I
can't quite get the includes of the top level package right.

I see https://github.com/golang/go/issues/14295, which will solve this
problem for me, but it doesn't exist yet.

Is there some clever way of structuring a project like this with go
modules that I haven't figured out yet?

Thanks,

Tycho

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


[go-nuts] help- i cant run program

2019-01-17 Thread eitanh33
hay
Help, while I'm running and getting this error


cannot find package "fmt" in any of: C:\Go\bin\src\fmt (from $GOROOT) 
C:\Users\HP\go\src\fmt (from $GOPATH) package . imports runtime: cannot 
find package "runtime" in any of: C:\Go\bin\src\runtime (from $GOROOT) 
C:\Users\HP\go\src\runtime (from $GOPATH)

I think it has to do with the definition of an "environment variable"
I'd be happy to get help with 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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] [security] Go 1.11.5 and 1.10.8 pre-announcement

2019-01-17 Thread Julie Qiu
Hello gophers,

We plan to issue Go 1.11.5 and 1.10.8 on Wednesday, January 23 at
approximately 8pm UTC (12pm PST, 3pm EST).

These are minor releases to fix a security issue.

Following our policy at https://golang.org/security, this is the
pre-announcement of those releases.

Cheers,
Julie on behalf of the Go team

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


[go-nuts] saving files on google app engine

2019-01-17 Thread Chris FractalBach
So I noticed this post: https://blog.golang.org/appengine-go111

And especially noticed this part:

Furthermore, the application code is completely portable—there are no ties 
> to the infrastructure that your application is deployed on.



So I wanted to try it out! Just to keep things simple, I revisited 
https://golang.org/doc/articles/wiki/ just to get back to basics.
I attempted to make really simple highscores for a game:  
1 json file,POST score, GET summary

But once I ioutil.WriteFile gets called...

SaveAs :: unable to save scoreboard to file :: open first.json: read-only 
file system

 
and then I realized...

The runtime includes a writable /tmp directory, with all other directories 
> having read-only access. Writing to /tmp takes up system memory.  

https://cloud.google.com/appengine/docs/standard/go111/runtime



So that explains the writing-file issue.
Perhaps I'm attempting to use app engine for something it wasn't designed 
for?

seems like overkill to use a VM instance or a database for something this 
simple.

Anybody got some advice?

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


[go-nuts] Re: Dependency hell with Go modules

2019-01-17 Thread David Collier-Brown
You're playing in a space where there are NP-complete problems, as 
described in part 
by 
https://leaflessca.wordpress.com/2017/02/12/dll-hell-and-avoiding-an-np-complete-problem/

Run screaming from the building (;-))

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


Re: [go-nuts] Dependency hell with Go modules

2019-01-17 Thread Space A.
go list ./...

пятница, 18 января 2019 г., 1:26:02 UTC+3 пользователь Francis Chuang 
написал:
>
> Thanks, Justin and Harmen.
>
> I deleted my go.mod and go.sum, then ran "go mod init ..." and "go test". 
> The list of dependencies in go.mod and go.sum is now a lot slimmer. I tend 
> to run my test suites in a bunch of docker containers, so "go test" fails 
> for me when blindly executed from the root of the project. I think it would 
> be nice if there is a command to "populate go.mod and go.sum with just the 
> things we need to build and run tests on the current platform" without 
> having to run tests.
>
> On Friday, January 18, 2019 at 5:47:55 AM UTC+11, Harmen wrote:
>>
>> On Fri, Jan 18, 2019 at 07:18:41AM +1300, Justin Israel wrote: 
>> > On Fri, Jan 18, 2019, 12:36 AM Francis Chuang  
>> wrote: 
>> > 
>> > > Hey everyone, 
>> > > 
>> > > I was wondering if I can get some ideas on how to solve this 
>> dependency 
>> > > problem with Go modules. I am using Go 1.11.4 on Linux (Windows 
>> Subsystem 
>> > > for Linux to be exact). 
>> > > 
>> > > The first part of the problem is that for one of my libraries, I am 
>> > > importing github.com/hashicorp/vault/api, which is an api client to 
>> > > access Vault servers. This package is pretty thin and does not 
>> contain a 
>> > > lot of dependencies. However, the root project at 
>> > > github.com/hashicorp/vault has quite a few dependencies. 
>> > > If I delete the current go.mod and go.sum files in my library and 
>> start 
>> > > from scratch: 
>> > > - I run go mod init github.com/username/mylibrary 
>> > > - I then run go mod tidy to add missing packages to my go.mod and 
>> generate 
>> > > a go.sum 
>> > > 
>> > > Go mod imports the Vault repository at its root ( 
>> > > github.com/hashicorp/vault) as expected. Unfortunately, this pulls 
>> in a 
>> > > lot of subdependencies and I have a ton of indirect dependencies in 
>> my 
>> > > go.mod and go.sum. This is not unexpected of course as this is how go 
>> > > modules work. Unfortunately, this does slow down continuous 
>> integration 
>> > > builds and is probably not great for Github and VCS hosts as each 
>> build 
>> > > pulls in all of these unneeded dependencies. 
>> > > 
>> > > The second problem is that 2 of Vault's subdependencies (not sure how 
>> > > deep) is labix.org/v2/mgo and launchpad.net/gocheck. These are 
>> bazaar 
>> > > repos, so they necessitate the installation of the bzr tool. In my 
>> library, 
>> > > I added the following to my go.mod to force it to pull from the 
>> Github 
>> > > repos: 
>> > > 
>> > > replace labix.org/v2/mgo => github.com/go-mgo/mgo 
>> > > v0.0.0-20160801194620-b6121c6199b7 
>> > > 
>> > > replace launchpad.net/gocheck => github.com/go-check/check 
>> > > v0.0.0-20180628173108-788fd7840127 
>> > > 
>> > > This works great for running tests in the username/mylibrary repo as 
>> I no 
>> > > longer need to install bzr when running my CI builds. However, if I 
>> create 
>> > > another project such as github.com/username/some-project and import 
>> > > username/mylibrary, go mod will attempt to download 
>> launchpad.net/gocheck 
>> > > and labix.org/v2/mgo from the original bazaar repos when running go 
>> test 
>> > > and other commands.These causes errors such as `go: 
>> > > labix.org/v2/mgo@v0.0.0-20140701140051-0287: bzr branch 
>> > > --use-existing-dir https://launchpad.net/mgo/v2 . in 
>> > > 
>> /go/pkg/mod/cache/vcs/ca61c737a32b1e09a0919e15375f9c2b6aa09860cc097f1333b3c3d29e040ea8:
>>  
>>
>> > > exec: "bzr": executable file not found in $PATH `. This is quite 
>> annoying 
>> > > and I'd like to avoid having to add those `replace` statements in the 
>> > > go.mod of projects that consume the mylibrary package. In addition, 
>> > > consumers of my library would need to install bazaar (which most 
>> people 
>> > > probably won't have installed). 
>> > > 
>> > > The 2 options I have thought of are: 
>> > > 1. Ask the Vault team to extract the api package into a separate 
>> > > repository. I am not sure how likely they would be interested in 
>> doing 
>> > > this, but I am guessing it would be quite low. 
>> > > 2. Make a copy of the api package and copy it directly into my 
>> library. 
>> > > This is something I am hoping to avoid as much as possible, because 
>> I'd 
>> > > like to use go modules to manage my dependencies. 
>> > > 
>> > > Are there any other options I've missed? 
>>
>> Yes: don't run `go mod tidy` 
>> See for example: https://github.com/golang/go/issues/27920 
>> (which was also with a hashicorp project) 
>>
>

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


Re: [go-nuts] Using "er" and "able" for interfaces

2019-01-17 Thread Rob Pike
It depends on the nature of the verb (method) and whether it's being used
to refer to the subject or the object, whether it is transitive or
intransitive, and all the rest of that messy human grammar nonsense. Which
is why trying to align the with justifications to English grammar is a
fool's errand. Instead we make it a Go-specific recommendation, informed by
not bound by English rules.

Guidelines, not hard rules. io.Reader is not a English word.

-rob


On Fri, Jan 18, 2019 at 6:48 AM Jakob Borg  wrote:

> On 16 Jan 2019, at 15:42, Victor Giordano  wrote:
>
>
> As far i can get to understand the english language (i'm not a native
> speaker), the "er" seems to denotes or describe things in a more "active
> way" (the thing that they actually do by itself), and the "able" describes
> things in a more "passive way"  (the thing that you can "ask it/his/her" to
> do). Do you find this appreciation correct?
>
>
> This was a mental stumbling block for me for a long time when I started
> out with Go. For me, the "Reader" is the one who calls Read(), so an
> io.Reader seemed like the opposite of what I wanted. I would have better
> understood it as io.Readee. It works out better if I see the Reader as some
> sort of intermediate entity that affects reads on whatever the underlying
> thing is you want to read from… Or if I see it as just an
> interface-indicating nonsense suffix, like a capital-I prefix…
>
> //jb
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: [go-nuts] Dependency hell with Go modules

2019-01-17 Thread Francis Chuang
Thanks, Justin and Harmen.

I deleted my go.mod and go.sum, then ran "go mod init ..." and "go test". 
The list of dependencies in go.mod and go.sum is now a lot slimmer. I tend 
to run my test suites in a bunch of docker containers, so "go test" fails 
for me when blindly executed from the root of the project. I think it would 
be nice if there is a command to "populate go.mod and go.sum with just the 
things we need to build and run tests on the current platform" without 
having to run tests.

On Friday, January 18, 2019 at 5:47:55 AM UTC+11, Harmen wrote:
>
> On Fri, Jan 18, 2019 at 07:18:41AM +1300, Justin Israel wrote: 
> > On Fri, Jan 18, 2019, 12:36 AM Francis Chuang  > wrote: 
> > 
> > > Hey everyone, 
> > > 
> > > I was wondering if I can get some ideas on how to solve this 
> dependency 
> > > problem with Go modules. I am using Go 1.11.4 on Linux (Windows 
> Subsystem 
> > > for Linux to be exact). 
> > > 
> > > The first part of the problem is that for one of my libraries, I am 
> > > importing github.com/hashicorp/vault/api, which is an api client to 
> > > access Vault servers. This package is pretty thin and does not contain 
> a 
> > > lot of dependencies. However, the root project at 
> > > github.com/hashicorp/vault has quite a few dependencies. 
> > > If I delete the current go.mod and go.sum files in my library and 
> start 
> > > from scratch: 
> > > - I run go mod init github.com/username/mylibrary 
> > > - I then run go mod tidy to add missing packages to my go.mod and 
> generate 
> > > a go.sum 
> > > 
> > > Go mod imports the Vault repository at its root ( 
> > > github.com/hashicorp/vault) as expected. Unfortunately, this pulls in 
> a 
> > > lot of subdependencies and I have a ton of indirect dependencies in my 
> > > go.mod and go.sum. This is not unexpected of course as this is how go 
> > > modules work. Unfortunately, this does slow down continuous 
> integration 
> > > builds and is probably not great for Github and VCS hosts as each 
> build 
> > > pulls in all of these unneeded dependencies. 
> > > 
> > > The second problem is that 2 of Vault's subdependencies (not sure how 
> > > deep) is labix.org/v2/mgo and launchpad.net/gocheck. These are bazaar 
> > > repos, so they necessitate the installation of the bzr tool. In my 
> library, 
> > > I added the following to my go.mod to force it to pull from the Github 
> > > repos: 
> > > 
> > > replace labix.org/v2/mgo => github.com/go-mgo/mgo 
> > > v0.0.0-20160801194620-b6121c6199b7 
> > > 
> > > replace launchpad.net/gocheck => github.com/go-check/check 
> > > v0.0.0-20180628173108-788fd7840127 
> > > 
> > > This works great for running tests in the username/mylibrary repo as I 
> no 
> > > longer need to install bzr when running my CI builds. However, if I 
> create 
> > > another project such as github.com/username/some-project and import 
> > > username/mylibrary, go mod will attempt to download 
> launchpad.net/gocheck 
> > > and labix.org/v2/mgo from the original bazaar repos when running go 
> test 
> > > and other commands.These causes errors such as `go: 
> > > labix.org/v2/mgo@v0.0.0-20140701140051-0287: bzr branch 
> > > --use-existing-dir https://launchpad.net/mgo/v2 . in 
> > > 
> /go/pkg/mod/cache/vcs/ca61c737a32b1e09a0919e15375f9c2b6aa09860cc097f1333b3c3d29e040ea8:
>  
>
> > > exec: "bzr": executable file not found in $PATH `. This is quite 
> annoying 
> > > and I'd like to avoid having to add those `replace` statements in the 
> > > go.mod of projects that consume the mylibrary package. In addition, 
> > > consumers of my library would need to install bazaar (which most 
> people 
> > > probably won't have installed). 
> > > 
> > > The 2 options I have thought of are: 
> > > 1. Ask the Vault team to extract the api package into a separate 
> > > repository. I am not sure how likely they would be interested in doing 
> > > this, but I am guessing it would be quite low. 
> > > 2. Make a copy of the api package and copy it directly into my 
> library. 
> > > This is something I am hoping to avoid as much as possible, because 
> I'd 
> > > like to use go modules to manage my dependencies. 
> > > 
> > > Are there any other options I've missed? 
>
> Yes: don't run `go mod tidy` 
> See for example: https://github.com/golang/go/issues/27920 
> (which was also with a hashicorp project) 
>

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


Re: [go-nuts] what is the use of context in golang RESTful apis?

2019-01-17 Thread robert engels
Singletons are not an “anti-pattern”. They are used incorrectly by many, so 
they become anti-patterns in the general case.

A proper use of singletons - and usually they are behind the scenes so you 
don’t even know they are a singleton - is the proper design for many 
architectures - especially for memory constrained devices.

> On Jan 17, 2019, at 4:07 PM, Ian Denhardt  wrote:
> 
> Quoting Space A. (2019-01-17 16:46:17)
> 
>> Go's package-level variables are also not "globals". And you can
>> control access with exported/unexported names or exported/unexported
>> package-level functions.
> 
> Exactly. A namespaced global is still a global, and most of the problems
> with them still apply.
> 
> This is also why "singletons" are an antipattern -- they're just dressed
> up globals.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

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


Re: [go-nuts] what is the use of context in golang RESTful apis?

2019-01-17 Thread Ian Denhardt
Quoting Space A. (2019-01-17 16:46:17)

> Go's package-level variables are also not "globals". And you can
> control access with exported/unexported names or exported/unexported
> package-level functions.

Exactly. A namespaced global is still a global, and most of the problems
with them still apply.

This is also why "singletons" are an antipattern -- they're just dressed
up globals.

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


Re: [go-nuts] what is the use of context in golang RESTful apis?

2019-01-17 Thread Space A.
Go's package-level variables are also not "globals". And you can control 
access with exported/unexported names or exported/unexported package-level 
functions.

PS: In Java everything is "class".


четверг, 17 января 2019 г., 23:31:34 UTC+3 пользователь robert engels 
написал:
>
> Java does not have “global” variables. All data access is via a Class, and 
> then possibly and instance of a Class. Contrast this with “globals” in C - 
> the variable - if declared external is visible to all code anywhere (there 
> are more modern ways to namespace this for some level of protection). 
>
> When declaring a ThreadLocal in Java, it still must be accessed using the 
> Class or instance accessor, which also means, since you can control 
> private/protected/package level access, you can prevent 
> unauthorized/uncontrolled mutation - this is completely different than 
> historical "globals” and the problems surrounding them. 
>
> > On Jan 17, 2019, at 2:19 PM, Ian Denhardt  > wrote: 
> > 
> >> They are not global variables, they are class variables. There's a 
> >> huge difference. 
> > 
> > Can you elaborate? I don't see a meaningful difference vs. Go's 
> > package-level var. 
> > 
> > -- 
> > 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...@googlegroups.com . 
> > For more options, visit https://groups.google.com/d/optout. 
>
>

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


Re: [go-nuts] what is the use of context in golang RESTful apis?

2019-01-17 Thread robert engels
Java does not have “global” variables. All data access is via a Class, and then 
possibly and instance of a Class. Contrast this with “globals” in C - the 
variable - if declared external is visible to all code anywhere (there are more 
modern ways to namespace this for some level of protection).

When declaring a ThreadLocal in Java, it still must be accessed using the Class 
or instance accessor, which also means, since you can control 
private/protected/package level access, you can prevent 
unauthorized/uncontrolled mutation - this is completely different than 
historical "globals” and the problems surrounding them.

> On Jan 17, 2019, at 2:19 PM, Ian Denhardt  wrote:
> 
>> They are not global variables, they are class variables. There's a
>> huge difference.
> 
> Can you elaborate? I don't see a meaningful difference vs. Go's
> package-level var.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

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


Re: [go-nuts] what is the use of context in golang RESTful apis?

2019-01-17 Thread Ian Denhardt
> They are not global variables, they are class variables. There's a
> huge difference.

Can you elaborate? I don't see a meaningful difference vs. Go's
package-level var.

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


[go-nuts] Re: what is the use of context in golang RESTful apis?

2019-01-17 Thread Victor Giordano
Hi Mahendra, allow me to point something, as far i can see on this matter, 
there are two things i would like to address separately:

1) Making a REST API for you application (that can be accessed through http 
(e.g: an app running in a web server) or, why not?, locally (e.g: an app 
running that uses stdin for receiving input)).
2) Long running task that executed in background, that may be canceled or 
query about it progress.
2.BIS) Making (2) part of the language elements so the devs have a solution 
at hand for dealing with something that is not trivial [I follow the 
conversation i saw that there is a debate over it, if i have to code less 
then i accept!! :P)


*Key points*
** I don't see why you need to approach both things at the same time. *
For (1) i will *strongly *suggest to read this article 
, it really helps me 
when i face my first set of entry-points (or end-points). I do know that is 
not easy to define an URL with a name that is accordenly to the business 
domain and that provides granular access to the data that the client may 
require. 
* For start i would suggest to use the prefix "/api/v1/" for each URL that 
maps to an end-point.
* Then you should start by providing the more granular points for getting 
data, thus allowing the client to combine the data according to the UI/UX 
needs (assuming that is a client app elsewhere)
* For (2) you will find that the article i suggest above 
 has a suggestion 
for dealing with them, a solution that is langauge agnostic (serach for 
"Transaction Resource"), so i guess that would be a good starting point to 
think how to design the system not attached to a library instead attaching 
to bussiness domain logic that shall be reflected in the solution domain.

Hope you can understand what i'm trying to explain and really hope that it 
helps a little at least.
Greetings
V



 El domingo, 13 de enero de 2019, 7:13:23 (UTC-3), Mahendra Bhoir escribió:
>
> Hi I am new to golang. I am writing some RESTful apis. I have read 
> somewhere that using context while writing RESTful apis is good practice.
> But context seems very confusing to me and I can write restful apis 
> without context.I know the uses of context but same can be done without 
> using context.
> Any suggestions.. Example codes will be appreciated. 
>

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


Re: [go-nuts] Using "er" and "able" for interfaces

2019-01-17 Thread Jakob Borg
On 16 Jan 2019, at 15:42, Victor Giordano 
mailto:vitucho3...@gmail.com>> wrote:

As far i can get to understand the english language (i'm not a native speaker), 
the "er" seems to denotes or describe things in a more "active way" (the thing 
that they actually do by itself), and the "able" describes things in a more 
"passive way"  (the thing that you can "ask it/his/her" to do). Do you find 
this appreciation correct?

This was a mental stumbling block for me for a long time when I started out 
with Go. For me, the "Reader" is the one who calls Read(), so an io.Reader 
seemed like the opposite of what I wanted. I would have better understood it as 
io.Readee. It works out better if I see the Reader as some sort of intermediate 
entity that affects reads on whatever the underlying thing is you want to read 
from… Or if I see it as just an interface-indicating nonsense suffix, like a 
capital-I prefix…

//jb

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


Re: [go-nuts] Dependency hell with Go modules

2019-01-17 Thread Harmen
On Fri, Jan 18, 2019 at 07:18:41AM +1300, Justin Israel wrote:
> On Fri, Jan 18, 2019, 12:36 AM Francis Chuang  wrote:
> 
> > Hey everyone,
> >
> > I was wondering if I can get some ideas on how to solve this dependency
> > problem with Go modules. I am using Go 1.11.4 on Linux (Windows Subsystem
> > for Linux to be exact).
> >
> > The first part of the problem is that for one of my libraries, I am
> > importing github.com/hashicorp/vault/api, which is an api client to
> > access Vault servers. This package is pretty thin and does not contain a
> > lot of dependencies. However, the root project at
> > github.com/hashicorp/vault has quite a few dependencies.
> > If I delete the current go.mod and go.sum files in my library and start
> > from scratch:
> > - I run go mod init github.com/username/mylibrary
> > - I then run go mod tidy to add missing packages to my go.mod and generate
> > a go.sum
> >
> > Go mod imports the Vault repository at its root (
> > github.com/hashicorp/vault) as expected. Unfortunately, this pulls in a
> > lot of subdependencies and I have a ton of indirect dependencies in my
> > go.mod and go.sum. This is not unexpected of course as this is how go
> > modules work. Unfortunately, this does slow down continuous integration
> > builds and is probably not great for Github and VCS hosts as each build
> > pulls in all of these unneeded dependencies.
> >
> > The second problem is that 2 of Vault's subdependencies (not sure how
> > deep) is labix.org/v2/mgo and launchpad.net/gocheck. These are bazaar
> > repos, so they necessitate the installation of the bzr tool. In my library,
> > I added the following to my go.mod to force it to pull from the Github
> > repos:
> >
> > replace labix.org/v2/mgo => github.com/go-mgo/mgo
> > v0.0.0-20160801194620-b6121c6199b7
> >
> > replace launchpad.net/gocheck => github.com/go-check/check
> > v0.0.0-20180628173108-788fd7840127
> >
> > This works great for running tests in the username/mylibrary repo as I no
> > longer need to install bzr when running my CI builds. However, if I create
> > another project such as github.com/username/some-project and import
> > username/mylibrary, go mod will attempt to download launchpad.net/gocheck
> > and labix.org/v2/mgo from the original bazaar repos when running go test
> > and other commands.These causes errors such as `go:
> > labix.org/v2/mgo@v0.0.0-20140701140051-0287: bzr branch
> > --use-existing-dir https://launchpad.net/mgo/v2 . in
> > /go/pkg/mod/cache/vcs/ca61c737a32b1e09a0919e15375f9c2b6aa09860cc097f1333b3c3d29e040ea8:
> > exec: "bzr": executable file not found in $PATH `. This is quite annoying
> > and I'd like to avoid having to add those `replace` statements in the
> > go.mod of projects that consume the mylibrary package. In addition,
> > consumers of my library would need to install bazaar (which most people
> > probably won't have installed).
> >
> > The 2 options I have thought of are:
> > 1. Ask the Vault team to extract the api package into a separate
> > repository. I am not sure how likely they would be interested in doing
> > this, but I am guessing it would be quite low.
> > 2. Make a copy of the api package and copy it directly into my library.
> > This is something I am hoping to avoid as much as possible, because I'd
> > like to use go modules to manage my dependencies.
> >
> > Are there any other options I've missed?

Yes: don't run `go mod tidy`
See for example: https://github.com/golang/go/issues/27920
(which was also with a hashicorp project)

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


Re: [go-nuts] Dependency hell with Go modules

2019-01-17 Thread Justin Israel
On Fri, Jan 18, 2019, 12:36 AM Francis Chuang  wrote:

> Hey everyone,
>
> I was wondering if I can get some ideas on how to solve this dependency
> problem with Go modules. I am using Go 1.11.4 on Linux (Windows Subsystem
> for Linux to be exact).
>
> The first part of the problem is that for one of my libraries, I am
> importing github.com/hashicorp/vault/api, which is an api client to
> access Vault servers. This package is pretty thin and does not contain a
> lot of dependencies. However, the root project at
> github.com/hashicorp/vault has quite a few dependencies.
> If I delete the current go.mod and go.sum files in my library and start
> from scratch:
> - I run go mod init github.com/username/mylibrary
> - I then run go mod tidy to add missing packages to my go.mod and generate
> a go.sum
>
> Go mod imports the Vault repository at its root (
> github.com/hashicorp/vault) as expected. Unfortunately, this pulls in a
> lot of subdependencies and I have a ton of indirect dependencies in my
> go.mod and go.sum. This is not unexpected of course as this is how go
> modules work. Unfortunately, this does slow down continuous integration
> builds and is probably not great for Github and VCS hosts as each build
> pulls in all of these unneeded dependencies.
>
> The second problem is that 2 of Vault's subdependencies (not sure how
> deep) is labix.org/v2/mgo and launchpad.net/gocheck. These are bazaar
> repos, so they necessitate the installation of the bzr tool. In my library,
> I added the following to my go.mod to force it to pull from the Github
> repos:
>
> replace labix.org/v2/mgo => github.com/go-mgo/mgo
> v0.0.0-20160801194620-b6121c6199b7
>
> replace launchpad.net/gocheck => github.com/go-check/check
> v0.0.0-20180628173108-788fd7840127
>
> This works great for running tests in the username/mylibrary repo as I no
> longer need to install bzr when running my CI builds. However, if I create
> another project such as github.com/username/some-project and import
> username/mylibrary, go mod will attempt to download launchpad.net/gocheck
> and labix.org/v2/mgo from the original bazaar repos when running go test
> and other commands.These causes errors such as `go:
> labix.org/v2/mgo@v0.0.0-20140701140051-0287: bzr branch
> --use-existing-dir https://launchpad.net/mgo/v2 . in
> /go/pkg/mod/cache/vcs/ca61c737a32b1e09a0919e15375f9c2b6aa09860cc097f1333b3c3d29e040ea8:
> exec: "bzr": executable file not found in $PATH `. This is quite annoying
> and I'd like to avoid having to add those `replace` statements in the
> go.mod of projects that consume the mylibrary package. In addition,
> consumers of my library would need to install bazaar (which most people
> probably won't have installed).
>
> The 2 options I have thought of are:
> 1. Ask the Vault team to extract the api package into a separate
> repository. I am not sure how likely they would be interested in doing
> this, but I am guessing it would be quite low.
> 2. Make a copy of the api package and copy it directly into my library.
> This is something I am hoping to avoid as much as possible, because I'd
> like to use go modules to manage my dependencies.
>
> Are there any other options I've missed?
>

I'm not yet well versed in modules since I use them in a very simple way
and I vendor. But is it also supported as an option to make /api a "sub
module" by adding another go.mod at that level?
If that is possible then it is way less intrusive of a change than
splitting it into another repo.

That aside, I don't know if that would help too much in this case because I
don't think Go modules differentiates between test and non test when
collecting dependencies. If the api tests have deps, they will get
collected I think. Even the non test files have some deps anyways. Might be
nice if there were a Go modules option to skip scanning tests.

Anyways just throwing that out there until someone more informed that me
responds.


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

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


[go-nuts] Re: Algorithm question: reversing text/template.Template.Execute efficiently

2019-01-17 Thread howardcshaw
I don't think the problem is well-defined or single-solution. Surely the 
simplest solution, given a single output and the data that produced it is 
to simply encode the entire output text in the template and ignore the data.

Instead, I think you need a matching corpus - i.e. a list of pairs of 
output and input. Once you have that, I expect you would basically run a 
diff-type algorithm across pairs of outputs looking to build an invariant 
list (i.e. the elements of the template that never change) paired with a 
variant list (the elements that change), to be interleaved in the template. 

I don't think there is any simple or valid path to go from there to a fully 
worked out template, given the level of coding permissible in templates. 
But you could do a series of heuristics to match clear elements. For 
example, having your list of variants, you would run a match against the 
content of that variant in each output against all the inputs looking for 
simple matches that hold true across the entire corpus, and replace these 
with simple substitutions in the template, marking them completed in your 
list of variants.

Then you would run the same comparison looking for substring matches (to 
attempt to capture simple substitutions that are chained (e.g. 
{{.Salutation}} {{.FirstName}} {{.LastName}} in a naive name implementation 
is going to show up as a single variant block in the analysis, so your 
first heuristic will fail to find a match). 

Finding repeated complex sub-elements of a template and matching them; or 
matching summary values such as subtotals and grand totals or worse, 
averages that have been formatted to less than the default number of 
digits? I suspect you are going well off the end of what is achievable with 
simple pattern matching, so if that is your normal interview fare, I pity 
your interviewees.

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


Re: [go-nuts] what is the use of context in golang RESTful apis?

2019-01-17 Thread Robert Engels
Actually, in many cases they are even more restrictive instance variables. They 
are not global in any sense. 

Furthermore, in most common usage they are read only. 

In my experience, they are used in very localized settings to avoid 
construction of non thread safe objects for performance, or they are used by 
frameworks to handle the context, and the framework manages the scope and 
lifecycle. 

In neither case are they confusing or error prone. 

> On Jan 17, 2019, at 7:56 AM, Robert Engels  wrote:
> 
> They are not global variables, they are class variables. There’s a huge 
> difference. 
> 
>> On Jan 17, 2019, at 2:32 AM, alex.besogo...@gmail.com wrote:
>> 
>>> On Wednesday, January 16, 2019 at 1:33:57 PM UTC-8, Ian Lance Taylor wrote:
>>> In particular everybody understands that the new thread will not have 
>>> access to any of the thread local 
>>> variables of the parent thread. 
>> To be fair, Java does have InheritableThreadLocal variables that are 
>> automatically shared with downstream threads.
>> 
>> Ironically, it's kinda buggy in Java because a lot of parallel code in Java 
>> uses thread pools that break InheritableThreadLocals. A similar construct in 
>> Go would behave much better simply because nobody uses goroutine pools.
>> 
>> Of course, TLS are bad for other reasons (they are basically disguised 
>> global variables and should be avoided).
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to golang-nuts+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.

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


Re: [go-nuts] what is the use of context in golang RESTful apis?

2019-01-17 Thread Robert Engels
They are not global variables, they are class variables. There’s a huge 
difference. 

> On Jan 17, 2019, at 2:32 AM, alex.besogo...@gmail.com wrote:
> 
>> On Wednesday, January 16, 2019 at 1:33:57 PM UTC-8, Ian Lance Taylor wrote:
>> In particular everybody understands that the new thread will not have access 
>> to any of the thread local 
>> variables of the parent thread. 
> To be fair, Java does have InheritableThreadLocal variables that are 
> automatically shared with downstream threads.
> 
> Ironically, it's kinda buggy in Java because a lot of parallel code in Java 
> uses thread pools that break InheritableThreadLocals. A similar construct in 
> Go would behave much better simply because nobody uses goroutine pools.
> 
> Of course, TLS are bad for other reasons (they are basically disguised global 
> variables and should be avoided).
> -- 
> You received this message because you are subscribed to the Google Groups 
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

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


[go-nuts] Dependency hell with Go modules

2019-01-17 Thread Francis Chuang
Hey everyone,

I was wondering if I can get some ideas on how to solve this dependency 
problem with Go modules. I am using Go 1.11.4 on Linux (Windows Subsystem 
for Linux to be exact).

The first part of the problem is that for one of my libraries, I am 
importing github.com/hashicorp/vault/api, which is an api client to access 
Vault servers. This package is pretty thin and does not contain a lot of 
dependencies. However, the root project at github.com/hashicorp/vault has 
quite a few dependencies.
If I delete the current go.mod and go.sum files in my library and start 
from scratch:
- I run go mod init github.com/username/mylibrary
- I then run go mod tidy to add missing packages to my go.mod and generate 
a go.sum

Go mod imports the Vault repository at its root 
(github.com/hashicorp/vault) as expected. Unfortunately, this pulls in a 
lot of subdependencies and I have a ton of indirect dependencies in my 
go.mod and go.sum. This is not unexpected of course as this is how go 
modules work. Unfortunately, this does slow down continuous integration 
builds and is probably not great for Github and VCS hosts as each build 
pulls in all of these unneeded dependencies.

The second problem is that 2 of Vault's subdependencies (not sure how deep) 
is labix.org/v2/mgo and launchpad.net/gocheck. These are bazaar repos, so 
they necessitate the installation of the bzr tool. In my library, I added 
the following to my go.mod to force it to pull from the Github repos:

replace labix.org/v2/mgo => github.com/go-mgo/mgo 
v0.0.0-20160801194620-b6121c6199b7

replace launchpad.net/gocheck => github.com/go-check/check 
v0.0.0-20180628173108-788fd7840127

This works great for running tests in the username/mylibrary repo as I no 
longer need to install bzr when running my CI builds. However, if I create 
another project such as github.com/username/some-project and import 
username/mylibrary, go mod will attempt to download launchpad.net/gocheck 
and labix.org/v2/mgo from the original bazaar repos when running go test 
and other commands.These causes errors such as `go: 
labix.org/v2/mgo@v0.0.0-20140701140051-0287: bzr branch 
--use-existing-dir https://launchpad.net/mgo/v2 . in 
/go/pkg/mod/cache/vcs/ca61c737a32b1e09a0919e15375f9c2b6aa09860cc097f1333b3c3d29e040ea8:
 
exec: "bzr": executable file not found in $PATH `. This is quite annoying 
and I'd like to avoid having to add those `replace` statements in the 
go.mod of projects that consume the mylibrary package. In addition, 
consumers of my library would need to install bazaar (which most people 
probably won't have installed).

The 2 options I have thought of are:
1. Ask the Vault team to extract the api package into a separate 
repository. I am not sure how likely they would be interested in doing 
this, but I am guessing it would be quite low.
2. Make a copy of the api package and copy it directly into my library. 
This is something I am hoping to avoid as much as possible, because I'd 
like to use go modules to manage my dependencies.

Are there any other options I've missed?

Cheers,
Francis

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


Re: [go-nuts] Unable to delete multiple records (multiple ids) on hitting endpoint

2019-01-17 Thread aniruddha . dwivedi
Thanks Ian

On Thursday, January 17, 2019 at 2:29:55 PM UTC+5:30, Ian Davis wrote:
>
> On Thu, 17 Jan 2019, at 8:13 AM, aniruddh...@nytimes.com  
> wrote:
>
> Hi I am using NYT's Marvin framework which internally uses gorilla mux. I 
> am able to delete single record when I pass single id as json object in 
> request body using postman but I don't know how to handle array of json 
> objects here. My code is as below:-
>  
> For decoding ---
>
> func DecodeDeleteUser(ctx context.Context, r *http.Request) (interface{}, 
> error) {
>   /// uriDeleteRequest := {}
> uriDeleteRequest := &[]UserDel{}
> log.Infof(ctx, "DeleteUser before decoding :: %+v", r)
>   if err := json.NewDecoder(r.Body).Decode(uriDeleteRequest); err != nil {
>   log.Errorf(ctx, "Delete User Error : Could not decode body from the 
> request")
>   return nil, marvin.NewJSONStatusResponse(
>   "could not decode request body in DeleteUser",
>   http.StatusBadRequest,
>   )
>   }
> log.Infof(ctx, "DeleteUser After decoding ::: decoding done 
> successfully", uriDeleteRequest)
>   return uriDeleteRequest, nil
> }
>
> It successfully decodes array of JSON. Now problem arises is function 
> below-
>
> func(s service) deleteUserFromDb(ctx context.Context, request interface{}) 
> (interface{}, error) {
> //  var userdel []UserDel
>   log.Infof(ctx, "request just inside method deleteUserFromDb : 
> %+V",request)
>   r := request.([]*UserDel)
>   log.Infof(ctx, "request in form of r is : %+V",r)
> //  db, err := s.ConnectsService.initPostgreConnection(ctx)
>   _, err := s.ConnectsService.initPostgreConnection(ctx)
>   if err != nil {
> log.Infof(ctx, "Connection established in deleteUserFromDb method ...")
> return nil,err
>   }
>   return "all fine",nil
> }
>
> Here line  * r := request.([]*UserDel) *gives following error - panic: 
> interface conversion: interface {} is *[]test_marvin.UserDel, not 
> []*test_marvin.UserDel
>
> Here test_marvin is my code's package name. Please help as I don't know 
> what is wrong with my above code in golang?
>
>
> In DecodeDeleteUser it looks like your request is a pointer to a slice of 
> UserDel but in deleteUserFromDb you are expecting it to be a slice of 
> pointers to UserDel. Change uriDeleteRequest := &[]UserDel{} to be 
> uriDeleteRequest := []*UserDel{} and it should work.
>
> All the best,
>
> Ian
>
>
>

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


Re: [go-nuts] How to use map to manage channel correctly?

2019-01-17 Thread Jan Mercl
On Thu, Jan 17, 2019 at 9:35 AM Fei Ding  wrote:

> map[string]chan int
> I can understand that the map forbids concurrent read/write, but in my
case, it actually forbid concurrent r/w to the channel, which is the basic
operation.
>
> The panic is something like:
>
> goroutine 1661 [running]:
> runtime.throw(0x59de0d, 0x21)
> /usr/local/go/src/runtime/panic.go:619 +0x81 fp=0xc420045ed8
sp=0xc420045eb8 pc=0x42a501
> runtime.mapaccess1_faststr(0x564e40, 0xc42008aba0, 0xc4200ceba0, 0x10,
0xc4200a2f48)
> /usr/local/go/src/runtime/hashmap_fast.go:181 +0x421 fp=0xc420045f48
sp=0xc420045ed8 pc=0x40be31

The panic is not caused by 'concurrent r/w to the channel', but by
concurrently reading and writing a map.

Please post somewhere a minimal, self contained reproducer, for example on
http://play.golang.org. Someone may help you to find/fix the problem. Note
that the playground probably runs in a single thread so the reproducer may
not actually reproduce the panic within the playground, but that's not a
problem as long as it can reproduce the panic on a local machine.

-- 

-j

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


Re: [go-nuts] Unable to delete multiple records (multiple ids) on hitting endpoint

2019-01-17 Thread Ian Davis
On Thu, 17 Jan 2019, at 8:13 AM, aniruddha.dwiv...@nytimes.com wrote:
> Hi I am using NYT's Marvin framework which internally uses gorilla mux. I am 
> able to delete single record when I pass single id as json object in request 
> body using postman but I don't know how to handle array of json objects here. 
> My code is as below:-
>  
> For decoding ---
> 
> func DecodeDeleteUser(ctx context.Context, r *http.Request) (interface{}, 
> error) {
>  /// uriDeleteRequest := {}
>  uriDeleteRequest := &[]UserDel{}
>  log.Infof(ctx, "DeleteUser before decoding :: %+v", r)
>   if err := json.NewDecoder(r.Body).Decode(uriDeleteRequest); err != nil {
>  log.Errorf(ctx, "Delete User Error : Could not decode body from the request")
>   return nil, marvin.NewJSONStatusResponse(
>   "could not decode request body in DeleteUser",
>   http.StatusBadRequest,
>   )
>   }
>  log.Infof(ctx, "DeleteUser After decoding ::: decoding done successfully", 
> uriDeleteRequest)
>   return uriDeleteRequest, nil
> }
> 
> It successfully decodes array of JSON. Now problem arises is function below-
> 
> func(s service) deleteUserFromDb(ctx context.Context, request interface{}) 
> (interface{}, error) {
> // var userdel []UserDel
>  log.Infof(ctx, "request just inside method deleteUserFromDb : %+V",request)
>  r := request.([]*UserDel)
>  log.Infof(ctx, "request in form of r is : %+V",r)
> // db, err := s.ConnectsService.initPostgreConnection(ctx)
>  _, err := s.ConnectsService.initPostgreConnection(ctx)
>  if err != nil {
>  log.Infof(ctx, "Connection established in deleteUserFromDb method ...")
>  return nil,err
>  }
>  return "all fine",nil
> }
> 
> Here line * r := request.([]*UserDel) *gives following error - panic: 
> interface conversion: interface {} is *[]test_marvin.UserDel, not 
> []*test_marvin.UserDel
> 
> Here test_marvin is my code's package name. Please help as I don't know what 
> is wrong with my above code in golang?
> 

In DecodeDeleteUser it looks like your request is a pointer to a slice of 
UserDel but in deleteUserFromDb you are expecting it to be a slice of pointers 
to UserDel. Change uriDeleteRequest := &[]UserDel{} to be uriDeleteRequest := 
[]*UserDel{} and it should work.

All the best,

Ian

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


[go-nuts] How to use map to manage channel correctly?

2019-01-17 Thread Fei Ding
Hi

I met a panic() when trying to manage channal by dict, as

map[string]chan int

I can understand that the map forbids concurrent read/write, but in my 
case, it actually forbid concurrent r/w to the channel, which is the basic 
operation.
So how to implement this request correctly?

The panic is something like:

goroutine 1661 [running]:
runtime.throw(0x59de0d, 0x21)
/usr/local/go/src/runtime/panic.go:619 +0x81 fp=0xc420045ed8 
sp=0xc420045eb8 pc=0x42a501
runtime.mapaccess1_faststr(0x564e40, 0xc42008aba0, 0xc4200ceba0, 0x10, 
0xc4200a2f48)
/usr/local/go/src/runtime/hashmap_fast.go:181 +0x421 fp=0xc420045f48 
sp=0xc420045ed8 pc=0x40be31

And the  throw is:

throw("concurrent map read and map write")



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


Re: [go-nuts] what is the use of context in golang RESTful apis?

2019-01-17 Thread alex . besogonov
On Wednesday, January 16, 2019 at 1:33:57 PM UTC-8, Ian Lance Taylor wrote:

> In particular everybody understands that the new thread will not have 
> access to any of the thread local 
> variables of the parent thread. 
>
To be fair, Java does have InheritableThreadLocal variables that are 
automatically shared with downstream threads.

Ironically, it's kinda buggy in Java because a lot of parallel code in Java 
uses thread pools that break InheritableThreadLocals. A similar construct 
in Go would behave much better simply because nobody uses goroutine pools.

Of course, TLS are bad for other reasons (they are basically disguised 
global variables and should be avoided).

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


Re: [go-nuts] what is the use of context in golang RESTful apis?

2019-01-17 Thread alex . besogonov
No. Just no.

TLS is just another form of global variables and suffers from the same 
problems. I.e. the "magic action at a distance" - it's impossible to 
understand what changes it without checking the whole program.

In particular, transactions, current users and other crap should NEVER go 
into the context. Pass them explicitly. This applies to Java as well, btw.

The test for inclusion into Context should be: "Is this thing used 
EVERYWHERE?". There are basically two such items in Go: logging and 
arguably the cancellation tree. Although cancellation is not always needed 
so it's probably better to be split into its own entity.

Alternatively Go can create special-cased TLS for logging use only and 
leave Context only for cancellation/deadlines.

On Wednesday, January 16, 2019 at 1:43:58 PM UTC-8, robert engels wrote:
>
> I agree with all of those assessments. That’s why I think the “context” 
> needs to be moved into a language construct. Then the developer is 
> insulated from most (all) of these problems - that is the “current context” 
> propagates unless specifically told not to when creating the Go routine. In 
> almost all cases the context is a single reference so it should be cheap to 
> propagate. 
>
> If the “context” was a higher level standardized concept, then the 
> “values” could be typed, so all of the benefits of the Java way - 
> transactions, logging, “current user”, etc. can all be addressed in a 
> type-safe manner. 
>
> I’ve stated a few times that a Go routines lack of context (name, purpose, 
> etc) is a huge problem. It really limits the ability to write very high 
> performance applications (pinning routines to cores, groups of routines to 
> CPU’s, marking some routines as “delay GC”, etc.). 
>
> > On Jan 16, 2019, at 3:33 PM, Ian Lance Taylor  > wrote: 
> > 
> >> On Wed, Jan 16, 2019 at 7:15 AM Robert Engels  > wrote: 
> >> 
> >> 
> >> I don’t see the complexity nor the real difference between Go routines 
> and Threads. In Java TLS is not passed to new threads you need to be 
> explicit. The ThreadLocal doesn’t allow  access to other threads locals 
> even with thread groups, etc. As far as I understand Go has no concept of 
> parent Go routine - at least not exposed - so I don’t see the issue. 
> > 
> > The difference is that in Java creating a new thread is a relatively 
> > heavyweight operation.  It's not hard, but it's not routine.  It's 
> > reasonable that when creating a new thread you consider how to handle 
> > any thread local variables.  In particular everybody understands that 
> > the new thread will not have access to any of the thread local 
> > variables of the parent thread. 
> > 
> > In Go new goroutines are started frequently and casually.  For 
> > example, it's routine for people to change a loop computing a list of 
> > values into a loop that starts a goroutine for each computation.  If 
> > we are using a thread-local context.Context to cancel a goroutine, 
> > then one would naturally expect all those goroutines to inherit that 
> > Context value, so that they too will be stopped.  If they don't 
> > inherit it, then we need some extra mechanism to set the thread-local 
> > Context, and we need to remember to do that.  If they do inherit it, 
> > then we need to think about the cases where they shouldn't inherit it. 
> > Either way, the operation is sometimes implicit and sometimes 
> > explicit.  That is confusing. 
> > 
> > In Java it's not confusing to always make thread-local handling 
> > explicit.  In Go that would be frustrating and awkward. 
> > 
> > Ian 
>
>

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


[go-nuts] Unable to delete multiple records (multiple ids) on hitting endpoint

2019-01-17 Thread aniruddha . dwivedi
Hi I am using NYT's Marvin framework which internally uses gorilla mux. I 
am able to delete single record when I pass single id as json object in 
request body using postman but I don't know how to handle array of json 
objects here. My code is as below:-
 
For decoding ---

func DecodeDeleteUser(ctx context.Context, r *http.Request) (interface{}, 
error) {
  /// uriDeleteRequest := {}
uriDeleteRequest := &[]UserDel{}
log.Infof(ctx, "DeleteUser before decoding :: %+v", r)
  if err := json.NewDecoder(r.Body).Decode(uriDeleteRequest); err != nil {
  log.Errorf(ctx, "Delete User Error : Could not decode body from the 
request")
  return nil, marvin.NewJSONStatusResponse(
  "could not decode request body in DeleteUser",
  http.StatusBadRequest,
  )
  }
log.Infof(ctx, "DeleteUser After decoding ::: decoding done 
successfully", uriDeleteRequest)
  return uriDeleteRequest, nil
}

It successfully decodes array of JSON. Now problem arises is function below-

func(s service) deleteUserFromDb(ctx context.Context, request interface{}) 
(interface{}, error) {
//  var userdel []UserDel
  log.Infof(ctx, "request just inside method deleteUserFromDb : 
%+V",request)
  r := request.([]*UserDel)
  log.Infof(ctx, "request in form of r is : %+V",r)
//  db, err := s.ConnectsService.initPostgreConnection(ctx)
  _, err := s.ConnectsService.initPostgreConnection(ctx)
  if err != nil {
log.Infof(ctx, "Connection established in deleteUserFromDb method ...")
return nil,err
  }
  return "all fine",nil
}

Here line  * r := request.([]*UserDel) *gives following error - panic: 
interface conversion: interface {} is *[]test_marvin.UserDel, not 
[]*test_marvin.UserDel

Here test_marvin is my code's package name. Please help as I don't know 
what is wrong with my above code in golang?

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