master
 1package get
 2
 3/*
 4#cgo linux LDFLAGS: ./lib/libsystem.a
 5#cgo darwin LDFLAGS: ./lib/libsystem.a -framework IOKit
 6#cgo windows LDFLAGS: ./lib/libsystem.a
 7#include "../../lib/system.h"
 8#include <stdlib.h>
 9*/
10import "C"
11import (
12	"fmt"
13
14	"github.com/kahnwong/swissknife/configs/color"
15)
16
17func Sensors() error {
18	result := C.sensors()
19
20	switch result.error {
21	case C.SENSOR_SUCCESS:
22		fmt.Printf("%s: %.2f\n", color.Green("Temperature"), float64(result.temperature))
23		return nil
24	case C.SENSOR_NO_COMPONENTS:
25		return fmt.Errorf("no components found")
26	case C.SENSOR_NO_TEMPERATURE:
27		return fmt.Errorf("no temperature reading available")
28	default:
29		return fmt.Errorf("unknown error occurred")
30	}
31}