-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds support for serializing the primary XXXInfo structs in `ghw` as JSON and YAML. Each `ghw.XXXInfo` struct now has a `YAMLString()` and `JSONString()` method that returns a string with the struct's information serialized to that format. The `ghwc` client has been enhanced with a `--format` CLI option that allows users to print the hardware information in human-readable (the default), JSON or YAML format: ``` [jaypipes@uberbox ghw]$ go run cmd/ghwc/main.go -f yaml memory 2>/dev/null memory: supported_page_sizes: - 1073741824 - 2097152 total_physical_bytes: 25263415296 total_usable_bytes: 25263415296 [jaypipes@uberbox ghw]$ go run cmd/ghwc/main.go -f json memory 2>/dev/null {"memory":{"total_physical_bytes":25263415296,"total_usable_bytes":25263415296,"supported_page_sizes":[1073741824,2097152]}} ``` The `--format json` CLI option can be paired with a `--pretty` CLI option to provide indented output: ``` [jaypipes@uberbox ghw]$ go run cmd/ghwc/main.go -f json --pretty memory 2>/dev/null { "memory": { "total_physical_bytes": 25263415296, "total_usable_bytes": 25263415296, "supported_page_sizes": [ 1073741824, 2097152 ] } } ``` Issue #78
- Loading branch information
Showing
25 changed files
with
539 additions
and
174 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// Use and distribution licensed under the Apache license version 2. | ||
// | ||
// See the COPYING file in the root project directory for full text. | ||
// | ||
|
||
package ghw | ||
|
||
import "strings" | ||
|
||
// Architecture describes the overall hardware architecture. It can be either | ||
// Symmetric Multi-Processor (SMP) or Non-Uniform Memory Access (NUMA) | ||
type Architecture int | ||
|
||
const ( | ||
// SMP is a Symmetric Multi-Processor system | ||
ARCHITECTURE_SMP Architecture = iota | ||
// NUMA is a Non-Uniform Memory Access system | ||
ARCHITECTURE_NUMA | ||
) | ||
|
||
var ( | ||
architectureString = map[Architecture]string{ | ||
ARCHITECTURE_SMP: "SMP", | ||
ARCHITECTURE_NUMA: "NUMA", | ||
} | ||
) | ||
|
||
func (a Architecture) String() string { | ||
return architectureString[a] | ||
} | ||
|
||
// NOTE(jaypipes): since serialized output is as "official" as we're going to | ||
// get, let's lowercase the string output when serializing, in order to | ||
// "normalize" the expected serialized output | ||
func (a Architecture) MarshalJSON() ([]byte, error) { | ||
return []byte("\"" + strings.ToLower(a.String()) + "\""), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.