If you need to check for Prime Numbers in Golang, then you can use the following method:

const n = 1212121
if big.NewInt(n).ProbablyPrime(0) {
  fmt.Println(n, "is prime")
} else {
  fmt.Println(n, "is not prime")
}

The ProbablyPrime method from the math/big package uses the Miller-Rabin primality test. The argument 0 means it uses a default number of test rounds, which is reliable for most practical purposes. For cryptographic use cases, pass a higher value like 20 for more certainty.

If you’re checking small numbers and don’t want to pull in math/big, a simple trial division loop works fine — just iterate from 2 to the square root of n and check for divisibility. But for large numbers, the probabilistic approach above is much faster.