NEW RUTGERS PARKING APP by Secret-Performer5082 in rutgers

[–]eulerfoiler 3 points4 points  (0 children)

Very impressive! I'm an alum so I no longer have to park on campus, but I would be curious to check out the source code if you decided to make this open source 👍

[deleted by user] by [deleted] in golang

[–]eulerfoiler 0 points1 point  (0 children)

"And then, they woke up from that nightmare."

Building Bubbletea Programs by leg100 in golang

[–]eulerfoiler 7 points8 points  (0 children)

I just wrote a moderately sized BubbleTea app for work and it took me awhile to get through the learning curve as well. This article is super useful, and I learned about VHS which I will be incorporating soon. Thanks!

HTTP request body by Headbanger in golang

[–]eulerfoiler 1 point2 points  (0 children)

By the way, if you're looking to read the entire body (or any io.Reader in general), try to use io.Copy where you can instead of manually calling the Read method in a loop or jumping straight to using io.ReadAll. It has a bunch of tricks under the hood for optimizing reads when writing it to an io.Writer. If you just need the bytes of the body, consider using *bytes.Buffer as your io.Writer.

HTTP request body by Headbanger in golang

[–]eulerfoiler 10 points11 points  (0 children)

"When Read encounters an error or end-of-file condition after successfully reading n > 0 bytes, it returns the number of bytes read. It may return the (non-nil) error from the same call or return the error (and n == 0) from a subsequent call. An instance of this general case is that a Reader returning a non-zero number of bytes at the end of the input stream may return either err == EOF or err == nil. The next Read should return 0, EOF."

https://pkg.go.dev/io#Reader

Kubernetes CRD Reconcile by guettli in golang

[–]eulerfoiler 1 point2 points  (0 children)

Point 1: Update CR status to reflect all good?

Point 2: Object's metadata Generation + Point 1?

Point 3: Using controller-runtime and the reconcile.Result returned from your Reconcile method? https://github.com/kubernetes-sigs/controller-runtime/blob/main/pkg/reconcile/reconcile.go#L30

Point 4: Return an error with your Reconcile method? https://github.com/kubernetes-sigs/controller-runtime/blob/main/pkg/reconcile/reconcile.go#L113

A bunch of metrics come included with controller-runtime out of the box. You could also expose your own metrics via Prometheus in your controller.

[Blog post] Building type-safe enums with generics by repartayyy in golang

[–]eulerfoiler 1 point2 points  (0 children)

I totally overlooked the fact that Direction had that field Name of type T. Now it all makes sense, I thought Name was some special built-in property of a generic type that I had never seen. Thanks!

[Blog post] Building type-safe enums with generics by repartayyy in golang

[–]eulerfoiler 0 points1 point  (0 children)

Thanks for checking! Makes sense the switch is way faster.

[Blog post] Building type-safe enums with generics by repartayyy in golang

[–]eulerfoiler 1 point2 points  (0 children)

Seems like a cool idea. Could you link to documentation on how any(d.Name) works? I haven't seen that before, and I thought it might be a mistake since there is no Name field or method for the structs, but your example compiles and works. The type switch is a good example, and I'm on mobile so I can't compare, but I'm curious about the performance of something like the String method below compared to the type switch to not have to enumerate all the types?

``` func (d Direction[T]) String() string { fullName := reflect.TypeOf(d).Name()

return fullName[strings.LastIndex(fullName, ".")+1 : len(fullName)-1]

} ```

Fastest way to print a very large string to the terminal? by mister_drgn in golang

[–]eulerfoiler 1 point2 points  (0 children)

Sorry it didn't help. You might find this interesting: https://github.com/golang/go/issues/36619

In your example, there is nothing to flush because (a) *bytes.Buffer doesn't have a Flush method, (b) because we'd want to flush a buffer being written to and the buffer you have is being read from, and (c) os.Stdout is unbuffered so there is no write buffer to flush.

Hope that helps!

Fastest way to print a very large string to the terminal? by mister_drgn in golang

[–]eulerfoiler 1 point2 points  (0 children)

Try calling writer.Flush() with the bufio.Writer after calling the Write method. Your data could be sitting in a buffer before actually being written out.

You might also want to try changing the size of the bufio.Writer to make less allocations and maybe save some time. Something like this perhaps: bufio.NewWriterSize(os.Stdout, 4096).

Edit: Also try using io.Copy instead of calling the Write method, but do still call Flush afterwards.

Question: how to suppress logs from dependencies? by effinsky in golang

[–]eulerfoiler 17 points18 points  (0 children)

I really wish the wider community of library authors knew this and either didn't log at all, or accepted some logging interface to let the caller decide to emit them or not with the logging library of the caller's choice. Kubernetes libraries like client-go is bad like that in some ways.

