Commit 975321364f
975321364f49295e83f269f5c267cd315c9f86a4
parent: f08d755cae
Unsigned
Wraient <wraient.911@gmail.com> · 2025-08-26 21:56 UTC
Add: Vendors
Layout: unified · split
vendor/github.com/pkg/browser/LICENSE
added
+23
| @@ -0,0 +1,23 @@ |
| |
1 | Copyright (c) 2014, Dave Cheney <dave@cheney.net> |
| |
2 | All rights reserved. |
| |
3 | |
| |
4 | Redistribution and use in source and binary forms, with or without |
| |
5 | modification, are permitted provided that the following conditions are met: |
| |
6 | |
| |
7 | * Redistributions of source code must retain the above copyright notice, this |
| |
8 | list of conditions and the following disclaimer. |
| |
9 | |
| |
10 | * Redistributions in binary form must reproduce the above copyright notice, |
| |
11 | this list of conditions and the following disclaimer in the documentation |
| |
12 | and/or other materials provided with the distribution. |
| |
13 | |
| |
14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| |
15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| |
16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| |
17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| |
18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| |
19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| |
20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| |
21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| |
22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| |
23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
vendor/github.com/pkg/browser/browser.go
added
+57
| @@ -0,0 +1,57 @@ |
| |
1 | // Package browser provides helpers to open files, readers, and urls in a browser window. |
| |
2 | // |
| |
3 | // The choice of which browser is started is entirely client dependant. |
| |
4 | package browser |
| |
5 | |
| |
6 | import ( |
| |
7 | "fmt" |
| |
8 | "io" |
| |
9 | "io/ioutil" |
| |
10 | "os" |
| |
11 | "os/exec" |
| |
12 | "path/filepath" |
| |
13 | ) |
| |
14 | |
| |
15 | // Stdout is the io.Writer to which executed commands write standard output. |
| |
16 | var Stdout io.Writer = os.Stdout |
| |
17 | |
| |
18 | // Stderr is the io.Writer to which executed commands write standard error. |
| |
19 | var Stderr io.Writer = os.Stderr |
| |
20 | |
| |
21 | // OpenFile opens new browser window for the file path. |
| |
22 | func OpenFile(path string) error { |
| |
23 | path, err := filepath.Abs(path) |
| |
24 | if err != nil { |
| |
25 | return err |
| |
26 | } |
| |
27 | return OpenURL("file://" + path) |
| |
28 | } |
| |
29 | |
| |
30 | // OpenReader consumes the contents of r and presents the |
| |
31 | // results in a new browser window. |
| |
32 | func OpenReader(r io.Reader) error { |
| |
33 | f, err := ioutil.TempFile("", "browser.*.html") |
| |
34 | if err != nil { |
| |
35 | return fmt.Errorf("browser: could not create temporary file: %v", err) |
| |
36 | } |
| |
37 | if _, err := io.Copy(f, r); err != nil { |
| |
38 | f.Close() |
| |
39 | return fmt.Errorf("browser: caching temporary file failed: %v", err) |
| |
40 | } |
| |
41 | if err := f.Close(); err != nil { |
| |
42 | return fmt.Errorf("browser: caching temporary file failed: %v", err) |
| |
43 | } |
| |
44 | return OpenFile(f.Name()) |
| |
45 | } |
| |
46 | |
| |
47 | // OpenURL opens a new browser window pointing to url. |
| |
48 | func OpenURL(url string) error { |
| |
49 | return openBrowser(url) |
| |
50 | } |
| |
51 | |
| |
52 | func runCmd(prog string, args ...string) error { |
| |
53 | cmd := exec.Command(prog, args...) |
| |
54 | cmd.Stdout = Stdout |
| |
55 | cmd.Stderr = Stderr |
| |
56 | return cmd.Run() |
| |
57 | } |
vendor/github.com/pkg/browser/browser_darwin.go
added
+5
| @@ -0,0 +1,5 @@ |
| |
1 | package browser |
| |
2 | |
| |
3 | func openBrowser(url string) error { |
| |
4 | return runCmd("open", url) |
| |
5 | } |
vendor/github.com/pkg/browser/browser_freebsd.go
added
+14
| @@ -0,0 +1,14 @@ |
| |
1 | package browser |
| |
2 | |
| |
3 | import ( |
| |
4 | "errors" |
| |
5 | "os/exec" |
| |
6 | ) |
| |
7 | |
| |
8 | func openBrowser(url string) error { |
| |
9 | err := runCmd("xdg-open", url) |
| |
10 | if e, ok := err.(*exec.Error); ok && e.Err == exec.ErrNotFound { |
| |
11 | return errors.New("xdg-open: command not found - install xdg-utils from ports(8)") |
| |
12 | } |
| |
13 | return err |
| |
14 | } |
vendor/github.com/pkg/browser/browser_linux.go
added
+21
| @@ -0,0 +1,21 @@ |
| |
1 | package browser |
| |
2 | |
| |
3 | import ( |
| |
4 | "os/exec" |
| |
5 | "strings" |
| |
6 | ) |
| |
7 | |
| |
8 | func openBrowser(url string) error { |
| |
9 | providers := []string{"xdg-open", "x-www-browser", "www-browser"} |
| |
10 | |
| |
11 | // There are multiple possible providers to open a browser on linux |
| |
12 | // One of them is xdg-open, another is x-www-browser, then there's www-browser, etc. |
| |
13 | // Look for one that exists and run it |
| |
14 | for _, provider := range providers { |
| |
15 | if _, err := exec.LookPath(provider); err == nil { |
| |
16 | return runCmd(provider, url) |
| |
17 | } |
| |
18 | } |
| |
19 | |
| |
20 | return &exec.Error{Name: strings.Join(providers, ","), Err: exec.ErrNotFound} |
| |
21 | } |
vendor/github.com/pkg/browser/browser_netbsd.go
added
+14
| @@ -0,0 +1,14 @@ |
| |
1 | package browser |
| |
2 | |
| |
3 | import ( |
| |
4 | "errors" |
| |
5 | "os/exec" |
| |
6 | ) |
| |
7 | |
| |
8 | func openBrowser(url string) error { |
| |
9 | err := runCmd("xdg-open", url) |
| |
10 | if e, ok := err.(*exec.Error); ok && e.Err == exec.ErrNotFound { |
| |
11 | return errors.New("xdg-open: command not found - install xdg-utils from pkgsrc(7)") |
| |
12 | } |
| |
13 | return err |
| |
14 | } |
vendor/github.com/pkg/browser/browser_openbsd.go
added
+14
| @@ -0,0 +1,14 @@ |
| |
1 | package browser |
| |
2 | |
| |
3 | import ( |
| |
4 | "errors" |
| |
5 | "os/exec" |
| |
6 | ) |
| |
7 | |
| |
8 | func openBrowser(url string) error { |
| |
9 | err := runCmd("xdg-open", url) |
| |
10 | if e, ok := err.(*exec.Error); ok && e.Err == exec.ErrNotFound { |
| |
11 | return errors.New("xdg-open: command not found - install xdg-utils from ports(8)") |
| |
12 | } |
| |
13 | return err |
| |
14 | } |
vendor/github.com/pkg/browser/browser_unsupported.go
added
+12
| @@ -0,0 +1,12 @@ |
| |
1 | // +build !linux,!windows,!darwin,!openbsd,!freebsd,!netbsd |
| |
2 | |
| |
3 | package browser |
| |
4 | |
| |
5 | import ( |
| |
6 | "fmt" |
| |
7 | "runtime" |
| |
8 | ) |
| |
9 | |
| |
10 | func openBrowser(url string) error { |
| |
11 | return fmt.Errorf("openBrowser: unsupported operating system: %v", runtime.GOOS) |
| |
12 | } |
vendor/github.com/pkg/browser/browser_windows.go
added
+7
| @@ -0,0 +1,7 @@ |
| |
1 | package browser |
| |
2 | |
| |
3 | import "golang.org/x/sys/windows" |
| |
4 | |
| |
5 | func openBrowser(url string) error { |
| |
6 | return windows.ShellExecute(0, nil, windows.StringToUTF16Ptr(url), nil, nil, windows.SW_SHOWNORMAL) |
| |
7 | } |