2016-09-01 22:34:48 +00:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"errors"
|
|
|
|
"io"
|
|
|
|
"os/exec"
|
|
|
|
"runtime"
|
|
|
|
)
|
|
|
|
|
2016-11-01 09:56:12 +00:00
|
|
|
var cmd map[string]string
|
2016-09-01 22:34:48 +00:00
|
|
|
var stderr bytes.Buffer
|
|
|
|
|
|
|
|
func init() {
|
2016-11-01 09:56:12 +00:00
|
|
|
cmd = map[string]string{
|
2016-09-01 22:34:48 +00:00
|
|
|
"windows": "start",
|
|
|
|
"darwin": "open",
|
|
|
|
"linux": "xdg-open",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Open(url string) (io.Writer, error) {
|
2016-11-01 09:56:12 +00:00
|
|
|
if open, err := cmd[runtime.GOOS]; !err {
|
2016-09-01 22:34:48 +00:00
|
|
|
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 {
|
|
|
|
return cmd.Stderr, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil, nil
|
|
|
|
}
|