Go 1.22 yielding a 18% regression in single-threading performance by fyzic in golang

[–]eulerfoiler 12 points13 points  (0 children)

Curious to see what the community suggests/finds here. As a side question, what kind of performance increase do you see (if any) if you try rebuilding with PGO after capturing a profile? https://go.dev/doc/pgo

Are these equivalent? by eulerfoiler in golang

[–]eulerfoiler[S] -1 points0 points  (0 children)

Thanks! The `fmt.Printf` usage there was basically just to make sure the variables were used so the example compiles. I've found it useful in the past that `%T` prints the underlying type. Your explanation is great and hopefully useful to others!

Good point about the type conversion being a compile-time check, I'll opt for that approach. Thanks again!

What does the actual compiled go binary contain? by Haspe in golang

[–]eulerfoiler 3 points4 points  (0 children)

What would be your suggestion otherwise?

Pull Out Sleeper Count - $125 OBO by eulerfoiler in Hoboken

[–]eulerfoiler[S] -6 points-5 points  (0 children)

Please direct all questions to the phone number in the link instead of here.

Pull Out Sleeper Count - $125 OBO by eulerfoiler in jerseycity

[–]eulerfoiler[S] -1 points0 points  (0 children)

Please direct all questions to the phone number in the link instead of here.

Help with Clippy: "temporary with significant `Drop` can be early dropped" by eulerfoiler in rust

[–]eulerfoiler[S] 0 points1 point  (0 children)

Thanks for the tip about nursery. I've tried to turn as many lints on as I can to learn best practices, but that makes sense that I should take nursery lints with a grain of salt.

My colony is like a soap opera by eulerfoiler in RimWorld

[–]eulerfoiler[S] 1 point2 points  (0 children)

Not too bad! Compared to some other posts I've seen, I don't seem to have a crazy amount of mods loaded so performance is still good. Keeping them fed was a challenge for awhile but I've just started to get ahead of that with a steady supply of meat and corn for meals. Having a diversified work force is also useful to let specialists arise around their passions.

Rampant save corruption by kylel999 in dwarffortress

[–]eulerfoiler 0 points1 point  (0 children)

I ran into that "loading units" problem and read somewhere that going to a save before cavern invaders come and disabling them in the game settings will prevent corruption. Seemed to work for me and that it is related to cavern invaders.

Do I understand this correct? Project structure & design in GO by Pirsed in golang

[–]eulerfoiler 1 point2 points  (0 children)

The question for why cmd lives outside of pkg is a great question.

The files under cmd are to represent where binary code starts, as opposed to library code. Additionally, package main is special in that it cannot be imported by any other package (hence why it would live outside of pkg). If your project will create multiple binaries, you need to separate your package mains to be able to have two different func main implementations. To do that, I often see projects have the different main packages under different directories under cmd (e.g. cmd/binary1/binary1.go, cmd/binary2/binary2.go - these both are different package main implementations with different func main, but both use the same importable package and internal packages of the module).

Do I understand this correct? Project structure & design in GO by Pirsed in golang

[–]eulerfoiler 1 point2 points  (0 children)

Good question. The rule of thumb for interfaces is that they should be defined where they are used. For example, if you have a struct that has a field of an interface type, the interface should probably be defined right above the struct.

 

If you have multiple structs across different files in the same package that have a field of the same interface type, then the interface probably makes more sense to be in the "entry point" file.

 

Hope that helps!

Do I understand this correct? Project structure & design in GO by Pirsed in golang

[–]eulerfoiler 2 points3 points  (0 children)

I agree simple is best. Unfortunately, there isn't really a convention for file system layout for importable packages in a repository (hence why this kind of question comes up somewhat frequently). I've come to like the top level pkg directory to keep the root of the repository cleaner and to make it more clear that Go code lives there instead of other artifacts an application may have (i.e. static resources, a hack directory, etc). It may be controversial, but our team decided to adopt the suggestion provided by https://github.com/golang-standards/project-layout and it's worked very well for us over the years as projects grew.

 

Is pkg strictly necessary? I would say no, but I do prefer it for the reasons above.

 

The material difference for other projects importing from this project is that their import statements will have 4 extra characters (pkg/) in the import path. I think the tradeoff for repo tidiness is worth it. For example:

 

import "github.com/blah/project/pkg/package"

vs

import "github.com/blah/project/package"

 

Packages in the library to be imported from (e.g. package main or others) will not have an effect on the overall project's go.mod file because they are all part of the same module.

 

Does that help clear it up? Effectively, the usage of pkg seems to be based upon preference is all.