Here is an example program in Go to get the system CPU temperature in Fahrenheit:
main.go973 chars36 lines
This code uses the exec
package to run the sensors
command, which is commonly available on Linux systems to get hardware temperature readings. It then looks for the line in the output containing the CPU temperature, parses the temperature in Celsius, and converts it to Fahrenheit using the conversion formula. Finally, it prints the temperature in Fahrenheit to the console.
gistlibby LogSnag