giohyperlink

package module
v0.0.0-...-2ac5d54 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 3, 2022 License: MIT, Unlicense Imports: 4 Imported by: 6

README

Opens a hyperlink in the default browser. 🤩

Setup

First, you need to go get github.com/inkeliz/giohyperlink, then you need to provide giohyperlink access to the Window events, so you need to add the following to your main loop function:


```diff
 for evt := range w.Events() { // Gio main event loop
+    giohyperlink.ListenEvents(e)

    switch evt := evt.(type) {
        // ...
    }
}

⚠️In some OSes (Windows, macOS...) this setup is optional, but it's recommended to do it anyway.

Usage

To open one link, you can use the Open function:

giohyperlink.Open("https://github.com")

That will open the link in the default browser. You can use OpenURL to open a *url.URL:

giohyperlink.OpenURL(&url.URL{
    Scheme: "https",
    Host:   "github.com",
})

By default only HTTP and HTTPS links are allowed, but you can change that by changing InsecureIgnoreScheme to true, you should validate the URL and scheme on your own.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotReady may occur when try to open a URL before the initialization is done.
	ErrNotReady = errors.New("some needed library was not loaded yet, make use that you are using ListenEvents()")
	// ErrInvalidURL occur when provide an invalid URL, like a non http/https URL.
	ErrInvalidURL = errors.New("given url is invalid")
)
View Source
var (
	// InsecureIgnoreScheme will remove any attempt to validate the URL
	// It's "false" by default. Set it to "true" if you are using a custom scheme (like "myapp://").
	InsecureIgnoreScheme bool
)

Functions

func ListenEvents

func ListenEvents(event event.Event)

ListenEvents must get all the events from Gio, in order to get the GioView once it's ready. You need to include that function where you listen for Gio events.

Similar as:

select {
case e := <-w.Events():
	giohyperlink.ListenEvents(e)

	switch e := e.(type) {
     (( ... your code ...  ))

func Open

func Open(uri string) error

Open opens the given string url in the browser (or equivalent app).

func OpenURL

func OpenURL(u *url.URL) error

OpenURL opens the given url.URL in the browser (or equivalent app)

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL