首页 » 技术分享 » golang 打开浏览器

golang 打开浏览器

 
package desktop

import (
    "fmt"
    "os/exec"
    "runtime"
)

var commands = map[string]string{
    "windows": "cmd /c start",
    "darwin":  "open",
    "linux":   "xdg-open",
}

var Version = "0.1.0"

// Open calls the OS default program for uri
func Open(uri string) error {
    run, ok := commands[runtime.GOOS]
    if !ok {
        return fmt.Errorf("don't know how to open things on %s platform", runtime.GOOS)
    }

    cmd := exec.Command(run, uri)
    return cmd.Start()
}

转载:https://www.qiansw.com/golang-calls-the-system-browser-to-open-a-web-page.html

转载自原文链接, 如需删除请联系管理员。

原文链接:golang 打开浏览器,转载请注明来源!

1