hostname.go 243 B

1234567891011121314
  1. package hostname
  2. import (
  3. "io/ioutil"
  4. "syscall"
  5. )
  6. func SetHostname(hostname string) error {
  7. if err := syscall.Sethostname([]byte(hostname)); err != nil {
  8. return err
  9. }
  10. return ioutil.WriteFile("/etc/hostname", []byte(hostname), 0644)
  11. }