How do diodes work?

I know what a diode does? But how does it only allow electrons to flow through in on direction given a certain voltage.