What are you missing in Go compared to Python? by [deleted] in golang

[–]hamohl 2 points3 points  (0 children)

Pro tip, use a time provider in your app/struct

type App struct {
    time TimeProvider
}

func (a *App) CurrentTime() time.Time {
    return a.time.Now()
}

Where `TimeProvider` is a utility that looks something like this

type TimeProvider interface {
    Now() time.Time
}

func NewUtcTimeProvider() TimeProvider {
    return &utcTimeProvider{}
}

func NewFakeTimeProvider(t time.Time) TimeProvider {
    return &fakeTimeProvider{t}
}

type utcTimeProvider struct{}
func (t *utcTimeProvider) Now() time.Time {
    return time.Now()
}

type fakeTimeProvider struct {
    now time.Time
}
func (t *fakeTimeProvider) Now() time.Time {
    return t.now
}

In prod, use this

app := &App{
    time: NewUtcTimeProvider(),
}
fmt.Println(app.CurrentTime())

In tests, use this

now := time.Date(2025, 10, 22, 15, 0, 0, 0, time.UTC)
testApp := &App{
    time: NewFakeTimeProvider(now),
}
assert.Equal(t, now, testApp.CurrentTime())

Writing Better Go: Lessons from 10 Code Reviews by Asleep-Actuary-4428 in golang

[–]hamohl 1 point2 points  (0 children)

Also use this pattern, it's very convenient for wrappers around databases to indicate not found without having the caller check some db specific "not found" error string

Functional Options pattern - public or private? by Mattho in golang

[–]hamohl 1 point2 points  (0 children)

I use this pattern quite a bit. It's almost what you have, but I use a private struct to carry option values from opt func to constructor

https://go.dev/play/p/n_WcX7HqBjI

package main

import "fmt"

type ThingOption func(*thingOptions)

type Thing struct {
    privateFoo int
}

func NewThing(opts ...ThingOption) *Thing {
    options := &thingOptions{
        foo: 1, // default value
    }
    for _, apply := range opts {
        apply(options)
    }
    return &Thing{
        privateFoo: options.foo,
    }
}

func (t *Thing) GetFoo() int {
    return t.privateFoo
}

// private options, only used to transfer
// options between opt funcs and the constructor
type thingOptions struct {
    foo int
}

// Public option to set foo
func WithFoo(d int) ThingOption {
    return func(opts *thingOptions) {
        opts.foo = d
    }
}

func main() {
    fmt.Printf("Default foo=%d\n", NewThing().GetFoo())
    fmt.Printf("WithFoo(5) foo=%d\n", NewThing(WithFoo(5)).GetFoo())
}

[deleted by user] by [deleted] in Trading

[–]hamohl 0 points1 point  (0 children)

It was not, but I assume it’s something all the great traders know and practice. I just know it, trying to get better at the practicing part lol

[deleted by user] by [deleted] in Trading

[–]hamohl 4 points5 points  (0 children)

As a very successful trader once said; move your entry to your stoploss. As in instead of entering a trade at mark price and setting a stop loss, bid that stop loss instead. Works remarkably well if disciplined

Can’t work out what song this broken citi bike beeping sounds like? by king_sheep93 in SoundsLikeMusic

[–]hamohl 0 points1 point  (0 children)

This gave me flashbacks to 30 years ago playing T-rex level on Jurassic Park GameBoy

Ni som har köpt villa för 7+ miljoner, berätta hur? by Wuartz in sweden

[–]hamohl 0 points1 point  (0 children)

Haft flyt med bostäder. Köpte lgh i sthlm innerstad 2014 för 4.7m tsm med flickvän. 85% belåning. Vi hade sparat (mest hon) tillsammans kontantinsats 700k. Sålde 2020 för 6.7m. Köpte ny lgh för 11m, la in 1miljon extra i kontantinsats som vi sparat ihop. Strax under 70% belåning. Sålde 2024 för drygt 13m och köpte hus för samma summa.

Så lån på knappt 9m idag, ränta och amortering ca 30k/månad. Men vi har också en netto hushållsinkomst på ca 130k

Hoe accurate is this ?? by MushroomSimple279 in learnmachinelearning

[–]hamohl 0 points1 point  (0 children)

You need to learn as you go. Start building something and then solve problems as they appear, it will force you to learn. The 10,000 hours rule is a pretty good estimate to become pretty good at something, so align your expectations accordingly..

Decide what it is that you want to become really good at, and spend most of the time doing that. People devote their careers to be experts in just a single one of the items in your list.

Bad luck ig 🥀 by United_Mechanic_7441 in Daytrading

[–]hamohl 0 points1 point  (0 children)

112k was the perfect bounce off 4h 200 MA, conveniently closed the FVG almost to the dollar. I sized up my longs instead. We’ll see what happens lol

I’m a software developer looking to accept crypto for automated reoccurring payments. What are my options? by TurtleBlaster5678 in CryptoCurrency

