[go-nuts] How to skip over or fix type-checking errors in the standard library?

2022-05-18 Thread Matt Mueller
Hey Gophers,

I'm trying to run the type-checker on some code using "go/types". I got it 
working for local packages, but I'm stuck on the following when "errors" is 
imported:

```
could not import errors (errors/wrap.go:8:2: could not import 
internal/reflectlite (internal/reflectlite/value.go:10:2: could not import 
runtime (runtime/atomic_pointer.go:8:2: could not import 
runtime/internal/atomic (runtime/internal/atomic/atomic_amd64.go:23:28: 
cannot convert ptr (variable of type unsafe.Pointer) to *unsafe.Pointer
```

I believe this is a valid type error, once you get into the guts of the 
standard library, there's some weird stuff happening.

Is there a way to skip over type-checking standard library packages? 
Otherwise how can one fix this error? If you're not sure, pointing me in 
the right direction would be super.

Let me know if you need any additional information or code. 

Thanks!
Matt

-- 
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/bb83bcfe-c5ad-4e6b-acea-bfd211560c38n%40googlegroups.com.


[go-nuts] Tracing across local subprocesses?

2022-02-17 Thread Matt Mueller
Hi there,

I was wondering if anyone has a solution for tracing across local 
subprocesses in Go?

Can the standard library do this somehow? OpenTelemetry seems a bit 
overkill for this use case.

Thanks!
Matt

-- 
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/0fa61e46-3394-4a72-ad2b-578248192b11n%40googlegroups.com.


Re: [go-nuts] Anyway to wrap or tweak a test file before running go test?

2021-11-03 Thread Matt Mueller
Hey, thanks. I'm aware of this approach.

I'm hoping for some technique that automatically injects, since it can be 
cumbersome to inject all your dependencies by hand. 

Similar to google/wire, but without the generated file sitting in the 
filesystem next to your test.

Matt 


On Wednesday, November 3, 2021 at 4:16:04 PM UTC-5 ben...@gmail.com wrote:

> func connectToDB(t *testing.T) *postgres.DB {
>> t.Helper()
>> // set up the connection, using t.Fatalf if an error occurs
>> return conn
>> }
>>
>> func UserTest(t *testing.T) {
>> db := connectToDB(t)
>> }
>>
>
> Yeah, that's a good way.
>
> And if you want to avoid re-connecting to the db every test, you can use a 
> top-level test function for the "suite", and sub-tests with t.Run() for the 
> individual tests, with the sub-tests closing over the db variable. Like so:
>
> func TestDatabaseThings(t *testing.T) {
> db := connectToDB(t)
>
> t.Run("Foo", func (t *testing.T) {
> fmt.Println(db, "test foo stuff") // use "db" and test stuff
> })
>
> t.Run("Bar", func (t *testing.T) {
> fmt.Println(db, "test bar stuff") // use "db" and test stuff
> })
> }
>
> -Ben
>
>

-- 
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/2a237fed-ba58-436a-b8e8-5c5be3c5c47cn%40googlegroups.com.


[go-nuts] Re: Go on AWS Lambda?

2021-11-03 Thread Matt Mueller
I'd say you pay a bit less for the memory you consume. Generally it runs 
faster than the more common JS or Python serverless functions, so you also 
pay less there.

I'd argue the main reason to use Go on Serverless is because you'd like to 
deploy to a Serverless environment and you prefer writing your backend code 
in Go over the other options.

Two libraries that make deploying Go functions to AWS very easy:
- https://github.com/apex/up
- https://github.com/apex/apex (deprecated but still works great)

Hope this helps,
Matt
On Tuesday, November 2, 2021 at 8:43:06 PM UTC-5 leam...@gmail.com wrote:

> I know Go can go on AWS Lambda, but I'm noob enough not to see how the 
> memory performance value of Go translates to serverless. What are the 
> benefits to using Go on AWS serverless?
>
> Thanks!
>
> Leam
>
> -- 
> Systems Programmer (reuel.net/resume)
> Scribe: The Domici War (domiciwar.net)
> General Ne'er-do-well (github.com/LeamHall)
>

-- 
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/40958846-0378-47f4-895c-ab5a2b15d807n%40googlegroups.com.


[go-nuts] Anyway to wrap or tweak a test file before running go test?

2021-11-03 Thread Matt Mueller
I'm looking for a way to inject test dependencies into a test suite. 
Something like:

