According to my experience 2 to 3day is enough to visit gokarna. If you want to spend some good time peacefully then 3 days.. Or else if you are super enthusiastic then 2 day is enough. All the beaches are almost connected to each other you can visist in one day.. And another day you can go for temple visit and some near markets.
A long weekend of 3 days is sufficient. Keep day 1 for beach activities and beach hopping, day 2 to visit Yana Caves and Day 3 to just chill by your favourite beach or visit the Mahabaleshwar Temple