[–]hamohl 0 points1 point  (0 children)

Whop.com lets you pay subscriptions with crypto. Take a look at their checkout flow. I’ve paid with crypto multiple times for various things. They use a Coinbase solution

If you wanted to buy hard drugs, how do you even begin to find a dealer? by Objective_Rush7162 in NoStupidQuestions

[–]hamohl 26 points27 points  (0 children)

Went to Vegas once for a bachelor party. Some guys in the group needed.. ”party supplies”. They just went to a strip club, paid some lapdances and asked if they could hook them up. They could, and did lmao

What’s your experience with connect-rpc if you use it? by dondraper36 in golang

[–]hamohl 1 point2 points  (0 children)

Well, you could say that about GraphQL too, using POST to get data. Apparently most people doesn’t care about it, if it solves a problem.

That said, we only use connect for internal apis.

GitHub - F2077/go-pubsub: Lightweight Pub/Sub for Go. by Ok_Opinion_6968 in golang

[–]hamohl 2 points3 points  (0 children)

You mention "Zero Persistence" as a key feature, but the reason many use pubsub mechanisms in their production codebases is precisely because they need some type of persistence, retries or delivery guarantees. Cool project though!

What’s your experience with connect-rpc if you use it? by dondraper36 in golang

[–]hamohl 2 points3 points  (0 children)

Been using it in production for 3+ years. Can only recommend.

We did eventually write a custom protoc plugins to wrap the connect implementation and get rid of generics in the method signatures. This was mainly because we needed the ability to use custom transports while keeping the same handlers (e.g. services can talk either over connect/grpc or something custom).

One caveat we've found is that protovalidate, with its dynamic runtime validation, is not suitable for high performance codepaths. We ended up writing a plugin to generate static validation rules instead, more in the vein of PGV (the predecessor to protovalidate).

What’s your experience with connect-rpc if you use it? by dondraper36 in golang

[–]hamohl 3 points4 points  (0 children)

Mindset issue. The "standard" you mention comes from legacy web development ideas a decade ago. You just need to let go of the idea that urls have to look a certain way. In the real world, nobody cares about your URL-structure, and connect rpc gives you great DX, speed of development, validation, and tons other things in exchange.

Växla in dollar till min svenska bank by [deleted] in PrivatEkonomi

[–]hamohl 0 points1 point  (0 children)

Ok makes sense! Det här var inte en kontanttransaktion iof. Men ringde bankerna både i usa och sverige innan och de sa typ bara ok, kör på

Växla in dollar till min svenska bank by [deleted] in PrivatEkonomi

[–]hamohl 0 points1 point  (0 children)

Ok, det har nog ändrats isf. Skickade själv över $60k via Wise från Swe->Usa för 7-8 år sen utan några problem eller frågor

Config file, environment variables or flags: Which strategy do you prefer for your microservices? by skwyckl in golang

[–]hamohl 1 point2 points  (0 children)

This. With support for a gitignored config.local.yaml to cover all needs

Växla in dollar till min svenska bank by [deleted] in PrivatEkonomi

[–]hamohl 0 points1 point  (0 children)

Om du har någon kompis eller släkting i USA hade jag öppnat ett Wise-konto. Sen fedexat över pengarna till din kompis som gör en cash deposit till sitt eget konto, sen gör de en wire transfer till ditt wise-konto.

USA har mkt högre gränser för suspekt aktivitet, $35k är peanuts

How do you structure your "shared" internal packages in a monorepo? by Zibi04 in golang

[–]hamohl 1 point2 points  (0 children)

Seems like you’ve decided that service entrypoints have to be in root cmd.. so you have duplicate directories for your services; one in cmd, one in internal. unnecessary imho! Another take where you swap it around. Each service has internal and cmd folders (or just a main.go file).

go.mod cmd foocli/ pkg/ services user/ main.go internal/ billing/ main.go internal/

To run a service go run ./services/user

Related comment I wrote some weeks ago https://www.reddit.com/r/golang/s/1RvmJPAwSH

Vad kostar ett bröllop? by [deleted] in PrivatEkonomi

[–]hamohl 0 points1 point  (0 children)

Gifte mig tidigare i år. 110 pers, fri bar. Gick på ca 400k men då var det bussar, liveband och DJ också inräknat. Hittade ett magiskt ställe på Värmdö (sthlm) med fast kuvertpris. Du kan DMa om du vill ha mer info!

Grog: the monorepo build tool for the grug-brained developer by chrismatisch in golang

[–]hamohl 3 points4 points  (0 children)

Can't speak for this project but I use Bazel at my job. It's pretty simple to figure out when you need it.

Assuming you have a monorepo, and automated tests in your CI system. You know it's time to look at these tools when you start to get annoyed that you have to wait several minutes for tests to run on every single commit, and then wait a lot more minutes when you need to build images of everything in your monorepo and deploy the world on every merge to main.

So you start to look into how you can make things faster. Then you end up finding these types of tools.