A comprehensive first-principles study of the energetics, electronic and magnetic properties of Co-doped GaN(0001) thin films are presented and the effect of surface structure on the magnetic coupling between Co atoms is demonstrated. It is found that Co atoms prefer to substitute the surface Ga sites in different growth conditions. In particular, a CoN/GaN interface structure with Co atoms replacing the first Ga layer is preferred under N-rich and moderately Ga-rich conditions, while CoGa x /GaN interface is found to be energetically stable under extremely Ga-rich conditions. It's worth noted that the antiferromagnetic coupling between Co atoms is favorable in clean GaN(0001) surface, but the existence of FM would be expected to occur as Co concentration increased in Ga-bilayer GaN(0001) surface. Our study provides the theoretical understanding for experimental research on Co-doped GaN films and might promise the Co:GaN system potential applications in spin injection devices. *