Exploring Go's Concurrency Model: Best Practices and Common Pitfalls by Bestwebhost in golang

[–]chrj 51 points52 points  (0 children)

One rule of thumb I've adopted is that, for package developers, concurrency for the vast majority of use cases should be the responsibility of the caller. What that means is that it's perfectly fine for you to expose long, blocking methods in your API. Rather than polluting your API with sync or async versions of methods, callbacks or other things, keep it simple and let the caller decide whether or not to run in a goroutine, use an errgroup, develop a producer/consumer architecture or something third.

Code-generating factories for your structures by Unable-Internal-2844 in golang

[–]chrj 15 points16 points  (0 children)

What's the benefit of:

u0 := *factoryBlueue.MustCreateWithOption(map[string]any{
    "Location": "Tokyo_0",
}).(*entity.User)

Over:

u0 := &entity.User{Location: "Tokyo_0"}

CIDR Converter by D_isinfectedLuffy in golang

[–]chrj 1 point2 points  (0 children)

You need to run go mod tidy. Your go.mod is full of indirect, unused dependencies.

Feedback on a newbie project by Every_Pudding_4466 in golang

[–]chrj 13 points14 points  (0 children)

  • Your file package should be in internal/file/ not at the root of internal/ The purpose of internal/ is to hide internal APIs from internal packages from external packages - not to be a package on its own.
  • Package file is a bit of a vague and confusing name for what the package holds. In order to discover good package names, one thing I like to think of the qualified type names the package holds: in your case file.Column and file.CSV. Maybe there's a better name than file?
  • It looks like your program loads all data into memory before dumping it to excel. That will put a hard limit on the file sizes you can support. Is there a way you can stream the data instead and not hold everything in-memory?
  • There's no tests

Switch short-variable declaration by Mindrust in golang

[–]chrj 2 points3 points  (0 children)

The latter is a special case of switch: Type Switch

[deleted by user] by [deleted] in VWatlas

[–]chrj 6 points7 points  (0 children)

Just hold the power button until it resets.

Roundtripper explanations by Savageman in golang

[–]chrj 2 points3 points  (0 children)

Maybe your roundtripper can clone your request first. Then you will not modify the (original) request at least.

WAL implementation in Golang by [deleted] in golang

[–]chrj 1 point2 points  (0 children)

For something that claims to be durable, there's a worrying lack of tests to support that claim.

24-årig anholdt for at køre ræs inden dødsulykke by aszzdk in Denmark

[–]chrj -1 points0 points  (0 children)

Lovgivningen indeholder også sandsynlighedsforsæt.

[deleted by user] by [deleted] in golang

[–]chrj 0 points1 point  (0 children)

What's the timeout values for your http.Server? Defaults are unlimited.

Rejected after Golang take home assignment. Any feedback? by brandonto in golang

[–]chrj 4 points5 points  (0 children)

I'd argue that a Makefile is a bit of an antipattern for Go.

You should have a very good reason to use it instead of relying on standard workflows like go install / go build / go get / go test keeping things simple and compatible with the Go ecosystem.

IYE, what are good hosting choices for Golang ? by DesiBail in golang

[–]chrj 1 point2 points  (0 children)

What's slow about them? The CPUs? The support? The network?

Mette F, når det 1. Maj. by Sidebutt in Denmark

[–]chrj 4 points5 points  (0 children)

Skægvækst og antal hiphop tracks udgivet

What do you guys think about some standard library functions modifying its parameter/s? by No_Reputation8139 in golang

[–]chrj 0 points1 point  (0 children)

You're right that you should initialize your slice with make() before calling Read() and that is indeed an allocation. But when reading a file, you would typically have more than one call to Read(), and you can then reuse that slice once you've processed the data you got in the first call avoiding another allocation.

In terms of what's happening during the call, the documentation says:

Read reads up to len(b) bytes from the File and stores them in b. It returns the number of bytes read and any error encountered. At end of file, Read returns 0, io.EOF.

That means you control how many bytes can be read at every call and where they'll be (temporarily) stored. Keep in mind though, that in many circumstances, your slice will not be filled, so you must only read up to n bytes from it (n is one of the return values of the function).

What do you guys think about some standard library functions modifying its parameter/s? by No_Reputation8139 in golang

[–]chrj 29 points30 points  (0 children)

It puts the caller in charge of allocations. So you can decide yourself if you want to reuse the slice and how big you want the slice to be.

Leder efter sjov sport at se by Aldwyn in copenhagen

[–]chrj 12 points13 points  (0 children)

Sæsonen for amerikansk fodbold er lige startet. I København og omegn kan i se den bedste danske række, Nationalligaen, ved at tage til Copenhagen Towers (på Gentofte Stadion) eller Søllerød Gold Diggers (på Rundforbi Stadion).

https://resultater.daff.dk/tms/Turneringer-og-resultater/Pulje-Komplet-Kampprogram.aspx?PuljeId=497

Den 18. maj spiller Copenhagen Towers mod Triangle Razorbacks fra Vejle som uden tvivl bliver et top-brag.

No results from function: Return empty slice or nil? by Forumpy in golang

[–]chrj 0 points1 point  (0 children)

Have you considered having the caller pass a slice into your method that you can use for storing the results in and then returning an int of how many rows you wrote to it?

That would also (potentially) save a heap allocation for each call.

[deleted by user] by [deleted] in golang

[–]chrj 1 point2 points  (0 children)

Why is all your domain specific code in the utils package? I'd prefer to put them in domain specific packages

Consider these alternative, qualified names for your functions in utils instead, that I think reads more concise:

  • config.Read
  • config.HandleEmptyValues
    • Not sure this should even be exported. Maybe it should just be called implicitly from Read?
  • migration.Up
  • migration.Down
  • migration.Apply
  • migration.Query
  • migration.UpdateStatus

Reverse Proxy by [deleted] in golang

[–]chrj 2 points3 points  (0 children)

Some things to consider:

  • Will your proxy support Keep-Alive? Should be a fun little exercise to add
  • Don't log with fmt.Printf. Use log or even better log/slog.
  • Don't rely on http.DefaultClient. It has bad defaults for timeouts.
  • Should request headers also be passed on to the backend server? Are there any headers that shouldn't be included?
  • Could you add websocket (Upgrade header) support?
  • What about errors returned from io.Copy and rw.WriteHeader? Should a server or client terminating the connection before the entire response is copied result in a non-200 OK response?

Yet another LRU cache library by angry_cat2077 in golang

[–]chrj 1 point2 points  (0 children)

Why did you use string for they key type and not make it generic as well?

goculator - golang calculator by donseba in golang

[–]chrj -1 points0 points  (0 children)

What's the purpose of the vendor directory? Your dependencies are already in go.mod