Skip to content

Commit

Permalink
open server url
Browse files Browse the repository at this point in the history
  • Loading branch information
asoseil committed Sep 1, 2016
1 parent f078087 commit 8c269b0
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions server/open.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package server

import (
"bytes"
"errors"
"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 {
return cmd.Stderr, err
}
}
return nil, nil
}

0 comments on commit 8c269b0

Please sign in to comment.