1 Star 0 Fork 0

tuboyou/c2

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
open.go 1.08 KB
一键复制 编辑 原始数据 按行查看 历史
tuboyou 提交于 2025-03-10 18:02 +08:00 . 添加注释
//go:build linux || darwin
// +build linux darwin
package u2
import (
"log"
"os/exec"
"runtime"
)
// Open 在默认应用程序中打开指定的链接或文件夹
//
// 参数:
//
// link - 要打开的URL或文件路径。可以是:
// - 网页地址(如 "https://example.com")
// - 本地文件路径(如 "/path/to/file")
// - 文件夹路径(如 "/path/to/folder")
//
// 注意:
// 1. 该函数目前仅支持Linux和macOS系统
// 2. 在Linux系统上使用xdg-open命令
// 3. 在macOS系统上使用open命令
// 4. 在其他操作系统上会记录不支持的信息
//
// 示例:
//
// Open("https://example.com") // 在默认浏览器中打开网页
// Open("/path/to/file.txt") // 用默认应用程序打开文件
// Open("/path/to/folder") // 在文件管理器中打开文件夹
func Open(link string) {
if runtime.GOOS == "linux" {
c := exec.Command("xdg-open", link)
c.Start()
} else if runtime.GOOS == "darwin" {
c := exec.Command("open", link)
c.Start()
} else {
log.Println("not support this os: ", runtime.GOOS)
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/tuboyou/c2.git
git@gitee.com:tuboyou/c2.git
tuboyou
c2
c2
v0.0.4

搜索帮助