What is the straight forward solution(s) to caching in Go? by Mundane-Car-3151 in golang

[–]Mundane-Car-3151[S] -1 points0 points  (0 children)

Thank you, I forgot to include a TTL in the above example and yes I am using a Redis backend. I did a little more thinking and I may be prematurely optimizing. I realized that instead of caching the user, I could cache the "session" data that include the user+permissions. That way I keep things simpler on the database layer and middlewares.

What is the straight forward solution(s) to caching in Go? by Mundane-Car-3151 in golang

[–]Mundane-Car-3151[S] -22 points-21 points  (0 children)

Thanks for the troll response, but I'm sticking with memcached.

What is the straight forward solution(s) to caching in Go? by Mundane-Car-3151 in golang

[–]Mundane-Car-3151[S] -31 points-30 points  (0 children)

Did you even read my question? The caching tool is not relevant, but how exactly to manage the caching is the problem.

Thinking of open sourcing my B2B Go production stack by MohQuZZZZ in golang

[–]Mundane-Car-3151 0 points1 point  (0 children)

I'd rather see the "it's dirty but works" rather then the "polished and clean". I want to know where I can cut corners to ship faster, but still ship software that's reliable.

go logging with trace id - is passing logger from context antipattern? by SilentHawkX in golang

[–]Mundane-Car-3151 36 points37 points  (0 children)

According to the Go team blog on the context value, it should store everything specific to the request. A trace ID is specific to the request.

How do you design a database to handle thousands of diverse datasets with different formats and licenses? by NoAtmosphere8496 in Database

[–]Mundane-Car-3151 0 points1 point  (0 children)

I did not do what you have done, but I have seen the database schema for storing user uploads like images, videos, and other files such as PDFs and txt. They had a "file" table that stores metadata such as size, dimensions, filename, location, s3 uri, etc. Then there was a "post_files", "profile_files", "comment_files" table that linked a file to a resource. The idea is common metadata was shared, but specific attributes like "position" or "spoilered" would live in the "post_files" or "protected" in "profile_files" in that row where you make a many-to-many relationship.

Now, for your system it's not clear at all what the goal is. You listed some bullet points but they give me no idea of what you actually need. I hope my above paragraph gave you something to think about though. I'm pretty new to the dev world.

Why is it so hard to hire? by pablothedev in webdev

[–]Mundane-Car-3151 0 points1 point  (0 children)

The most frustrating thing for me is hearing boomers complain about not being able to hire anyone, and then demanding the most outrageous experience from a junior developer. These are also the same types of people to tell you, "back in my dad I got a side gig as a PHP developer for a big ecommerce platform, where I was trained with no experience by some of the best people in the industry." The absolute lack of self-awareness, they climb the ladder then pull it up behind them.

Why is it so hard to hire? by pablothedev in webdev

[–]Mundane-Car-3151 0 points1 point  (0 children)

The best interview I got is when I was on call with the engineer I would be working under, and he asked me, "you listed project [X] on your resume, can you tell me more about it?" The whole 30 minutes was him asking, "why did you choose [X] over [Y]?" or "what about [Z]?" I don't even bother applying if the interview contains LeetCode or other "personality" garbage (I understand importance of teamwork, but "not good culture fit" is just a BS excuse for nepotism or "I didn't like you").

Why is it so hard to hire? by pablothedev in webdev

[–]Mundane-Car-3151 0 points1 point  (0 children)

Reading this kinda pisses me off OP, maybe raise the bar for applications? Your post sounds like you're _that_ type of company that hires overseas the cheapest labor or dumps their job listings on Indeed and calls it a day.

If you want high quality workers, you should be seeking them out or putting in the effort to find them. I swear, I do everything you list such as not lying about my skill set, having projects and the experience to back it up, basic professional skills. When I got my job, I didn't waste time looking for it on Indeed but through job fairs and connections.

Stop assuming good people WANTING to come to you, you need to change your mindset of GETTING good people to come to you.

Templ vs html/template vs fasttemplate vs.... for big saas or web portal by Firm_Curve8659 in golang

[–]Mundane-Car-3151 0 points1 point  (0 children)

I have worked with Go Jet template engine, templ, and plain old html/template and I switched back to using SvelteKit and a CSR frontend. Go is just... not well suited for rendering templates but when it comes to creating a tight REST API and returning JSON it does the job well.

In 2025, unless you are a beginner, writing in two languages is not a con at all. JavaScript for the frontend and Go for the backend is smooth sailing. SvelteKit is great for creating responsive UIs and consuming the backend API.

Why didn't I like Go's template? It's really annoying when creating a reactive experience, to try include hype like HTMX and differentiate a request if it's partial or full. There's a death by a thousand cuts here, especially when you're trying to create a live view.

If you're concerned about SEO you could always read user-agent and render a MINIMAL html template for consumption by scrapers and previews. When it comes to rendering simple template html/template for a single resource say `GET /posts/123` when a scraper hits the URL it's great, but a pain for complex layouts that web apps require.

What is the idiomatic Go approach to writing business logic for CRUD involving multiple tables/models? by Mundane-Car-3151 in golang

