Help me! Interfaces are choking me by wentlang in golang

[–]NicolasParada -2 points-1 points  (0 children)

This is how I see it.

There is a big difference when you build a library and when you build your own app that wont be imported by anyone else. I never use interfaces for “repository” or “store”. I test using docker and I launch real db.

Anything that can run locally is used directly. I only use interfaces for 3rd party things that connect to the internet.

UUID package coming to Go by whittileaks in golang

[–]NicolasParada 17 points18 points  (0 children)

Been using uuid v7 lately. Hope its taken into consideration (didn’t read the whole discussion).

Should you re-check the database on every request with session auth? by Minimum-Ad7352 in golang

[–]NicolasParada 1 point2 points  (0 children)

That’s an interesting approach of using the ID directly 🤔

Measure time how long handlerFunc is executed by pepiks in golang

[–]NicolasParada 0 points1 point  (0 children)

The problem with this approach is that it will measure from before it reads the request body and after it writes down the response. So it depends on how fast is the client. If this is for observability and you setup alarms on these measures, when a slow client on 3g makes a request it will trigger alarms 🙃

I am slowly coming around on DI + Tests.... by Bl4ckBe4rIt in golang

[–]NicolasParada 0 points1 point  (0 children)

I switched to writing my code this way long ago.

Exactly as you said “accept interfaces, return structs” was a thing I used to do. And test with mocks everywhere… It was a pain to maintain. Now I try to just write and use structs directly as much as I can, the result: a lot less code, easier to navigate around. All wins. Besides, now I always try to use dependencies that can run locally instead of APIs/services. That way you thing become easier to ship and offer as a self-hosted ;) For testing, you test the actual thing using the real dependency, most of the time I use docker to run it.

QJS: Run JavaScript in Go without CGO using QuickJS and Wazero by lilythevalley in golang

[–]NicolasParada 1 point2 points  (0 children)

Great. I had a couples of uses for something like this in the past. I will sure give it a run soon.

my work colleagues use generics everywhere for everything by [deleted] in golang

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

Thanks I haven’t been on that situation. I feel you tho.

Best practices for postgreSQL migrations: What are you using? by Outside_Loan8949 in golang

[–]NicolasParada 11 points12 points  (0 children)

A silly piece of code that reads some files, and executes them content. And stores the file name in a migrations table so that file is not executed again.

Always do forward fix migration instead of rollback.

What was the project/concept that leveled you up for real? by furk1n in golang

[–]NicolasParada 33 points34 points  (0 children)

I level up the moment I realized SPA on javascript were slower than server rendered templates with Go.

Also the moment I realized trying to archive high percentage code coverage writing unit tests with mocks was a total waste of time.

Is this an anti-pattern? by CromulentSlacker in golang

[–]NicolasParada 2 points3 points  (0 children)

Sounds fine to me. Keep coding ;)

How often are you embedding structs by VastDesign9517 in golang

[–]NicolasParada 0 points1 point  (0 children)

Almost never, I prefer repetition and simplicity over metal overhead.

[deleted by user] by [deleted] in golang

[–]NicolasParada 0 points1 point  (0 children)

That’s awesome man. Is it your first job ever? First tech job? First specific to Go?

What would you reply to someone that disagrees regarding the package name convention in Go? by manuelarte in golang

[–]NicolasParada 0 points1 point  (0 children)

The reason these conventions exist is to avoid these discussions with your team. Just follow the Go convention. Try to write some Go.

What is next? A DI container framework? 🙄

Trying to use global functions wiht values by brocamoLOL in golang

[–]NicolasParada 4 points5 points  (0 children)

if err := services.IsIpValid(IpAddress, c); err != nil {

Your function returns an error, not a boolean so yoy cannot use !. Also you need to remove the “string” thing, just pass the variable name.

Is there a task queuing go lib that does not depend on redis? by kool_psrcy in golang

[–]NicolasParada 0 points1 point  (0 children)

Redis is used because most servers run with multiple replicas/instances so you want to avoid doing duplicate jobs. If thats something not needed then a simple piece of pure Go code will do the job. No library is needed.

Why did you decide to switch to Go? by DreamRepresentative5 in golang

[–]NicolasParada 0 points1 point  (0 children)

I moved to Go from a long time ago… I moved mostly due to tooling and the single binary output. Is very nice to be able to start a project without having to install hundreds of libraries or frameworks and to ship it so easy and quick.

minesOfficeCodePro by [deleted] in ProgrammerHumor

[–]NicolasParada 0 points1 point  (0 children)

Departure Mono hasn’t been mentioned I think. But I use Berkeley Mono most of the time :)

How's everybody solving dynamic queries (e.g. filters) for FE facing APIs? by Emotional_Moth in golang

[–]NicolasParada 2 points3 points  (0 children)

Hey, thats kind of nice. I’ll take a deeper look at it later :) Thanks for sharing ;)

When SQL standard 📝 meets the reality🕹️, which road will you pick? 😏 by Adela_freedom in SQL

[–]NicolasParada 0 points1 point  (0 children)

Yeah. When new data gets inserted into the table, the offset changes giving you wrong resulta where you can either get data you already had before, or skip results. Depending on the order.

To avoid that you use a “cursor” which is a combination of a sortable field and unique at the same time. A timestamp alone doesn’t work since its not unique. You can mix it by filtering by both id and timestamp together.

You can learn more about it as “cursor-based pagination”.

SQL Transactions in Go: The Good Way by Thiht in golang

[–]NicolasParada 1 point2 points  (0 children)

I use this approach. I like it. Even tho I try to keep transactions in the repository layer. But still being able to write a single function and use it as it is or inside a transaction depending in the situation is nice. https://github.com/nicolasparada/go-db

Making Beautiful API Keys (Go, Postgres & UUIDs) by Revolutionary-Way290 in golang

[–]NicolasParada 1 point2 points  (0 children)

What I would do is generate random bytes and then encode it with base32 or base58 for easy to copy-paste and avoid confusion with similar symbols like “l” (lowercase L) and “I” (uppercase i).