Skip to content
Permalink
Browse files

add opening of browser on `up start`

  • Loading branch information...
tj committed Jan 31, 2018
1 parent 5b3b6c7 commit 9de01b021614e8ccfc5773a7c2db6389e706d469
Showing with 11 additions and 0 deletions.
  1. +11 −0 internal/cli/start/start.go
@@ -1,10 +1,13 @@
package start

import (
"fmt"
"net"
"net/http"
"os"

"github.com/apex/log"
"github.com/pkg/browser"
"github.com/pkg/errors"
"github.com/tj/kingpin"

@@ -62,6 +65,8 @@ func init() {
return errors.Wrap(err, "initializing handler")
}

open(*addr)

log.WithField("address", *addr).Info("listening")
if err := http.ListenAndServe(*addr, h); err != nil {
return errors.Wrap(err, "binding")
@@ -70,3 +75,9 @@ func init() {
return nil
})
}

// open addr in the browser.
func open(addr string) {
_, port, _ := net.SplitHostPort(addr)
browser.OpenURL(fmt.Sprintf("http://localhost:%s", port))
}

0 comments on commit 9de01b0

Please sign in to comment.
You can’t perform that action at this time.