hyperlink

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2024 License: BSD-3-Clause, MIT Imports: 3 Imported by: 0

README

Go Reference

Open a hyperlink in the default browser.


Usage

Freestanding

  • hyperlink.NewShare:
    • Creates a instance of Share struct, given the config.
  • hyperlink.Configure:
    • Updates the current Share with the given config.
  • hyperlink.Open:
    • Opens the link in the default browser.
    • By default, only supports http and https schemes.

Gio

Non-Plugin:

If you want to use it without plugin, read the Freestanding instructions. We provide some helper functions, such as NewConfigFromViewEvent and such.

To open one link, you can use the Open operation.

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

giohyperlink.OpenOp{URI: &url.URL{
    Scheme: "https",
    Host:   "github.com",
}}.Add(gtx.Ops)
Operations:

Operations must be added with .Add(gtx.Ops) method. The operation will be executed at the end of the frame.

  • giohyperlink.OpenOp:
    • Opens the link in the default browser. Currently, only supports http and https schemes.

Events:

Events are response sent using the Tag and should be handled with gtx.Events().

  • giohyperlink.ErrorEvent:
    • Sent to Tag when it's not possible to open the hyperlink.

Features

Features Windows Android MacOS iOS WebAssembly FreeBSD Linux
HTTP
HTTPS

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

This section is empty.

Types

type Config

type Config struct{}

Config is the configuration for a Hyperlink.

type Hyperlink struct {
	// contains filtered or unexported fields
}

Hyperlink is the main struct, which holds the driver.

func NewHyperlink(config Config) *Hyperlink

NewHyperlink creates a new hyperlink.

func (*Hyperlink) Configure

func (h *Hyperlink) Configure(config Config)

Configure reconfigures the driver.

func (*Hyperlink) Open

func (h *Hyperlink) Open(uri *url.URL) error

Open opens the given URL. It will return ErrInvalidURL if the URL doesn't use http or https.

If you want to ignore the scheme, set InsecureIgnoreScheme to true, or use OpenUnsafe.

func (*Hyperlink) OpenUnsafe

func (h *Hyperlink) OpenUnsafe(uri *url.URL) error

OpenUnsafe is the same as Open, but it doesn't validate the URL.

That may crash or cause unexpected behavior if you use a non http/https URL, so use it with caution.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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