{"id":24686929,"url":"https://github.com/rickypc/native-messaging-host","last_synced_at":"2026-03-02T09:32:12.904Z","repository":{"id":51051440,"uuid":"244579544","full_name":"rickypc/native-messaging-host","owner":"rickypc","description":"A module for sending and receiving native messaging protocol message","archived":false,"fork":false,"pushed_at":"2023-05-08T21:59:26.000Z","size":73,"stargazers_count":12,"open_issues_count":2,"forks_count":6,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-06-19T05:55:12.061Z","etag":null,"topics":["chrome","messaging","native","native-messaging","native-messaging-host"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rickypc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-03-03T08:19:57.000Z","updated_at":"2024-02-17T02:03:16.000Z","dependencies_parsed_at":"2024-06-19T05:35:48.222Z","dependency_job_id":null,"html_url":"https://github.com/rickypc/native-messaging-host","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rickypc%2Fnative-messaging-host","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rickypc%2Fnative-messaging-host/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rickypc%2Fnative-messaging-host/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rickypc%2Fnative-messaging-host/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rickypc","download_url":"https://codeload.github.com/rickypc/native-messaging-host/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235726364,"owners_count":19035841,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chrome","messaging","native","native-messaging","native-messaging-host"],"created_at":"2025-01-26T16:17:10.829Z","updated_at":"2025-10-08T15:31:52.790Z","avatar_url":"https://github.com/rickypc.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build](https://github.com/rickypc/native-messaging-host/actions/workflows/build.yml/badge.svg)](https://bit.ly/3djObUY)\n[![Coverage](https://img.shields.io/codecov/c/github/rickypc/native-messaging-host)](https://bit.ly/2TwjOyb)\n[![Dependabot](https://img.shields.io/badge/dependabot-enabled-025e8c?logo=Dependabot)](https://bit.ly/3Li7tqm)\n[![GoDev](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go\u0026logoColor=white\u0026style=flat-square)][4.1]\n[![GoDoc](https://godoc.org/github.com/rickypc/native-messaging-host?status.svg)][4.2]\n[![License](https://img.shields.io/github/license/rickypc/native-messaging-host)][8]\n\n# Native Messaging Host Module for Go\n\nnative-messaging-host is a module for sending [native messaging protocol][1]\nmessage marshalled from struct and receiving [native messaging protocol][1]\nmessage unmarshalled to struct. native-messaging-host can auto-update itself\nusing update URL that response with Google Chrome [update manifest][2],\nas well as it provides hook to install and uninstall manifest file to\n[native messaging host location][3].\n\n## Installation and Usage\n\nPackage documentation can be found on [GoDev][4.1] or [GoDoc][4.2].\n\nInstallation can be done with a normal `go get`:\n\n```\n$ go get github.com/rickypc/native-messaging-host\n```\n\n#### Sending Message\n\n```go\nmessaging := (\u0026host.Host{}).Init()\n\n// host.H is a shortcut to map[string]interface{}\nresponse := \u0026host.H{\"key\":\"value\"}\n\n// Write message from response to os.Stdout.\nif err := messaging.PostMessage(os.Stdout, response); err != nil {\n  log.Fatalf(\"messaging.PostMessage error: %v\", err)\n}\n\n// Log response.\nlog.Printf(\"response: %+v\", response)\n```\n\n#### Receiving Message\n\n```go\n// Ensure func main returned after calling [runtime.Goexit][5].\ndefer os.Exit(0)\n\nmessaging := (\u0026host.Host{}).Init()\n\n// host.H is a shortcut to map[string]interface{}\nrequest := \u0026host.H{}\n\n// Read message from os.Stdin to request.\nif err := messaging.OnMessage(os.Stdin, request); err != nil {\n  log.Fatalf(\"messaging.OnMessage error: %v\", err)\n}\n\n// Log request.\nlog.Printf(\"request: %+v\", request)\n```\n\n#### Auto Update Configuration\n\nupdates.xml example for cross platform executable:\n\n```xml\n\u003c?xml version='1.0' encoding='UTF-8'?\u003e\n\u003cgupdate xmlns='http://www.google.com/update2/response' protocol='2.0'\u003e\n  \u003capp appid='tld.domain.sub.app.name'\u003e\n    \u003cupdatecheck codebase='https://sub.domain.tld/app.download.all' version='1.0.0' /\u003e\n  \u003c/app\u003e\n\u003c/gupdate\u003e\n```\n\nupdates.xml example for individual platform executable:\n\n```xml\n\u003c?xml version='1.0' encoding='UTF-8'?\u003e\n\u003cgupdate xmlns='http://www.google.com/update2/response' protocol='2.0'\u003e\n  \u003capp appid='tld.domain.sub.app.name'\u003e\n    \u003cupdatecheck codebase='https://sub.domain.tld/app.download.darwin' os='darwin' version='1.0.0' /\u003e\n    \u003cupdatecheck codebase='https://sub.domain.tld/app.download.linux' os='linux' version='1.0.0' /\u003e\n    \u003cupdatecheck codebase='https://sub.domain.tld/app.download.exe' os='windows' version='1.0.0' /\u003e\n  \u003c/app\u003e\n\u003c/gupdate\u003e\n```\n\n```go\n// It will do daily update check.\nmessaging := (\u0026host.Host{\n  AppName:   \"tld.domain.sub.app.name\",\n  UpdateUrl: \"https://sub.domain.tld/updates.xml\", // It follows [update manifest][2]\n  Version:   \"1.0.0\",                              // Current version, it must follow [SemVer][6]\n}).Init()\n```\n\n#### Install and Uninstall Hooks\n\n```go\n// AllowedExts is a list of extensions that should have access to the native messaging host. \n// See [native messaging manifest](https://bit.ly/3aDA1Hv)\nmessaging := (\u0026host.Host{\n  AppName:     \"tld.domain.sub.app.name\",\n  AllowedExts: []string{\"chrome-extension://XXX/\", \"chrome-extension://YYY/\"},\n}).Init()\n\n...\n\n// When you need to install.\nif err := messaging.Install(); err != nil {\n  log.Printf(\"install error: %v\", err)\n}\n\n...\n\n// When you need to uninstall.\nhost.Uninstall()\n```\n\n#### Syntactic Sugar\n\nYou can import client package separately.\n\n```go\nimport \"github.com/rickypc/native-messaging-host/client\"\n```\n\n##### GET call with context\n\n```go\nctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)\ndefer cancel()\n\nresp := client.MustGetWithContext(ctx, \"https://domain.tld\")\ndefer resp.Body.Close()\n```\n\n##### GET call with tar.gz content\n\n```go\nctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)\ndefer cancel()\n\nclient.MustGetAndUntarWithContext(ctx, \"https://domain.tld\", \"/path/to/extract\")\n```\n\n##### GET call with zip content\n\n```go\nctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)\ndefer cancel()\n\nclient.MustGetAndUnzipWithContext(ctx, \"https://domain.tld\", \"/path/to/extract\")\n```\n\n##### POST call with context\n\n```go\nctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)\ndefer cancel()\n\nresp := client.MustPostWithContext(ctx, \"https://domain.tld\", \"application/json\", strings.NewReader(\"{}\"))\ndefer resp.Body.Close()\n```\n\nContributing\n-\nIf you would like to contribute code to Native Messaging Host repository you can do so\nthrough GitHub by forking the repository and sending a pull request.\n\nIf you do not agree to [Contribution Agreement](CONTRIBUTING.md), do not\ncontribute any code to Native Messaging Host repository.\n\nWhen submitting code, please make every effort to follow existing conventions\nand style in order to keep the code as readable as possible. Please also include\nappropriate test cases.\n\nThat's it! Thank you for your contribution!\n\nLicense\n-\nCopyright (c) 2018 - 2022 Richard Huang.\n\nThis utility is free software, licensed under: [Mozilla Public License (MPL-2.0)][8].\n\nDocumentation and other similar content are provided under [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License][9].\n\n[1]: https://bit.ly/3axo5Xv\n[2]: https://bit.ly/2vOdAR5\n[3]: https://bit.ly/2TuQrMw\n[4.1]: http://bit.ly/2Tw22L6\n[4.2]: https://bit.ly/2TMGqcj\n[5]: https://bit.ly/2Tt4Poo\n[6]: https://bit.ly/3cAVAdq\n[7]: https://bit.ly/3aDA1Hv\n[8]: https://mzl.la/2vLmCye\n[9]: https://bit.ly/2SMCRlS\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frickypc%2Fnative-messaging-host","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frickypc%2Fnative-messaging-host","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frickypc%2Fnative-messaging-host/lists"}