```
package user_test

func UserTest(t *testing.T, db *postgres.DB) {
  fmt.Println("running user test", New("Alice Wonderland"))
}
```

```
go_test ./user_test.go
```

Where go_test would either manipulate the file in memory and pass it to go 
test, or wrap it somehow in a separate go test file someplace else. I'm 
trying to make this as transparent to the developer as possible. Just like 
how go test works.

Any ideas? Thanks!

Matt

-- 
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/7ef4b9e0-3591-4505-9ce8-2bb9a7e76fe6n%40googlegroups.com.


[go-nuts] What's the BUG in the flag package?

2021-03-24 Thread Matt Mueller
I noticed a lonely BUG comment without an explanation in the flag 
package: https://github.com/golang/go/blob/master/src/flag/flag.go#L955

I did a quick `git blame` and it goes all the way back to the initial 
commit: 
https://github.com/golang/go/commit/ac0dd5ae525db0d057e94c03c3f506bc30afae31.

Any ideas what the bug could be? Maybe this can be removed and I should 
open a PR?

Thanks!
Matt

-- 
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/0adc9978-7c9b-4de9-a1c5-eba3c477492an%40googlegroups.com.


Re: [go-nuts] What does `go install path/to/main.go` do with GO111MODULE=on?

2021-03-10 Thread Matt Mueller
Thanks for the message! Unfortunately, 

GOBIN=$GOPATH/bin go install ./cmd/app/main.go

Doesn't change anything. Actually I'm realizing that even without go 
modules but with $GOPATH this never installed anywhere:

GOBIN=$GOPATH/bin GO111MODULE=off go install ./cmd/testinstall/main.go

You have to do:

cd ./cmd/app && go install

Then it appears to work in all cases. 

I'm assuming this is by design, but it feels to me like go install 
./cmd/app/main.go silently failing is a bug.

Is this worth opening an issue for?


On Thursday, March 11, 2021 at 12:08:09 AM UTC+1 Kurtis Rader wrote:

> Do you have environment var GOBIN set? Check the output of "go env GOBIN". 
> See https://golang.org/ref/mod#mod-commands.
>
> On Wed, Mar 10, 2021 at 2:59 PM Matt Mueller  wrote:
>
>> Hey folks, 
>>
>> I'm trying to install a command inside a module globally on my system so 
>> that I can use that binary elsewhere. During the $GOPATH era this worked 
>> something like this:
>>
>> go install cmd/app/main.go
>> // installed app to $GOPATH/bin
>>
>> Unfortunately that doesn't seem to work anymore. It doesn't error, but I 
>> don't know where it installed the binary. Not in $GOPATH/bin.
>>
>> I've read the documentation for `go help install`. It pointed me to `go 
>> help modules`, but then I got lost after that.
>>
>> Any pointers would be greatly appreciated. Thanks!
>>
>> Matt
>>
>> -- 
>> 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.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/golang-nuts/ad5e444b-7d40-464b-9848-e2135d1788e0n%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/golang-nuts/ad5e444b-7d40-464b-9848-e2135d1788e0n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
>
> -- 
> Kurtis Rader
> Caretaker of the exceptional canines Junior and Hank
>

-- 
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/aa91e235-2984-4f83-8c8c-6daa3d185af2n%40googlegroups.com.


[go-nuts] What does `go install path/to/main.go` do with GO111MODULE=on?

2021-03-10 Thread Matt Mueller
Hey folks, 

I'm trying to install a command inside a module globally on my system so 
that I can use that binary elsewhere. During the $GOPATH era this worked 
something like this:

go install cmd/app/main.go
// installed app to $GOPATH/bin

Unfortunately that doesn't seem to work anymore. It doesn't error, but I 
don't know where it installed the binary. Not in $GOPATH/bin.

I've read the documentation for `go help install`. It pointed me to `go 
help modules`, but then I got lost after that.

Any pointers would be greatly appreciated. Thanks!

Matt

-- 
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/ad5e444b-7d40-464b-9848-e2135d1788e0n%40googlegroups.com.


Re: [go-nuts] Can we "go get" unreleased standard library packages?

2020-12-02 Thread Matt Mueller
Ah, that's a great point. Thanks for taking the time to explain it!

I'll wait for the beta then – thanks!

On Thursday, December 3, 2020 at 1:10:51 AM UTC+1 axel.wa...@googlemail.com 
wrote:

> No, that's not really possible. The stdlib is packaged with the Go 
> compiler and is very interdependent.
> It also wouldn't help you a lot, because in go1.15, the `io/fs` package 
> has no implementation yet. For example, (*os.File).Stat does not return the 
> correct type, compare
> https://tip.golang.org/pkg/os/#FileInfo
> with
> https://golang.org/pkg/os/#FileInfo
>
> If you want to experiment, you have to use a go version compiled from tip. 
> You can already develop against it, if you use build tags to guard on 
> go1.16 (though keep in mind that the interfaces could, theoretically, still 
> change).
>
> Otherwise you just have to wait for go1.16. A beta should be released soon 
> (probably next week, AIUI).
>
>
> On Thu, Dec 3, 2020 at 12:32 AM Matt Mueller  wrote:
>
>> Hey there, I'd like to try the io/fs package on Go 1.15. Is there an easy 
>> way to do this?
>>
>> I tried without much expectation:
>>
>> go get -u github.com/golang/go/src/io/fs
>>
>> But was greeted with this error:
>>
>> go: found github.com/golang/go/src/io/fs in github.com/golang/go/src 
>> v0.0.0-20201202201757-2d0258d49568
>> go get: github.com/golang/go/s...@v0.0.0-20201202201757-2d0258d49568 
>> <http://github.com/golang/go/src@v0.0.0-20201202201757-2d0258d49568>: 
>> parsing go.mod:
>> module declares its path as: std
>> but was required as: github.com/golang/go/src
>>
>> Any ideas? 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...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/golang-nuts/8857da92-774a-453b-9c81-46bf818b38b6n%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/golang-nuts/8857da92-774a-453b-9c81-46bf818b38b6n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
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/1d0d62b9-e0fa-4315-bea0-b106db18e3b4n%40googlegroups.com.


[go-nuts] Can we "go get" unreleased standard library packages?

2020-12-02 Thread Matt Mueller
Hey there, I'd like to try the io/fs package on Go 1.15. Is there an easy 
way to do this?

I tried without much expectation:

go get -u github.com/golang/go/src/io/fs

But was greeted with this error:

go: found github.com/golang/go/src/io/fs in github.com/golang/go/src 
v0.0.0-20201202201757-2d0258d49568
go get: github.com/golang/go/src@v0.0.0-20201202201757-2d0258d49568: 
parsing go.mod:
module declares its path as: std
but was required as: github.com/golang/go/src

Any ideas? 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/8857da92-774a-453b-9c81-46bf818b38b6n%40googlegroups.com.


Re: [go-nuts] Re: Generating code into module cache?

2020-10-21 Thread Matt Mueller
Thanks for your thoughts!

> I'm not sure what the advantages would be over doing the normal approach 
of generating the files and committing them?

Mostly trying to improve the UX by avoiding generated code clutter during 
development. I concede that storing all your generated code in one 
directory inside your project isn't that big of a deal. Another solution 
could be to configure your editor to hide the generated directory. 

> So we are talking local development only.

Yah, exactly. The CLI wraps "go run" anyway, so there's a place to generate 
code on new machines before starting the program.

> In which case replace directives with a directory target is most likely 
your best solution:

Replace is an interesting idea. I think replace would work well if there 
was a standard place to put generated code outside of your project. I guess 
that's what I'm looking for: a standard place to hide away generated code 
until you care about it and want to vendor it. And when you do want to 
vendor it, you can use the same code paths as your third-party dependencies.

On Wednesday, October 21, 2020 at 8:25:33 AM UTC+2 Paul Jolly wrote:

> I would personally steer clear of writing anything to the module cache.
>
> If you are only code generating into the module cache and not
> publishing this generated code, by definition that generated content
> will not be available remotely. Hence any code you publish that
> depends on this generated content will fail to resolve. So we are
> talking local development only.
>
> In which case replace directives with a directory target is most
> likely your best solution:
>
> https://golang.org/ref/mod#go-mod-file-replace
>
> On Wed, 21 Oct 2020 at 00:12, 'Axel Wagner' via golang-nuts
>  wrote:
> >
> > On a second read, I probably misunderstood what you intend to do.
> > I still think what you intend to do might technically be possible - I'm 
> not entirely sure, though. The module cache is by default read-only, so 
> you'd want a tool that force-replaces a directory. And then, the go build 
> cache might get confused, if the contents of the cache change. I'd also 
> predict that you regularly run into issues where things don't build the 
> same on your machine as for other people, leading to hard to debug and 
> confusing errors. And, lastly, I'm not sure what the advantages would be 
> over doing the normal approach of generating the files and committing them? 
> It seems strictly more work, with no added benefits.
> >
> > On Wed, Oct 21, 2020 at 1:06 AM Axel Wagner  
> wrote:
> >>
> >> Technically, I think this would be possible. Your code wouldn't be 
> usable together with code that doesn't use modules. And you'd need to have 
> a server that takes the code from the git repository and generates a .zip 
> file for any interesting version (possibly on demand), which you would 
> probably have to build yourself. It also means there is no reliable 
> provenance from your git repository to your published module, so 
> reproducing/forking what you do might be more difficult. Code analysis 
> running from the repository (like sourcegraph or githubs hover info) might 
> not understand the code anymore.
> >>
> >> But, yeah. In general, you can put *any* go code in an appropriate 
> .zip-file and serve it up as a module. You don't even have to publish the 
> repository itself at all, if you so wish.
> >>
> >> On Wed, Oct 21, 2020 at 12:39 AM Matt Mueller  
> wrote:
> >>>
> >>> Sorry, maybe cache is the wrong word.
> >>>
> >>> Wherever "go get -u ..." downloads modules, I'd like to stick my 
> generated code.
> >>>
> >>> Conceptually you could think of it as a virtual module used only 
> during development. If you're familiar with Node.js, You could also think 
> of it as creating a directory in node_modules/ and then importing it with 
> require(...).
> >>>
> >>> I'm just wondering if I'll run into issues doing this or mess up other 
> people's modules.
> >>>
> >>> On Tuesday, October 20, 2020 at 9:22:05 PM UTC+2 seank...@gmail.com 
> wrote:
> >>>>
> >>>> That doesn't really make sense?
> >>>> The module cache is for immutable versions of modules,
> >>>> ie. publish your (generated) code as a package/module, import that
> >>>> it will then get cached
> >>>>
> >>>> On Tuesday, October 20, 2020 at 8:50:25 PM UTC+2 mattm...@gmail.com 
> wrote:
> >>>>>
> >>>>> Hey folks,
> >>>

[go-nuts] Re: Generating code into module cache?

2020-10-20 Thread Matt Mueller
Sorry, maybe cache is the wrong word.

Wherever "go get -u ..." downloads modules, I'd like to stick my generated 
code. 

Conceptually you could think of it as a virtual module used only during 
development. If you're familiar with Node.js, You could also think of it as 
creating a directory in node_modules/ and then importing it with 
require(...).

I'm just wondering if I'll run into issues doing this or mess up other 
people's modules.

On Tuesday, October 20, 2020 at 9:22:05 PM UTC+2 seank...@gmail.com wrote:

> That doesn't really make sense? 
> The module cache is for immutable versions of modules,
> ie. publish your (generated) code as a package/module, import that
> it will then get cached
>
> On Tuesday, October 20, 2020 at 8:50:25 PM UTC+2 mattm...@gmail.com wrote:
>
>> Hey folks, 
>>
>> I'm working on a project with a lot of code generation. I'd love to:
>>
>> - get the code generation out of the way when you don't care about it
>> - be able to vendor the generated code when you do care about it
>>
>> That led me to an idea about generating code into the go module cache. Do 
>> you see any downside in doing this? 
>>
>> Thanks!
>> Matt
>>
>

-- 
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/a26c4aca-bbe3-4dc5-9f66-09d1db521517n%40googlegroups.com.


[go-nuts] Generating code into module cache?

2020-10-20 Thread Matt Mueller
Hey folks, 

I'm working on a project with a lot of code generation. I'd love to:

- get the code generation out of the way when you don't care about it
- be able to vendor the generated code when you do care about it

That led me to an idea about generating code into the go module cache. Do 
you see any downside in doing this? 

Thanks!
Matt

-- 
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/50350276-d3b4-4971-8e58-357c46e64214n%40googlegroups.com.


[go-nuts] Re: Why does x/tools/go/packages use `go list` under the hood?

2020-08-17 Thread Matt Mueller
I think I got it. It looks like `go list` uses an internal cache to make 
its use really fast. Hopefully this package gets merged into the stdlib and 
we can take advantage of the cache directly!

On Monday, August 17, 2020 at 11:22:52 PM UTC+2 Matt Mueller wrote:

> Hi folks,
>
> I was looking into where my packages.Load time was being spent and I 
> noticed that under the hood the packages library calls out to "go list" for 
> information.
>
> I'm just wondering if there's any specific reason for this? It seems like 
> fairly low-hanging fruit performance-wise to not spawn additional processes.
>
> Thanks!
> Matt
>

-- 
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/44687ba3-af67-44d5-ad0a-6de6c59f88acn%40googlegroups.com.


[go-nuts] Why does x/tools/go/packages use `go list` under the hood?

2020-08-17 Thread Matt Mueller
Hi folks,

I was looking into where my packages.Load time was being spent and I 
noticed that under the hood the packages library calls out to "go list" for 
information.

I'm just wondering if there's any specific reason for this? It seems like 
fairly low-hanging fruit performance-wise to not spawn additional processes.

Thanks!
Matt

-- 
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/ae1dce34-6547-4464-b1a2-c0527e0ce8c3n%40googlegroups.com.


[go-nuts] Measuring go run and go build times?

2020-07-29 Thread Matt Mueller
I'm working on a dev tool for automatically reloading the server when you 
change a file.

I'd like for the reload time to be as fast as possible. Are there any flags 
or environment variables that I can set to see where the time is being 
spent (compiling, linking etc.)? Also seeing what packages are cached and 
which are not would be very helpful.

Also if you have any recommendations for makes this as fast as possible 
(turning off optimizations, etc.) please let me know!

Thanks!
Matt

 

-- 
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/c6042560-1863-42b1-a84c-d4696fa60618o%40googlegroups.com.


[go-nuts] Choosing thread for goroutine?

2020-07-19 Thread Matt Mueller
Hey folks,

I'm working on a server-side Javascript rendering package in Go. It uses 
https://bellard.org/quickjs/ for it's parser and interpreter. I'm using 
https://github.com/lithdew/quickjs to package it with Go.

Quickjs appears to have some thread-local memory, so I'm 
use runtime.LockOSThread() to make sure that the goroutine is always placed 
on the same thread. I'm using a worker pattern to distribute load.

The problem I'm running into is that sometimes worker's goroutines get 
scheduled (and then locked) to the same thread, effectively serializing the 
computation. This seems random and causes a loss in parallelism since these 
goroutines will remain on the same thread through their lifetime.

Are there any workarounds with this issue?

Thanks!
Matt


-- 
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/c1e1e698-c227-42a4-bdc9-332ea15509f9o%40googlegroups.com.


[go-nuts] Safe to treat time.Local != time.LoadLocation("your current timezone")?

2018-10-18 Thread Matt Mueller
Hey folks,

I'm trying to ensure that the user must pass a specific location (anything 
but time.Local) into a function.

I'd like to add a check like this:

// ensure we didn't pass in an offset the default time.Local
if offset.Location() == time.Local {
 return nil, errors.New("offset use a specific timezone")
}


But I'm just not sure if the user happens to specify the timezone that 
matches time.Local that this may evaluate as true. From preliminary tests, 
it seems like it should be fine, but I'd like to double-check.

Thanks!

Matt

-- 
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] Closing os.Stdin while trying to read from it?

2018-03-19 Thread Matt Mueller
Thanks for the great info! 

Out of curiosity, how is Go handling ctrl+d (sending EOF to stdin) right 
now? Is it part of the special case? A more generic way to ask this is: 

Is it possible to programmatically tell os.Stdin that we've reached EOF 
while you're trying to read from it?

On Friday, March 16, 2018 at 7:56:08 PM UTC+7, Ian Lance Taylor wrote:
>
> On Fri, Mar 16, 2018 at 5:29 AM, Alex Efros  > wrote: 
> > 
> > On Thu, Mar 15, 2018 at 12:49:15PM +, roger peppe wrote: 
> >> If it helps, you can set deadlines on *os.File now, as of Go 1.10: 
> >> 
> >>https://play.golang.org/p/h3Pg9Ql0CMB 
> >> 
> >> I don't see a way to cancel without deciding the deadline in advance 
> though. 
> > 
> > Why? What makes os.Stdin so special? 
> > 
> > If we add this at beginning of main() it'll work as expected: 
> > os.Stdin, _ = os.Open("/dev/stdin") 
>
> What is special about os.Stdin is the way it is initialized, which is 
> to say it is normally in blocking mode, and therefore reads block even 
> if you close the descriptor in a different goroutine.  This would be 
> affected by changes to https://golang.org/issue/22939. 
>
> 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] Closing os.Stdin while trying to read from it?

2018-03-15 Thread Matt Mueller
Hey folks,

I'm trying to figure out how to cancel reading from stdin programmatically. 
Basically the same way that ctrl+d works on OSX.

I would have thought this would work, but this program will just run 
forever:

package main


import (
 "io/ioutil"
 "os"
 "time"
)


func main() {
 go func() {
 time.Sleep(time.Second)
 println("closing...")
 os.Stdin.Close()
 }()

 _, _ = ioutil.ReadAll(os.Stdin)
 println("done")
}


Any help would be much appreciated – 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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Where to stick temporary go files after an AST rewrite?

2017-12-28 Thread Matt Mueller
Oh that's brilliant, I didn't realize $GOPATH acted like $PATH. Haha, seems 
obvious when writing it out, but I thought it was just an environment 
variable. Thanks Matt!

On Wednesday, December 27, 2017 at 10:40:21 AM UTC+7, Matt Harden wrote:
>
> You can put them anywhere on your GOPATH. So for example, if you're on a 
> unix-y system, $HOME/go is normally your GOPATH, and you want to rewrite 
> the file $HOME/go/src/github.com/my/repo/hello.go, you could store the 
> rewritten file at /tmp/go/src/github.com/my/repo/hello.go, and run the go 
> tool with the GOPATH environment variable set to /tmp/go:$HOME/go. This 
> would cause the tool to find the rewritten file before the original. If 
> there are other files in the same package that you are *not* rewriting, 
> you may have to copy those anyway to the new directory; I'm not sure 
> whether the go tool expects all files in a package to be in the same 
> directory or not.
>
> The way to call "go run" from Go is to use the os/exec 
> <http://godoc.org/os/exec#example-Cmd-CombinedOutput> package to 
> literally run the command.
>
> On Mon, Dec 25, 2017 at 6:48 AM Matt Mueller  > wrote:
>
>> Hey folks!
>>
>> I'm using the new 
>> https://godoc.org/golang.org/x/tools/go/ast/astutil#Apply function, but 
>> keep running into the question:
>>
>> After I rewrite these files, where do I stick them so they're still 
>> buildable with the rest of the program? Is there anyway to call "go run" 
>> after modifying the AST of these files? 
>>
>> 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...@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] Where to stick temporary go files after an AST rewrite?

2017-12-25 Thread Matt Mueller
Hey folks!

I'm using the new https://godoc.org/golang.org/x/tools/go/ast/astutil#Apply 
function, but keep running into the question:

After I rewrite these files, where do I stick them so they're still 
buildable with the rest of the program? Is there anyway to call "go run" 
after modifying the AST of these files? 

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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] TCP writes without a corresponding read?

2017-10-23 Thread Matt Mueller
Thanks for taking the time to respond Ian! If I'm understanding you 
correctly, the client's socket is what's storing the buffer. When accept is 
called, it looks in the queue of pending requests and it then creates a 
matching socket on the server. Is that right? 

The thing that's still throwing me is the 
following: https://play.golang.org/p/YjxTKDYwnj

func TestTCP(t *testing.T) {
  ln, err := net.Listen("tcp", "127.0.0.1:0")
  if err != nil {
panic(err)
  }

  // mock server
  connected := make(chan bool)
  go func() {
conn, err := ln.Accept()
if err != nil {
  panic(err)
}

fmt.Printf("closing connection\n")
if e := conn.Close(); e != nil {
  panic(e)
}

fmt.Printf("closing listener\n")
if e := ln.Close(); e != nil {
  panic(e)
}

close(connected)
  }()

  client, e := net.Dial("tcp", ln.Addr().String())
  if e != nil {
panic(e)
  }

  <-connected

  fmt.Printf("writing...\n")
  n, e := client.Write([]byte("hi world!"))
  if e != nil {
panic(e)
  }
  fmt.Printf("wrote %d bytes\n", n)
}

Results in: 

closing connection
closing listener
writing...
wrote 9 bytes



Playground link: https://play.golang.org/p/YjxTKDYwnj

Anyone know what's going on here? I would have thought that write would 
return EOF after closing the connection, but at the very least, after 
closing the listener.

Thanks!

Matt

On Tuesday, October 24, 2017 at 12:43:21 AM UTC+7, Ian Lance Taylor wrote:
>
> On Mon, Oct 23, 2017 at 10:25 AM, Matt Mueller  > wrote: 
> > 
> > Ah thanks guys for the insights, this led me to do some more digging: 
> > 
> > http://man7.org/linux/man-pages/man2/listen.2.html 
> > http://man7.org/linux/man-pages/man2/accept.2.html 
> > 
> > - Looks like Listen() creates a socket and a backlog queue. 
> > - When you call Dial(), the connection request gets stored in that 
> backlog 
> > - When you call Accept(), the connection gets dequeued and a new socket 
> is 
> > made for that connection 
> > 
> > What I still don't quite understand is, what happens to the written 
> bytes 
> > between Listen() and Accept()? Do they get buffered in that backlog 
> queue as 
> > well? 
>
> No, they are stored in the socket's buffer.  The backlog queue is a 
> queue of sockets. 
>
> 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] TCP writes without a corresponding read?

2017-10-23 Thread Matt Mueller
Ah thanks guys for the insights, this led me to do some more digging:

http://man7.org/linux/man-pages/man2/listen.2.html
http://man7.org/linux/man-pages/man2/accept.2.html

- Looks like Listen() creates a socket and a backlog queue.
- When you call Dial(), the connection request gets stored in that backlog
- When you call Accept(), the connection gets dequeued and a new socket is 
made for that connection

What I still don't quite understand is, what happens to the written bytes 
between Listen() and Accept()? Do they get buffered in that backlog queue 
as well?

Matt

On Sunday, October 22, 2017 at 5:07:49 PM UTC+7, Ayan George wrote:
>
>
>
> On 10/22/2017 06:06 AM, Ayan George wrote: 
> > 
> > 
> > buf := make([]byte, 0, 20) 
> > 
>
> Sorry -- I meant: 
>
>   buf := make([]byte, 20) 
>
>
>

-- 
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] TCP writes without a corresponding read?

2017-10-22 Thread Matt Mueller
Hey everyone!

This question cropped up while testing. It's 2 related questions:

*1. Why am I able to write to without accepting a connection?*

  addr, err := net.ResolveTCPAddr("tcp", "127.0.0.1:0")
  if err != nil {
t.Fatal(err)
  }

  ln, err := net.ListenTCP("tcp", addr)
  if err != nil {
t.Fatal(err)
  }
  defer ln.Close()

  raddr, err := net.ResolveTCPAddr("tcp", ln.Addr().String())
  if err != nil {
t.Fatal(err)
  }

  client, e := net.DialTCP("tcp", nil, raddr)
  if e != nil {
t.Fatal(e)
  }

  if n, e := client.Write([]byte("hi world!")); e != nil {
fmt.Printf("error writing %s\n", e)
  } else {
fmt.Printf("wrote %d bytes\n", n)
  }

This will come back as: "wrote 9 bytes"
- https://play.golang.org/p/HmiRu-9xEv

*2. How would I only allow it to write what it's able to read? In this 
example, the server connection only reads 1 byte before closing. This would 
be useful for testing flaky connections and retry logic:*

addr, err := net.ResolveTCPAddr("tcp", "127.0.0.1:0")
if err != nil {
  t.Fatal(err)
}

ln, err := net.ListenTCP("tcp", addr)
if err != nil {
  t.Fatal(err)
}
defer ln.Close()

// mock server
go func() {
  for {
s, e := ln.AcceptTCP()
if e != nil {
  t.Fatal(e)
}

buf := make([]byte, 1)
if n, e := s.Read(buf); e != nil {
  t.Fatal(e)
} else {
  fmt.Printf("read %d bytes\n", n)
}

// close before reading everything
s.Close()
  }
}()

// make the connection to our little server
raddr, err := net.ResolveTCPAddr("tcp", ln.Addr().String())
if err != nil {
  t.Fatal(err)
}

client, e := net.DialTCP("tcp", nil, raddr)
if e != nil {
  t.Fatal(e)
}

if n, e := client.Write([]byte("hi world!")); e != nil {
  fmt.Printf("error writing %s\n", e)
} else {
  fmt.Printf("wrote %d bytes\n", n)
}

This will come back as: "wrote 9 bytes", "read 1 bytes"
- https://play.golang.org/p/-T2UunLy5T

Thanks for the help in advance!

Matt

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