Skip to content

HAP Go SDK 文档 ​

Go client SDK for HAP.

Setup ​

  1. Download your Go SDK from HAP Console
  2. Extract the hap directory in the zip to your project directory
  3. Copy hap/lib/HAP_SDK64.dll (or HAP_SDK32.dll) to your build directory
  4. Import the hap package, e.g. import ("github.com/my-org/my-app/hap")

Usage ​

go
package main

import (
	"fmt"
	"github.com/my-org/my-app/hap"
)

func main() {
	// Initialize the SDK
	version := hap.NewClientVersion(1, 0, 0, 0)
	err := hap.Initialize("127.0.0.1", 16000, version)

	// Test login (with a dummy key for demonstration)
	err = hap.Login("HAPxxxxx")
	if err != nil {
		fmt.Println("✗ Login failed")
		fmt.Printf("Error code: %s\n", err.Error())
	} else {
		fmt.Println("✓ Login successful")

		// Test login integrity
		fmt.Println("\nTesting login integrity...")
		err = hap.LoginIntegrity()
		if err != nil {
			fmt.Println("✗ Login integrity check failed")
			fmt.Printf("Error code: %s\n", err.Error())
		} else {
			fmt.Println("✓ Login integrity check passed")
		}

		// Test heartbeat
		fmt.Println("\nTesting heartbeat...")
		err = hap.Heartbeat()
		if err != nil {
			fmt.Println("✗ Heartbeat failed")
			fmt.Printf("Error code: %s\n", err.Error())
		} else {
			fmt.Println("✓ Heartbeat successful")
		}
	}
}

可联系客服了解详情。