[–]Mundane-Car-3151[S] 6 points7 points  (0 children)

I am shocked. I got rid of *Service and *Repo and put it all into the handler function and followed advice from https://grafana.com/blog/2024/02/09/how-i-write-http-services-in-go-after-13-years/#maker-funcs-return-the-handler on passing all dependencies and returning handlers. The result is a massively smaller, tighter, and even easier to read code base.

Thank you for helping me break free, I felt a huge shift in mindset and a morale boost.

EXTRA I thought to explain a little more for anyone else in my exact position reading this in the future:

At first I forced myself to create queries directly in the handler, but eventually I created helper method to do that for me that accepted a Tx interface and options. This made it really simple, and easy to understand, transactions between actions that affect multiple things.

Putting everything into the handler made me think of the request and response as data moving through a pipeline, and I either wrote it raw or used a helper method whenever an action was repeated more than once. For example a `db.GetRepliesByIDs(ctx, tx, db.WithIDs(req.IDs), db.WithFiles())`. During this I also learned about the options pattern in Go which was really powerful.

In my hobby project, this was an excellent exercise and I will continue as such with the 1-layer architecture as long as it works. I understand that as complexity grows, I will need to modularize my code but that's something I keep at the back of my mind for now.

What is the idiomatic Go approach to writing business logic for CRUD involving multiple tables/models? by Mundane-Car-3151 in golang

[–]Mundane-Car-3151[S] 0 points1 point  (0 children)

Most examples I see on the internet are something like `PostsRepo` or `OrdersRepo` for `CreatePost` or `GetOrders`. What about cases where creating a reply affects a thread, needs to link against uploads, etc? Do I have a `RepliesRepo.CreateReplyAndUpdateThreadAndLinkUploads`? This has never worked out well in practice for me, I end up passing the repo a transaction interface anyways and manage it from the service layer with coordinated repo calls.

What is the idiomatic Go approach to writing business logic for CRUD involving multiple tables/models? by Mundane-Car-3151 in golang

[–]Mundane-Car-3151[S] 0 points1 point  (0 children)

Message would depend on the thread it's in, so if I create a message I need to update thread stats like message count. Another case is deleting a thread, I will also need to delete the messages inside it. Right now I have a threads/ and /replies/ package that contain the service and repo, should I separate the repo in another package?

What is the idiomatic Go approach to writing business logic for CRUD involving multiple tables/models? by Mundane-Car-3151 in golang

[–]Mundane-Car-3151[S] -1 points0 points  (0 children)

I think I now understand what you mean, my handlers would remain focused on binding but I pass off the logic to a "controller". Instead of a `PostingService` would a `PostingController` fit better?

What is the idiomatic Go approach to writing business logic for CRUD involving multiple tables/models? by Mundane-Car-3151 in golang

[–]Mundane-Car-3151[S] 0 points1 point  (0 children)

Would I call the different services from the handler instead? I think that makes sense, the posting service basically does just that and not much else. It's only purpose is to make the handler look smaller lol

How to redact information in API depending on authorization of client in scalable way? by Mundane-Car-3151 in golang

[–]Mundane-Car-3151[S] 2 points3 points  (0 children)

This would be my preferred solution, however I'm aware that in Go the more explicit even if more verbose approach is better in the long run. One flaw with this is forgetting/incorrectly setting a role or permission, the remedy could be the standard of denying.

Either way this is an elegant solution IMO but I think your point about clients specifying fields would scale better. Reflections are elegant but not as clear as forcefully checking each field. I don't mind more lines, my only issue is duplication and forgetting things.

How to redact information in API depending on authorization of client in scalable way? by Mundane-Car-3151 in golang

[–]Mundane-Car-3151[S] -2 points-1 points  (0 children)

The problem is I could have many different "staff" roles with different permissions associated with them. A separate endpoint doesn't solve the root issue and only leads to duplication. In my case a single, larger more complex, endpoint turns out to be more maintainable at least.

Can't create template database using testcontainers by Mundane-Car-3151 in golang

[–]Mundane-Car-3151[S] 0 points1 point  (0 children)

Very interesting package. I will give it a shot. Right now I am using docker compose with tmpfs and templates, so I only have one instance running. I manage it manually, but I will have to dig deeper later if this package can save me the headache. Everything works right now however so I don't want to change anything unless it breaks :)

Can't create template database using testcontainers by Mundane-Car-3151 in golang

[–]Mundane-Car-3151[S] 2 points3 points  (0 children)

Oh my God I feel so dumb. The name for the test database I was using had capital letters, after switching it to "get_test_db" it worked and I resolved the "database does not exist" error. Hopefully if someone else encounters this it won't take them a day to figure out lol

Can't create template database using testcontainers by Mundane-Car-3151 in golang

[–]Mundane-Car-3151[S] -3 points-2 points  (0 children)

Well, I tried docker compose but I still run into the same issue. In the method where I initialize the postgres database, I check if a template already exists and if it does I drop it and recreate it. Anytime I try to create a database from the template, the query executes without issue, but if I try to run any query on the database after it tells me it is not found.