Comments (14)
Hi @icholy! No reason other than my lack of familiarity with the Go documentation tooling. Would love some assistance on this if you're interested in helping out?
I like having lots of good documentation in the README.md file, so I wouldn't want to get rid of that. But certainly I'd also like to align source code documentation with the Go tooling needs.
from ghw.
I see you added the help wanted label, and I would love to help out in this repo. What part of the documentation would you like help with?
from ghw.
Hi @glvr182! Basically, this is about making ghw's documentation follow Golang standards, which unfortunately I haven't had a chance to read up on those standards and make any necessary changes to.
from ghw.
@jaypipes So where can i help with
from ghw.
Read https://blog.golang.org/godoc-documenting-go-code and then go from there.
-
I believe we need to have a doc.go file that contains much of the long-form documentation currently in the README.md file.
-
Running
godoc .
in the checked-out source directory yields a wide variety of things, not all of which seem to be well-organized and there are definitely structs and functions that do not have in-code comments that are read bygodoc
to generate that output. -
Figure out how to generate HTML documentation for the source code itself. I've read the
godoc
program's help output and it's less than helpful... need to research how to do this...
from ghw.
Most of the work is just taking the struct documentation and moving it into the source.
Memory
Information about the host computer's memory can be retrieved using the
ghw.Memory()
function which returns a pointer to a ghw.MemoryInfo
struct.
The ghw.MemoryInfo
struct contains three fields:
ghw.MemoryInfo.TotalPhysicalBytes
contains the amount of physical memory on
the hostghw.MemoryInfo.TotalUsableBytes
contains the amount of memory the
system can actually use. Usable memory accounts for things like the kernel's
resident memory size and some reserved system bitsghw.MemoryInfo.SupportedPageSizes
is an array of integers representing the
size, in bytes, of memory pages the system supports
// MemoryInfo contains information about the host computer's memory.
type MemoryInfo struct {
// TotalPhysicalBytes contains the amount of physical memory on the host
TotalPhysicalBytes int64 `json:"total_physical_bytes"`
// TotalUsableBytes contains the amount of memory the system can actually use.
// Usable memory accounts for things like the kernel's resident memory size and
// some reserved system bits
TotalUsableBytes int64 `json:"total_usable_bytes"`
// SupportedPageSizes is an array of integers representing the size, in bytes,
// of memory pages the system supports
SupportedPageSizes []uint64 `json:"supported_page_sizes"`
}
from ghw.
The issue with that is that I still want the README.md to have well-written long-form documentation and not have areas where I need to worry about content in the README getting out of sync with content in code comments in the Go source code. If there was a way to generate good looking markdown from the Go source code, I'd certainly be interested in investigating that path.
from ghw.
I think this is why many projects just link to https://godoc.org/github.com/jaypipes/ghw from their README.
If you really prefer it duplicated inline in the README as checked into the repo though, https://github.com/robertkrimen/godocdown (which I've just found and never tried) seems like a rather promising option.
from ghw.
Yeah, I was looking at that earlier. I think it's worth checking into...
from ghw.
I think that the README should contain the following. The rest can live in the Godoc.
ghw
- Golang HardWare discovery/inspection library
ghw
is a small Golang library providing hardware inspection and discovery.
Design Principles
-
No root privileges needed for discovery
ghw
goes the extra mile to be useful without root priveleges. We query for
host hardware information as directly as possible without relying on shellouts
to programs likedmidecode
that require root privileges to execute. -
Well-documented code and plenty of example code
The code itself should be well-documented, of course, with lots of usage
examples. -
Interfaces should be consistent across modules
Each module in the library should be structured in a consistent fashion, and
the structs returned by various library functions should have consistent
attribute and method names.
Overriding the root mountpoint ghw
uses
The default root mountpoint that ghw
uses when looking for information about
the host system is /
. So, for example, when looking up CPU information on a
Linux system, ghw.CPU()
will use the path /proc/cpuinfo
.
If you are calling ghw
from a system that has an alternate root mountpoint,
you can either set the GHW_CHROOT
environment variable to that alternate
path, or call the module constructor function with the ghw.WithChroot()
modifier.
For example, if you are executing from within an application container that has
bind-mounted the root host filesystem to the mount point /host
, you would set
GHW_CHROOT
to /host
so that ghw
can find /proc/cpuinfo
at
/host/proc/cpuinfo
.
Alternately, you can use the ghw.WithChroot()
function like so:
cpu, err := ghw.CPU(ghw.WithChroot("/host"))
Disabling warning messages
When ghw
isn't able to retrieve some information, it may print certain
warning messages to stderr
. To disable these warnings, simply set the
GHW_DISABLE_WARNINGS
environs variable:
$ ghwc memory
WARNING:
Could not determine total physical bytes of memory. This may
be due to the host being a virtual machine or container with no
/var/log/syslog file, or the current user may not have necessary
privileges to read the syslog. We are falling back to setting the
total physical amount of memory to the total usable amount of memory
memory (24GB physical, 24GB usable)
$ GHW_DISABLE_WARNINGS=1 ghwc memory
memory (24GB physical, 24GB usable)
Serialization
All of the ghw
XXXInfo
structs -- e.g. ghw.CPUInfo
-- have two methods
for producing a serialized JSON or YAML string representation of the contained
information:
JSONString()
returns a string containing the information serialized into
JSON. It accepts a single boolean parameter indicating whether to use
indentation when outputting the stringYAMLString()
returns a string containing the information serialized into
YAML
Developers
Contributions to ghw
are welcomed! Fork the repo on GitHub and submit a pull
request with your proposed changes. Or, feel free to log an issue for a feature
request or bug report.
This project uses dep to manage dependencies.
Dependencies must be set to a specific tag (no open-ended dependencies) in the
Gopkg.toml
file. To manually execute dep
run make dep
.
Running tests
You can run unit tests easily using the make test
command, like so:
[jaypipes@uberbox ghw]$ make test
go test github.com/jaypipes/ghw github.com/jaypipes/ghw/cmd/ghwc
ok github.com/jaypipes/ghw 0.084s
? github.com/jaypipes/ghw/cmd/ghwc [no test files]
from ghw.
I think the godoc should be used for the code information. Because as stated above, many projects use it, and it is completly free (if it is hosted on github). As for the information that does not concern the code, that could be inside the readme. As @icholy stated.
from ghw.
ack, @glvr182 and @icholy, that's fair.
Glenn, please feel free to work on a set of patches that would do just that! :)
Thank you very much in advance!
-jay
from ghw.
@glvr182 @icholy @jpo-joyent OK, so I put together a doc.go and updated the cpu.go module to have in-code comments/descriptions for all struct fields, member methods and package-level functions.
If you go to https://godoc.org/github.com/jaypipes/ghw you will see what the new long-form docs look like.
If you ask me, I think they look terrible compared to the existing README.md markdown docs and are harder to read and understand. I'm interested in your thoughts and opinions. Please share.
from ghw.
If you're going to include the examples in the godoc, there's built-in support for it https://blog.golang.org/examples
I prefer keeping the long-form docs in the README though.
from ghw.
Related Issues (20)
- NIC on Windows has IsVirtual always set to false HOT 1
- I am surprised HOT 2
- May disk's driver type need more checks HOT 5
- Properly detect iSCSI disks HOT 2
- Properly detect dm devices HOT 3
- ghw-snapshot broken on Linux >= 5.16-rc3: hugepages demote HOT 1
- GPU information cannot be queried after virtual machine GPU pass through. By traversing the PCI information, it is found that the driver is not NVIDIA but vfio PCI. Can I add a vendor Name judge whether the PCI identification is GPU HOT 2
- replace ethtool invocation with go packages HOT 1
- drop use of blkid on block_linux.go HOT 1
- ghw.PCI throw an exception “pciFillInfo not implemented on windows” HOT 6
- github.com/StackExchange/wmi is archived, change it HOT 1
- too many open files error when using ghw in gotop client HOT 1
- Panic when collecting host information HOT 5
- Consider updating declared Go version in go.mod HOT 1
- On my windows, sometimes it show error: Cannot change thread mode after it is set HOT 7
- ci: enable gh actions with arm64 HOT 1
- ARM: failed to determine memory area for node: open /sys/devices/system/memory/block_size_bytes: no such file or directory HOT 7
- HDD is classified as SSD on windows 10 HOT 1
- Linux: failed to determine memory area for node: open /sys/devices/system/node/node0/memory_failure/state: no such file or directory HOT 11
- Possible bug in parsing core.ID and core.Index HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ghw.