open admin UI on windows

Change-Id: I0df5042ddd9bb9058660468b862916a97b86c280
This commit is contained in:
Brad Fitzpatrick 2011-07-17 17:30:40 -07:00
parent 7a0e7a30ce
commit 95a98d991d
2 changed files with 49 additions and 0 deletions

View File

@ -0,0 +1,36 @@
/*
Copyright 2011 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package osutil
import (
"exec"
"runtime"
"os"
)
func OpenURL(url string) os.Error {
if runtime.GOOS == "windows" {
return exec.Command("start", url).Run()
}
if runtime.GOOS == "darwin" {
return exec.Command("open", url).Run()
}
return exec.Command("xdg-open", url).Run()
}

View File

@ -22,6 +22,7 @@ import (
"http"
"log"
"path/filepath"
"runtime"
"strings"
"os"
@ -194,6 +195,7 @@ func main() {
handler: make(map[string]interface{}),
}
uiPath := ""
for prefix, vei := range prefixes {
if !strings.HasPrefix(prefix, "/") {
exitFailure("prefix %q doesn't start with /", prefix)
@ -221,8 +223,19 @@ func main() {
conf: handlerArgs,
}
hl.config[prefix] = h
if handlerType == "ui" {
uiPath = prefix
}
}
hl.setupAll()
ws.Listen()
if runtime.GOOS == "windows" && uiPath != "" {
// Might be double-clicking an icon with no shell window?
// Just open the URL for them.
osutil.OpenURL(ws.BaseURL() + uiPath)
}
ws.Serve()
}