github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/client/lib/cgutil/editor.go (about) 1 //go:build linux 2 3 package cgutil 4 5 import ( 6 "os" 7 "path/filepath" 8 "strings" 9 ) 10 11 // editor provides a simple mechanism for reading and writing cgroup files. 12 type editor struct { 13 fromRoot string 14 } 15 16 func (e *editor) path(file string) string { 17 return filepath.Join(CgroupRoot, e.fromRoot, file) 18 } 19 20 func (e *editor) write(file, content string) error { 21 return os.WriteFile(e.path(file), []byte(content), 0o644) 22 } 23 24 func (e *editor) read(file string) (string, error) { 25 b, err := os.ReadFile(e.path(file)) 26 return strings.TrimSpace(string(b)), err 27 }