realize/server/open.go

36 lines
587 B
Go
Raw Normal View History

2016-09-01 22:34:48 +00:00
package server
import (
"bytes"
"errors"
2016-10-14 09:03:58 +00:00
"fmt"
2016-09-01 22:34:48 +00:00
"io"
"os/exec"
"runtime"
)
var cli map[string]string
var stderr bytes.Buffer
func init() {
cli = map[string]string{
"windows": "start",
"darwin": "open",
"linux": "xdg-open",
}
}
func Open(url string) (io.Writer, error) {
if open, err := cli[runtime.GOOS]; !err {
return nil, errors.New("This operating system is not supported.")
} else {
cmd := exec.Command(open, url)
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
2016-10-14 09:03:58 +00:00
fmt.Println(cmd.Stderr, err)
2016-09-01 22:34:48 +00:00
return cmd.Stderr, err
}
}
return nil, nil
}