File: object.go

package info (click to toggle)
golang-github-ungerik-go-sysfs 0.0~git20210209.68e6f4d-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 92 kB
  • sloc: makefile: 2
file content (42 lines) | stat: -rw-r--r-- 857 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package sysfs

import (
	// "os"
	"strings"
)

type Object string

func (obj Object) Exists() bool {
	return dirExists(string(obj))
}

func (obj Object) Name() string {
	return string(obj)[strings.LastIndex(string(obj), "/")+1:]
}

func (obj Object) SubObjects() []Object {
	path := string(obj) + "/"
	objects := make([]Object, 0)
	lsDirs(path, func(name string) {
		objects = append(objects, Object(path+name))
	})
	return objects
}

func (obj Object) SubObject(name string) Object {
	return Object(string(obj) + "/" + name)
}

func (obj Object) Attributes() []Attribute {
	path := string(obj) + "/"
	attribs := make([]Attribute, 0)
	lsFiles(path, func(name string) {
		attribs = append(attribs, Attribute{Path: path + name})
	})
	return attribs
}

func (obj Object) Attribute(name string) *Attribute {
	return &Attribute{Path: string(obj) + "/" + name}
}