Git Product home page Git Product logo

ldnvnbl / hms-push-serverdemo-go Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hms-core/hms-push-serverdemo-go

1.0 2.0 0.0 51 KB

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

Home Page: https://developer.huawei.com/consumer/cn/doc/development/HMS-Guides/push-introduction

License: Apache License 2.0

Go 100.00%

hms-push-serverdemo-go's Introduction

HMS Pushkit Go Severdemo

English | δΈ­ζ–‡

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.

Package Description
examples Sample code packages. Each package can run independently.
httpclient Common package for sending network requests.
push Package 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.

Method Description
SendMessage Sends 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.

Parameter Description
appId App ID, which is obtained from app information.
appSecret Secret access key of an app, which is obtained from app information.
authUrl URL for the Huawei OAuth 2.0 service to obtain a token, please refer to Generating an App-Level Access Token.
pushUrl URL for accessing HUAWEI Push Kit, please refer to Sending Messages.

The following table describes parameters in target.go.

Parameter Description
TargetTopic Name of a topic to be subscribed to, unsubscribed from, or queried.
TargetCondition Combination of condition expressions for a message.
TargetToken Token of a target device, which is obtained from the device.
TargetTokenArray Tokens of all target devices, which are obtained from the devices.

Sample Code

Download Golang sample code in Downloading Server Sample Code.

1). Send an Android data message. You can obtain the initialized MessageRequest instance of the data message using the NewTransparentMsgRequest method in the push/model package.

Code location: examples/send_data_message/main.go

2). Send an Android notification message. You can obtain the initialized MessageRequest instance of the notification message using the NewNotificationMsgRequest method in the push/model package.

Code location: examples/send_notify_message/main.go

3). Send a message by topic. You can send a notification message or data message to a device by topic. Specify the topic after obtaining the MessageRequest instance.

Code location: examples/send_topic_message/main.go

4). Send a message by conditions. You can send a notification message or data message to a device by conditions. Specify the conditions after obtaining the MessageRequest instance.

Code location: examples/send_condition_message/main.go

5). Send a message to a Huawei quick app. You can send a message to a quick app by setting FastAppTarget.

Code location: examples/send_instance_app_message/main.go

6). Send a message through the APNs agent. You can send a message through the APNs agent by setting Apns of the message.

Code location: examples/send_apns_message/main.go

7). Send a message through the WebPush agent. You can send a message through the WebPush agent by setting WebPush of the message.

Code location: examples/send_webpush_message/main.go

8). Send a test message.

Code location: examples/send_test_message/main.go

Question or issues

If you want to evaluate more about HMS Core, r/HMSCore on Reddit is for you to keep up with latest news about HMS Core, and to exchange insights with other developers.

If you have questions about how to use HMS samples, try the following options:

  • Stack Overflow is the best place for any programming questions. Be sure to tag your question with huawei-mobile-services.
  • Huawei Developer Forum HMS Core Module is great for general questions, or seeking recommendations and opinions.

If you run into a bug in our samples, please submit an issue to the Repository. Even better you can submit a Pull Request with a fix.

License

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

hms-push-serverdemo-go's People

Contributors

mike-mei avatar hmspushkit avatar

Stargazers

YangZhi avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.