wrap

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2020 License: MIT Imports: 3 Imported by: 0

README

gojs/wrap

Some wrappers for js callers

Compatible with JS and WASM

Wrappers example

Console
c := wrap.ConsoleGet()

// There is pure js calls of console object

c.Log("Some text")
c.Error("Error log")
c.Info("Info text")
c.Warn("Warn text")
Location
l := wrap.LocationGet()

path := l.GetPathname() + l.GetSearch() + l.GetHash()
println(path)

println(l.GetFullDomainPath())

l.Reload()     // just reload
l.Reload(true) // force reload without cache
History
// Change URL and adds it to history

h := wrap.HistoryGet()
h.PushState(nil, "", "/someurl")

// OR

h.PushURL("/someurl")

// ReplaceURL without history
h.ReplaceURL("/someurl-replace")
wrap.CookieSet("name", "value", "")                               // without path and expires
wrap.CookieSet("name", "value", "/", time.Now().AddDate(0, 1, 0)) // with path and expires in next month

value, ok := wrap.CookieGet("name")
wrap.ConsoleGet().Log(value, ok)

wrap.CookieDelete("name")
Alert
wrap.Alert("Just alert")

Documentation

Rendered for js/wasm

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Alert

func Alert(s string)

Alert calls alert in JS

func CookieDelete

func CookieDelete(name string)

CookieDelete deletes a cookie specified by name

func CookieGet

func CookieGet(name string) (value string, ok bool)

CookieGet returns a given cookie by name. If the cookie is not set then ok will be set to false

func CookieSet

func CookieSet(name, value, path string, expires ...time.Time)

CookieSet adds a cookie to a user's browser with a name, value, expiry and path value, path and expires can be omitted

Examples: Without path and expires: CookieSet("name", "value", "")

or with path and expires to next month: CookieSet("name", "value", "/", time.Now().AddDate(0, 1, 0))

func CookieSetString

func CookieSetString(cookie string)

CookieSetString sets a cookie given a correctly formatted cookie string i.e "username=John Smith; expires=Thu, 18 Dec 2013 12:00:00 UTC; path=/"

func IsCookieEnabled

func IsCookieEnabled() bool

IsCookieEnabled returns false if setting a cookie will be ignored and true otherwise.

Types

type Console

type Console struct {
	Value js.Value
}

Console object

func ConsoleGet

func ConsoleGet() *Console

ConsoleGet returns console

func (*Console) Clear

func (c *Console) Clear()

Clear clears the console if the environment allows it

func (*Console) Count

func (c *Console) Count(label string)

Count logs the number of times that this particular call to Count() has been called

func (*Console) Debug

func (c *Console) Debug(args ...interface{})

Debug outputs a message to the console with the log level "debug"

func (*Console) Error

func (c *Console) Error(args ...interface{})

Error outputs an error message.

func (*Console) Info

func (c *Console) Info(args ...interface{})

Info is a informative logging of information

func (*Console) Log

func (c *Console) Log(args ...interface{})

Log outputs a message to the Web Console. For general output of logging information

func (*Console) Time

func (c *Console) Time(label string)

Time starts a timer you can use to track how long an operation takes. label identify the timer.

func (*Console) TimeEnd

func (c *Console) TimeEnd(label string)

TimeEnd stops a timer that was previously started by calling Time

func (*Console) TimeLog

func (c *Console) TimeLog(label string)

TimeLog logs the current value of a timer that was previously started by calling Time

func (*Console) Trace

func (c *Console) Trace()

Trace outputs a stack trace

func (*Console) Warn

func (c *Console) Warn(args ...interface{})

Warn outputs a warning message.

type History

type History struct {
	Value js.Value
}

History object

func HistoryGet

func HistoryGet() *History

HistoryGet returns js history object

func (*History) Back

func (h *History) Back()

Back moves to backward through history. This acts exactly as if the user clicked on the Back button in their browser toolbar.

func (*History) Forward

func (h *History) Forward()

Forward moves forward as if the user clicked the Forward button.

func (*History) Go

func (h *History) Go(delta int)

Go method loads a specific page from the session history. You can use it to move forwards and backwards through the history. -1 equivalent of calling Back()

1 just like calling Forward()

-2 or 2 backwards by two pages or forward two pages

0 will reload the current page

func (*History) PushState

func (h *History) PushState(state interface{}, title, url string)

PushState adds a state to the browser's session history stack. state - JavaScript object which is associated with the new history entry. title - most browsers currently ignores this parameter, although they may use it in the future. url - The new history entry's URL is given by this parameter. Note that the browser won't attempt to load this URL after a call to pushState(), but it might attempt to load the URL later, for instance after the user restarts the browser.

func (*History) PushURL

func (h *History) PushURL(url string)

PushURL is a wrap pushState just to set url and add it to history

func (*History) ReplaceState

func (h *History) ReplaceState(state interface{}, title, url string)

ReplaceState method modifies the current history entry, replacing it with the state, title, and URL passed in the method parameters. This method is particularly useful when you want to update the state object or URL of the current history entry in response to some user action.

func (*History) ReplaceURL

func (h *History) ReplaceURL(url string)

ReplaceURL is a wrap replaceState just to set new URL without adding it to history

type Location

type Location struct {
	Value js.Value
}

Location object allows you to get any parts of the URL and set href fragments. If you want to set new URL use History object

func LocationGet

func LocationGet() *Location

LocationGet returns location object

func (*Location) GetFullDomainPath

func (l *Location) GetFullDomainPath() string

GetHostnameFullPath return full path with hostname and protocol

func (*Location) GetFullPath

func (l *Location) GetFullPath() string

GetFullPath is just wrap to get current full path without host like a 'path?query=param#fragment' in the root path will be '/'

func (*Location) GetHash

func (l *Location) GetHash() string

GetHash returns string containing a '#' followed by the fragment identifier of the URL.

func (*Location) GetHost

func (l *Location) GetHost() string

GetHost returns string containing the host, that is the hostname, a ':', and the port of the URL.

func (*Location) GetHostname

func (l *Location) GetHostname() string

GetHostname returns string containing the domain of the URL

func (*Location) GetHref

func (l *Location) GetHref() string

GetHref returns string containing the entire URL

func (*Location) GetOrigin

func (l *Location) GetOrigin() string

GetOrigin returns string containing the canonical form of the origin of the specific location.

func (*Location) GetPathname

func (l *Location) GetPathname() string

GetPathname returns string containing an initial '/' followed by the path of the URL.

func (*Location) GetPort

func (l *Location) GetPort() string

GetPort returns string containing the port number of the URL

func (*Location) GetProtocol

func (l *Location) GetProtocol() string

GetProtocol returns string containing the protocol scheme of the URL including the final ':', example 'http:' or 'https:'

func (*Location) GetSearch

func (l *Location) GetSearch() string

GetSearch returns string containing a '?' followed by the parameters or "querystring" of the URL.

func (*Location) Reload

func (l *Location) Reload(forcedReload ...bool)

Reload reloads the current resource, like the Refresh button. It has an optional Boolean parameter, which is false by default. If true, the page is always reloaded from the server, ignoring the browser cache.

func (*Location) SetHref

func (l *Location) SetHref(href string)

SetHref sets href and associated document navigates to the new page

Jump to

Keyboard shortcuts

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