Ejemplo n.º 1
0
func main() {
	hw := internal.GetHardware()
	fmt.Println("Commands are 'status', 'lock', 'unlock' or 'quit'")
	bio := bufio.NewReader(os.Stdin)

	for {
		fmt.Fprintf(os.Stdout, "> ")
		os.Stdout.Sync()
		line, _, err := bio.ReadLine()
		if err != nil {
			fmt.Println("ERROR:", err)
			return
		}
		cmd := strings.ToLower(strings.TrimSpace(string(line)))
		switch {
		case strings.HasPrefix(cmd, "s"):
			fmt.Println(hw.Status())
		case strings.HasPrefix(cmd, "l"):
			if err := hw.SetStatus(lock.Locked); err != nil {
				fmt.Println("ERROR:", err)
			}
		case strings.HasPrefix(cmd, "u"):
			if err := hw.SetStatus(lock.Unlocked); err != nil {
				fmt.Println("ERROR:", err)
			}
		case strings.HasPrefix(cmd, "q"), strings.HasPrefix(cmd, "x"):
			return
		default:
			fmt.Printf("ERROR: unrecognized command %q\n", cmd)
		}
	}
}
Ejemplo n.º 2
0
func newLock() lock.LockServerStub {
	return lock.LockServer(&lockImpl{hw: internal.GetHardware()})
}