Hi, I am trying to add hosts to /etc/hosts file using ioutil.Writefile fucntion. But I get permission denied error. err := ioutil.WriteFile(fileName, hfData, 0644) This line throws open /etc/hosts: permission denied error. Can anyone guide how to overcome this problem?
Thank you, I just write go code and run so, a user who can use sudo and have root access. But the when I issue go run, it does not ask for root password.
Oh, but the program is not that small, I thought running entire code as sudo is not the best way to do. Is there anyway, I can use the root priviledge only during this function call?