nat
github.com/qrtz/nativemessaging
go get github.com/qrtz/nativemessaging
nat

github.com/qrtz/nativemessaging

Native messaging host library for go application

go get github.com/qrtz/nativemessaging
Readme

nativemessaging

Native messaging host library for go application

Usage

Go host application

package main

import (
    "io"
    "os"

    "github.com/qrtz/nativemessaging"
)

func main() {
    decoder := nativemessaging.NewNativeJSONDecoder(os.Stdin)
    encoder := nativemessaging.NewNativeJSONEncoder(os.Stdout)

    for {
        var rsp response
        var msg message
        err := decoder.Decode(&msg)

        if err != nil {
            if err == io.EOF {
                // exit
                return
            }
            rsp.Text = err.Error()
        } else {
            if msg.Text == "ping" {
                rsp.Text = "pong"
                rsp.Success = true
            } else {
                // Echo the message back to the client
                rsp.Text = msg.Text
            }
        }

        if err := encoder.Encode(rsp); err != nil {
            // Log the error and exit
            return
        }
    }
}

type message struct {
    Text string `json:"text"`
}

type response struct {
    Text    string `json:"text"`
    Success bool   `json:"success"`
}

Javascript client

    chrome.runtime.sendNativeMessage('com.github.qrtz.nativemessaginghost', {text:'ping'}, (response) => {
        console.log('Native messaging host response ', response);
    })

More info:

https://developer.chrome.com/extensions/nativeMessaging
https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Native_messaging

GitHub Stars

12

LAST COMMIT

5yrs ago

MAINTAINERS

0

CONTRIBUTORS

1

OPEN ISSUES

0

OPEN PRs

0
VersionTagPublished
v0.0.0-20161221035708-f4769a80e040
3yrs ago
No alternatives found
No tutorials found
Add a tutorial