Home

Awesome

This project was forked from github.com/HMS-Core/hms-push-serverdemo-go.

Table of Contents

Introduction

Golang sample code encapsulates APIs of the HUAWEI Push Kit server. It provides many sample programs for your reference or usage.

The following describes packages of Golang sample code.

PackageDescription
examplesSample code packages. Each package can run independently.
httpclientCommon package for sending network requests.
pushPackage where APIs of the HUAWEI Push Kit server are encapsulated.

Installation

Before using Golang sample code, check whether the Golang environment has been installed. Golang 1.11 or a later version is recommended. Decompress the Golang sample code package.

Copy the org.huawei.com package in the decompressed folder to the project vendor directory in the path specified by GOPATH. Refresh the project and ensure that the file is successfully copied to the destination directory.

Configuration

Golang sample code uses the Client structure in the push package as the entry. Each method in the Client structure calls an API of the HUAWEI Push Kit server. The following describes methods in the Client structure.

MethodDescription
SendMessageSends a message to a device.

To use functions provided by packages in examples, you need to set related parameters in pushcommon.go in the common package.

The following describes parameters in pushcommon.go.

ParameterDescription
appIdApp ID, which is obtained from app information.
appSecretSecret access key of an app, which is obtained from app information.
authUrlURL for the Huawei OAuth 2.0 service to obtain a token, please refer to Generating an App-Level Access Token.
pushUrlURL for accessing HUAWEI Push Kit, please refer to Sending Messages.

The following table describes parameters in target.go.

ParameterDescription
TargetTopicName of a topic to be subscribed to, unsubscribed from, or queried.
TargetConditionCombination of condition expressions for a message.
TargetTokenToken of a target device, which is obtained from the device.
TargetTokenArrayTokens of all target devices, which are obtained from the devices.

License

pushkit Go sample is licensed under the Apache License, version 2.0.