Here's how I think about this: it's very similar to the old question about "can you ready an action outside of combat?". Opinions about this seem to be mixed, but my answer to that question is: that's what the surprise round represents.
If you know there are goblins behind the door, and the goblins don't know you're coming, then you and all your friends could ready an action to attack the goblins. But having everyone go around the table and say "I ready an action" is tiresome, so we just declare a surprise round and give everyone a standard action.
On the other hand, if the goblins do know you're coming, then presumably the goblins have a readied action as well. When lots of creatures have readied actions which all fire at once, we have to roll initiative to see which ones fire first -- so at that point we might as well just go into the initiative sequence and let everyone take their actions in initiative order.
Here's how your goblin example should work. If you know there are goblins behind the door, and the goblins don't know you are there, then you get a surprise round at the start of combat. During your surprise round you can declare total defense. Then, (if the goblins get a higher initiative roll than you), when the goblins shoot at you, you get your dodge bonus.
If you know there are goblins behind the door, and the goblins do know you are there, then you don't get your surprise round, and you don't get to start with total defense.
You could imagine saying "I declare total defense and then I open the door" -- but if combat starts and the goblins beat your initiative, then they have caught you flat-footed, which means you lose your Dexterity bonus to AC and also your dodge bonuses.
(Elsewhere you've asked: "what if I have uncanny dodge, which allows me to keep my dexterity and dodge bonus when flat-footed?". It's messy, but I think I'd have to concede that this works the way you want it to.)
Having said all that, I do think there are situations where you can declare total defense outside of combat. For example, if you know that a swinging blade trap is going to attack you when you step on a given pressure plate, you could say "I declare total defense against the swinging blade trap" and get your +4 AC.