libudev

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 25, 2020 License: MIT Imports: 8 Imported by: 1

README

libudev

Golang native implementation Udev library

Build Status Coverage Status Go Report Card GoDoc GitHub release

Installation

go get github.com/citilinkru/libudev

Usage

Scanning devices
sc := libudev.NewScanner()
err, devices := s.ScanDevices()
Filtering devices
m := matcher.NewMatcher()
m.SetStrategy(matcher.StrategyOr)
m.AddRule(matcher.NewRuleAttr("dev", "189:133"))
m.AddRule(matcher.NewRuleEnv("DEVNAME", "usb/lp0"))

filteredDevices := m.Match(devices)
Getting parent device
if device.Parent != nil {
    fmt.Printf("%s\n", device.Parent.Devpath)
}
Getting children devices
fmt.Printf("Count children devices %d\n", len(device.Children))

Features

  • 100% Native code
  • Without external dependencies
  • Code is covered by tests

Requirements

  • Need at least go1.13 or newer.

Documentation

You can read package documentation here or read tests.

Testing

Unit-tests:

go test -race -v ./...

Contributing

  • Fork
  • Write code
  • Run unit test: go test -v ./...
  • Run go vet: go vet -v ./...
  • Run go fmt: go fmt ./...
  • Commit changes
  • Create pull-request

Documentation

Overview

Package libudev implements a native udev library.

Recursively passes `/sys/devices/...` directory and reads `uevent` files (placed in `Env`). Based on the information received from `uevent` files, it tries to enrich the data based on the data received from the files that are on the same level as the `uevent` file (they are placed in `Attrs`), and also tries to find and read the files `/run/udev/data/...` (placed in `Env` or `Tags`).

After building a list of devices, the library builds a device tree.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Scanner

type Scanner struct {
	// contains filtered or unexported fields
}

Scanner structure of the device scanner.

func NewScanner

func NewScanner() *Scanner

NewScanner creates a new instance of device scanner.

func (*Scanner) ScanDevices

func (s *Scanner) ScanDevices() (err error, devices []*types.Device)

ScanDevices scans directories for `uevent` files and creates a device tree.

Directories

Path Synopsis
Package matcher implements a service for filtering devices.
Package matcher implements a service for filtering devices.
Package types contains data structures
Package types contains data structures

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL