Coating made of magnesium or of Mg-based alloys