Documentation
¶
Overview ¶
Package host provides native-messaging host configurations, send and receive message handler, manifest install and uninstall, as well as auto update daily check.
Index ¶
- Constants
- type App
- type H
- type Host
- func (h *Host) AutoUpdateCheck()
- func (h *Host) GetHttpClient() *http.Client
- func (h *Host) Init() *Host
- func (h *Host) Install() error
- func (h *Host) MustGet(url string) *http.Response
- func (h *Host) OnMessage(reader io.Reader, v interface{}) error
- func (h *Host) PostMessage(writer io.Writer, v interface{}) error
- func (h *Host) Uninstall() error
- type Update
- type UpdateCheckResponse
Constants ¶
const ( HttpContinueTimeout = 5 HttpKeepAlive = 600 HttpDialTimeout = 10 HttpOverallTimeout = 15 IdleTimeout = 90 MaxConnections = 100 ResponseHeaderTimeout = 10 TLSDialTimeout = 15 )
The Http connection and timeout configurations.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type App ¶
An App is represent one application returned by updates.xml.
<app appid='tld.domain.sub.app.name'></app>
type H ¶
type H map[string]interface{}
H is a map[string]interface{} type shortcut and represents a dynamic key-value-pair data.
type Host ¶
type Host struct { AppName string `json:"name"` AppDesc string `json:"description"` ExecName string `json:"path"` AppType string `json:"type"` AllowedExts []string `json:"allowed_origins"` AutoUpdate bool `json:"-"` ByteOrder binary.ByteOrder `json:"-"` UpdateUrl string `json:"-"` Version string `json:"-"` }
Host represents a single native messaging host, where all native messaging host operations can be done.
func (*Host) AutoUpdateCheck ¶
func (h *Host) AutoUpdateCheck()
AutoUpdateCheck downloads the latest update as necessary.
func (*Host) GetHttpClient ¶
GetHttpClient provides http client with configured connection and timeout.
func (*Host) Init ¶
Init sets default value to its fields and return the Host pointer back.
* AppName is an application name in manifest file and will be defaulted to current executable file name without extension, if any.
* AppDesc is an application description in manifest file and will be defaulted to current AppName.
* AppType is an application communication type in manifest file and will be defaulted to "stdio".
* AutoUpdate indicates whether update check will be perform for this application and will be defaulted to true only if UpdateUrl and application Version are present, otherwise it will be false.
* ByteOrder specifies how to convert byte sequences into unsigned integers and will be defaulted to binary.LittleEndian.
* ExecName is an executable path used across the module and will get assigned to current executable's absolute path after the evaluation of any symbolic links.
messaging := (&host.Host{}).Init()
func (*Host) Install ¶
Install creates native-messaging manifest file on appropriate location. It will return error when it come across one. See https://developer.chrome.com/extensions/nativeMessaging#native-messaging-host-location-nix
func (*Host) MustGet ¶
MustGet is a helper that wraps a http GET call to given URL and log error if any.
func (*Host) OnMessage ¶
OnMessage reads message header and message body from given reader and unmarshal to given struct. It will return error when it come across one.
// Ensure func main returned after calling runtime.Goexit // See https://golang.org/pkg/runtime/#Goexit. defer os.Exit(0) messaging := (&host.Host{}).Init() // host.H is a shortcut to map[string]interface{} request := &host.H{} // Read message from os.Stdin to request. if err := messaging.OnMessage(os.Stdin, request); err != nil { log.Fatalf("messaging.OnMessage error: %v", err) } // Log request. log.Printf("request: %+v", request)
func (*Host) PostMessage ¶
PostMessage marshals given struct and writes message header and message body to given writer. It will return error when it come across one.
messaging := (&host.Host{}).Init() // host.H is a shortcut to map[string]interface{} response := &host.H{"key":"value"} // Write message from response to os.Stdout. if err := messaging.PostMessage(os.Stdout, response); err != nil { log.Fatalf("messaging.PostMessage error: %v", err) } // Log response. log.Printf("response: %+v", response)
func (*Host) Uninstall ¶
Uninstall removes native-messaging manifest file from installed location. It will return error when it come across one. See https://developer.chrome.com/extensions/nativeMessaging#native-messaging-host-location-nix
type Update ¶
type Update struct { Goos *string `xml:"os,attr"` Url *string `xml:"codebase,attr"` Version *string `xml:"version,attr"` }
An Update is represent application download URL and latest version.
It can have target OS optionally. This is an extended attribute that is not part of original Google Chrome update manifest.
<updatecheck codebase='https://sub.domain.tld/app.download.all' os='darwin' version='1.0.0' />
type UpdateCheckResponse ¶
An UpdateCheckResponse implements Google Chrome update manifest XML format borrowed from Google's Omaha. See https://developer.chrome.com/apps/autoupdate#update_manifest
<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'></gupdate>
func (*UpdateCheckResponse) GetUrlAndVersion ¶
func (u *UpdateCheckResponse) GetUrlAndVersion(appName string) (string, string)
GetUrlAndVersion returns download URL and latest version of given application name.