facts

package module
v0.0.0-...-59662b7 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Facts

Facts was originally included in Shepherd to gather facts about the operating system. It makes sense to break it out into a separate project so that they can move at different speeds.

Install

$ go get github.com/sfreiberg/facts

Documentation

http://godoc.org/github.com/sfreiberg/facts

Simple Example

package main

import (
	"github.com/sfreiberg/facts"

	"fmt"
)

func main() {
	f := factsFindFacts()
	json, err := f.ToPrettyJson()
	if err != nil {
		panic(err)
	}
	fmt.Printf("%s\n", json)
}

Current Features

  • Get hostname, domain, cpu, os and interfaces

Planned Features

  • BSD support
  • Additional facts
    • Memory
    • Mounts

Current Limitations

  • Only works on Linux, Mac OS X
  • Lack of testing

Documentation

Overview

Gather facts (memory, cpus, filesystems, etc...) about the current machine.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Address

type Address struct {
	Network   string `json:"network"`
	Address   string `json:"address"`
	IPNetwork string `json:"ip_network"`
}

type Facts

type Facts struct {
	Hostname         string                `json:"hostname"`
	Domain           string                `json:"domain"`
	Fqdn             string                `json:"fqdn"`
	Cpus             int                   `json:"cpus"`
	Arch             string                `json:"arch"`
	Os               string                `json:"os"`
	Platform         string                `json:"platform"`
	PlatformVersion  string                `json:"platform_version"`
	PlatformCodename string                `json:"platform_codename"`
	Uptime           float64               `json:"uptime"`
	Memory           uint64                `json:"memory"`      // In megabytes
	Swap             uint64                `json:"swap"`        // In megabytes
	Interfaces       map[string]Interface  `json:"interfaces"`  // key is nic name ex: en0, eth0
	FileSystems      map[string]FileSystem `json:"filesystems"` // key is DeviceName
}

func FindFacts

func FindFacts() *Facts

Gather all of the system facts available

func (*Facts) ToJson

func (f *Facts) ToJson() ([]byte, error)

Return facts as a JSON document

func (*Facts) ToPrettyJson

func (f *Facts) ToPrettyJson() ([]byte, error)

Return facts as a JSON document with newlines and indentation added.

func (*Facts) ToYAML

func (f *Facts) ToYAML() ([]byte, error)

Return facts as YAML

type FileSystem

type FileSystem struct {
	Directory  string `json:"directory"`
	DeviceType string `json:"device_type"`
	SysType    string `json:"sys_type"`
	Options    string `json:"options"`
	Size       uint64 `json:"size"` // in megabytes
}

type Interface

type Interface struct {
	Index        int       `json:"index"`
	MTU          int       `json:"mtu"`
	Name         string    `json:"name"`
	HardwareAddr string    `json:"hardware_addr"`
	Flags        []string  `json:"flags"`
	Addresses    []Address `json:"addresses"`
}

Jump to

Keyboard shortcuts

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