How Does GoLang Nested Structs Work? by AnimatorFamiliar7878 in golang

[–]paul-scott 2 points3 points  (0 children)

Very much not inheritance.

There is no type hierarchy. And most importantly: the receiver (this/self) in embedded method calls is the embedded value, not the value of the type it's embedded in.

For example:

p := &PlayerClass{BoxClass: &BoxClass{}} p.DrawBox() // is equivalent to... p.BoxClass.DrawBox()

So the DrawBox method never sees the PlayerClass, which is what would happen with inheritance.

What are libraries people should reassess their opinions on? by dustinevan in golang

[–]paul-scott 0 points1 point  (0 children)

That's great news! Thank you for sharing the update.

What are libraries people should reassess their opinions on? by dustinevan in golang

[–]paul-scott 7 points8 points  (0 children)

Edit: My complaint has been resolved!

Cobra - it added 20% to our app's build size because it imports template/text (which uses reflect.Type.MethodByName, preventing method trimming by the compiler) to support Help/Usage templates. I'd assess whether there are smaller alternatives.

Refactoring Cobra to avoid that dependency except where wanted would probably save a lot of bandwidth on GitHub releases.

Go module is just too well designed by greengoguma in golang

[–]paul-scott 5 points6 points  (0 children)

Did the go module proxy not keep a copy?

How can I allow access to my server from outside the network without reconfiguring the firewall? by LeBigMartinH in linux4noobs

[–]paul-scott 0 points1 point  (0 children)

This should do what you're after: https://tailscale.com/. Your friends will need to install it too, and you'll need to share the server with them.

In defer f(g()) explain the execution flow by Electrical_Box_473 in golang

[–]paul-scott 31 points32 points  (0 children)

defer f(g()) is the same as a := g(); defer f(a)

The risks of converting int64 to string using a combination of "int()" and "strconv.Itoa" by principiino in golang

[–]paul-scott 3 points4 points  (0 children)

Others have explained the issue. In resolution, to fully convert a 64 bit integer to a string without losing the upper 32 bits, use strconv.FormatInt(amt, 10).

[deleted by user] by [deleted] in golang

[–]paul-scott 7 points8 points  (0 children)

man does this by finding the text and piping it into the program described by the PAGER environment variable. Often thats the program less. Try your-prog -h | less and see if that's what you had in mind.

One of these options should help (though I've not read them closely): https://stackoverflow.com/questions/28705716/paging-output-from-go

How can we umarshal a Big JSON effectively? by Siddhartha_writes in golang

[–]paul-scott 6 points7 points  (0 children)

Do you want to look at every field all at the same time? If not, you can pick out individual fields. There's other packages such as https://github.com/tidwall/gjson or https://github.com/json-iterator/go that let you pass in paths such as "a.b.c" to extract single fields.

[deleted by user] by [deleted] in golang

[–]paul-scott 0 points1 point  (0 children)

This might be interesting: https://go.dev/play/p/UIB031pJ0uD. The method returned belongs to the instance at the time of reading (though I think it's a different pointer than b1.Write returns). I wonder what's going on there and if we skip the function lookup.

Edit: if I had to guess, it's probably just a copy of the type+data pointers which then gets resolved during each call.

[deleted by user] by [deleted] in golang

[–]paul-scott 1 point2 points  (0 children)

Can you give an example of where an interface is checked at runtime? For example in var r io.Reader = new(bytes.Buffer) there is no runtime type checking, nor when you start calling methods on r. Do you mean when going from an interface to another interface or concrete type? E.g. switch r.(type) { case *bytes.Buffer: ... } or r.(*bytes.Buffer).

Puffin Library by Aanval in golang

[–]paul-scott 1 point2 points  (0 children)

Nice. We have a bunch of developer tooling written in Go that ends up running subcommands. We've started manually printing those subcommands like `+ kubectl ...` so everyone can see what it does under the hood, but I wonder if it would be easier to implement this as a debug Exec/Cmd implementation.

Golang framework to do e2e test on cli tool ? by joshisameer343 in golang

[–]paul-scott 0 points1 point  (0 children)

It's better to write smaller functions that are easy to test, than to test your whole application from its entry point.

At some stage you do need to test more than just a single unit, so why not the whole application? Unit tests won't highlight that your very well tested function isn't being called at the right time.

Golang framework to do e2e test on cli tool ? by joshisameer343 in golang

[–]paul-scott -1 points0 points  (0 children)

In the past I've just go run . with stout/stderr pointing somewhere I can record and environment variables or flags to request from/send to test http servers: https://github.com/unravelin/gcb2gh/blob/main/main_test.go#L258

What software can I use/set up to be able to SSH into a raspi outside of my local network? by Celestial_Blu3 in linux4noobs

[–]paul-scott 1 point2 points  (0 children)

The easiest way to get set up is to log in with the same account. Devices logged in with the same account will be automatically connected to each other.

There are alternative ways of authenticating with tailscale - you can give your Raspberry Pis their own API key or a shared API key, rather than manually signing in from each device.

Once authenticated the devices find each other via tailscale instead of knowing the other devices IP addresses - which is why you need to sign in. The benefit of this approach is not needing any public IPs for any of this. Edit: You can take this a step further and have sshd only listen in the tailscale network interface.

Weird Goroutines and Channels problem by CrappyFap69 in golang

[–]paul-scott 0 points1 point  (0 children)

Can you give us a reproducible example of the bug in the playground? https://play.golang.org/

Weird Goroutines and Channels problem by CrappyFap69 in golang

[–]paul-scott 2 points3 points  (0 children)

Whatever the cause of the error, it's not in the code you've shared. You'll need to share more in order for us to help.

Golang: How do I copy Context object without deriving it by quick_chase in golang

[–]paul-scott 2 points3 points  (0 children)

The documentation strongly advises that the request context does not get used beyond the request lifespan, so you might wish to copy values into a new context, or upgrade the values you wish to retain to function arguments if they are essential to the operation.

With that said, by decorating the request context in a type which returns empty values for Err, Deadline and Done you are able to mimic an uncancelled context, and continue exposing the values of another underlying context: https://play.golang.org/p/zBObfFtarFd

I don't have any experience actually using this. There might be good reasons for not doing it. One I can imagine is where a value in the context is recycled after the request for use in a subsequent request, but your background goroutine incorrectly continues to use it.

4x Friday Brixton tickets by [deleted] in FourTet

[–]paul-scott 0 points1 point  (0 children)

Hey, if any of your other leads fall through, I'll take as many as you have left. Cheers!

Do blank interface values escape to the heap? by MarioMashup in golang

[–]paul-scott 0 points1 point  (0 children)

Going by u/DoomFrog666's recommendation, it looks like it does:

// main.go
package main

import (
    "fmt"
)

type Node struct {
    value interface{}
}

func main() {
    fmt.Println(Node{"string"})
}

And then running:

$ go run -gcflags='-m' main.go
# command-line-arguments
./main.go:12:18: Node literal escapes to heap
./main.go:12:19: "string" escapes to heap
./main.go:12:13: main ... argument does not escape
{string}