本文整理汇总了Golang中github.com/pkg/browser.OpenURL函数的典型用法代码示例。如果您正苦于以下问题:Golang OpenURL函数的具体用法?Golang OpenURL怎么用?Golang OpenURL使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了OpenURL函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: openService
func openService(ns string, serviceName string, c *k8sclient.Client, printURL bool, retry bool) {
if retry {
if err := RetryAfter(40, func() error { return CheckService(ns, serviceName, c) }, 10*time.Second); err != nil {
util.Errorf("Could not find finalized endpoint being pointed to by %s: %v", serviceName, err)
os.Exit(1)
}
}
svcs, err := c.Services(ns).List(kubeApi.ListOptions{})
if err != nil {
util.Errorf("No services found %v\n", err)
}
found := false
for _, service := range svcs.Items {
if serviceName == service.Name {
url := service.ObjectMeta.Annotations[exposeURLAnnotation]
if printURL {
util.Successf("%s\n", url)
} else {
util.Successf("\nOpening URL %s\n", url)
browser.OpenURL(url)
}
found = true
break
}
}
if !found {
util.Errorf("No service %s in namespace %s\n", serviceName, ns)
}
}
示例2: StackoverflowceptionCheck
func StackoverflowceptionCheck(err error) bool {
if err != nil {
url := "http://stackoverflow.com/search?q="
url += err.Error()
browser.OpenURL(url)
return true
}
return false
}
示例3: authorizeInBrowser
// Opens a browser tab/window with the login to pocket for authorization.
// Only returns when the user presses enter.
func authorizeInBrowser(requestToken string, redirectURI string) {
template := "https://getpocket.com/auth/authorize?" +
"request_token=%s&redirect_uri=%s"
url := fmt.Sprintf(template, requestToken, redirectURI)
browser.OpenURL(url)
reader := bufio.NewReader(os.Stdin)
fmt.Println("Press enter when authorized")
_, err := reader.ReadString('\n')
checkFatal(err)
}
示例4: main
func main() {
var err error
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage of %s: command <args>...\n", os.Args[0])
flag.PrintDefaults()
}
flag.Parse()
if len(flag.Args()) < 1 {
flag.Usage()
return
}
ifaceAndPort := fmt.Sprintf("%v:0", *iface)
listener, err := net.Listen("tcp4", ifaceAndPort)
if err != nil {
log.Fatal(err)
}
pr, pw, _ := os.Pipe()
gcChan := make(chan *gctrace, 1)
scvgChan := make(chan *scvgtrace, 1)
parser := Parser{
reader: pr,
gcChan: gcChan,
scvgChan: scvgChan,
}
gcvisGraph = NewGraph(strings.Join(flag.Args(), " "), GCVIS_TMPL)
go startSubprocess(pw, flag.Args())
go parser.Run()
http.HandleFunc("/", indexHandler)
go http.Serve(listener, nil)
url := fmt.Sprintf("http://%s/", listener.Addr())
log.Printf("opening browser window, if this fails, navigate to %s", url)
browser.OpenURL(url)
for {
select {
case gcTrace := <-gcChan:
gcvisGraph.AddGCTraceGraphPoint(gcTrace)
case scvgTrace := <-scvgChan:
gcvisGraph.AddScavengerGraphPoint(scvgTrace)
}
}
}
示例5: main
// main is the entry point for the application.
func main() {
print("Starting - HTTP service on port 8676\n")
print("Press 'ctrl + c' to quit\n")
folderPath, err := osext.ExecutableFolder()
if err != nil {
print(err)
}
browser.OpenURL("http://localhost:8676/index.html")
panic(http.ListenAndServe(":8676", http.FileServer(http.Dir(folderPath))))
}
示例6: main
func main() {
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage of %s: command <args>...\n", os.Args[0])
flag.PrintDefaults()
}
flag.Parse()
if len(flag.Args()) < 1 {
flag.Usage()
return
}
subcommand := NewSubCommand(flag.Args())
parser := NewParser(subcommand.PipeRead)
gcvisGraph := NewGraph(strings.Join(flag.Args(), " "), GCVIS_TMPL)
server := NewHttpServer(*iface, *port, &gcvisGraph)
go subcommand.Run()
go parser.Run()
go server.Start()
url := server.Url()
log.Printf("opening browser window, if this fails, navigate to %s", url)
browser.OpenURL(url)
for {
select {
case gcTrace := <-parser.GcChan:
gcvisGraph.AddGCTraceGraphPoint(gcTrace)
case scvgTrace := <-parser.ScvgChan:
gcvisGraph.AddScavengerGraphPoint(scvgTrace)
case output := <-parser.NoMatchChan:
fmt.Fprintln(os.Stderr, output)
case <-parser.done:
if parser.Err != nil {
fmt.Fprintf(os.Stderr, parser.Err.Error())
os.Exit(1)
}
if subcommand.Err() != nil {
fmt.Fprintf(os.Stderr, subcommand.Err().Error())
os.Exit(1)
}
os.Exit(0)
}
}
}
示例7: Open
// Open opens a product on the amazon website
func Open(c *cli.Context) {
api := api.Create(c.GlobalString("locale"))
conf := config.GetConfig()
asin, exists := conf.ASINFromCache("Products", c.Args().First())
if !exists {
fmt.Fprintln(os.Stderr, "Cannot look up ASIN")
os.Exit(1)
}
result, err := api.ItemLookup(asin, "Small")
if err != nil {
panic(err)
}
browser.OpenURL(result.Items.ItemList[0].DetailPageURL)
}
示例8: serve
func serve(ctx context.Context) error {
wgctx.Add(ctx, "serve")
defer wgctx.Done(ctx, "serve")
env := envctx.FromContext(ctx)
cmd := cmdctx.FromContext(ctx)
// Starting with port zero chooses a random open port
listner, err := net.Listen("tcp", fmt.Sprintf(":%d", cmd.Port))
if err != nil {
return kerr.Wrap("QGLXHWPWQW", err)
}
defer listner.Close()
// Here we get the address we're serving on
address, ok := listner.Addr().(*net.TCPAddr)
if !ok {
return kerr.New("CBLPYVGGUR", "Can't find address (l.Addr() is not *net.TCPAddr)")
}
url := fmt.Sprintf("http://localhost:%d/%s/", address.Port, env.Path)
cmd.Printf("Server now running on %s\n", url)
// We open the default browser and navigate to the address we're serving
// from. This will error if the system doesn't have a browser, so we can
// ignore the error.
browser.OpenURL(url)
withCancel(ctx, func() {
err = http.Serve(listner, nil)
})
if err != nil {
return kerr.Wrap("TUCBTWMRNN", err)
}
if cmd.Debug {
return kerr.New("ATUTBOICGJ", "Connection closed")
}
return nil
}
示例9: Checkout
// Checkout initiates the checkout for a cart
func Checkout(c *cli.Context) {
api := api.Create(c.GlobalString("locale"))
conf := config.GetConfig()
defer conf.Flush()
cartName := conf.CartNameFromCache(c.Args().First())
if cart, exists := conf.Carts[cartName]; exists {
if getResponse, getErr := api.CartGet(cart.CartID, cart.HMAC); getErr == nil {
delete(conf.Carts, cartName)
browser.OpenURL(getResponse.Cart.PurchaseURL)
} else {
panic(getErr)
}
} else {
fmt.Fprintf(os.Stderr, "Cart %s is unknown\n", cartName)
os.Exit(1)
}
}
示例10: main
func main() {
if len(os.Args) < 2 {
log.Fatalf("usage: %s command <args>...", os.Args[0])
}
pr, pw, _ := os.Pipe()
gc := make(chan *gctrace, 1)
scvg := make(chan *scvgtrace, 1)
go startSubprocess(pw)
go startParser(pr, gc, scvg)
l, err := net.Listen("tcp4", "127.0.0.1:0")
if err != nil {
log.Fatal(err)
}
http.HandleFunc("/", index)
go http.Serve(l, nil)
url := fmt.Sprintf("http://%s/", l.Addr())
log.Printf("opening browser window, if this fails, navigate to %s", url)
browser.OpenURL(url)
for {
select {
case gc := <-gc:
mu.Lock()
ts := int(time.Now().UnixNano() / 1e6)
heapuse = append(heapuse, graphPoints{ts, gc.Heap1})
mu.Unlock()
case scvg := <-scvg:
mu.Lock()
ts := int(time.Now().UnixNano() / 1e6)
scvginuse = append(scvginuse, graphPoints{ts, scvg.inuse})
scvgidle = append(scvgidle, graphPoints{ts, scvg.idle})
scvgsys = append(scvgsys, graphPoints{ts, scvg.sys})
scvgreleased = append(scvgreleased, graphPoints{ts, scvg.released})
scvgconsumed = append(scvgconsumed, graphPoints{ts, scvg.consumed})
mu.Unlock()
}
}
}
示例11: openURL
func openURL(data string, isHTML bool) error {
if isHTML {
tmpfile, err := ioutil.TempFile("", "pmbopenurl")
if err != nil {
return err
}
_, err = tmpfile.Write([]byte(data))
if err != nil {
return err
}
err = tmpfile.Close()
if err != nil {
return err
}
nameWithSuffix := fmt.Sprintf("%s.html", tmpfile.Name())
err = os.Rename(tmpfile.Name(), nameWithSuffix)
if err != nil {
return err
}
go func() {
time.Sleep(15 * time.Second)
logrus.Infof("cleaning up temporary file: %s", nameWithSuffix)
os.Remove(nameWithSuffix)
}()
logrus.Infof("opening file: %s", nameWithSuffix)
return browser.OpenFile(nameWithSuffix)
}
logrus.Infof("opening url: %s", data)
return browser.OpenURL(data)
}
示例12: doServe
func doServe(c *cli.Context) {
master := c.Bool("master")
theme := c.String("theme")
// Get the presentation path from the command line, or grab the current directory.
presentationPath, _ := os.Getwd()
if len(c.Args()) > 0 {
presentationPath = c.Args()[0]
}
// Check if the path is relative.
if !strings.HasPrefix(presentationPath, "/") {
presentationPath, _ = filepath.Abs(presentationPath)
}
// Check if there is a presentation file present.
if _, err := os.Stat(path.Join(presentationPath, "slides.md")); err != nil {
fmt.Printf("slides.md does not exist at %s\n", presentationPath)
os.Exit(1)
}
if theme != "" {
fmt.Println("Using one of the packaged themes ...")
http.Handle("/css/", http.FileServer(&assetfs.AssetFS{Asset, AssetDir, "themes/" + theme}))
http.Handle("/fonts/", http.FileServer(&assetfs.AssetFS{Asset, AssetDir, "themes/" + theme}))
} else {
if _, err := os.Stat(path.Join(presentationPath, "css", "theme.css")); err == nil {
fmt.Println("Found a theme, using it ...")
http.Handle("/css/", http.FileServer(http.Dir(presentationPath)))
http.Handle("/fonts/", http.FileServer(http.Dir(presentationPath)))
} else {
fmt.Println("No theme found ...")
}
}
// Handle the slides.
http.HandleFunc("/slides.md", func(w http.ResponseWriter, r *http.Request) {
t, _ := template.ParseFiles(path.Join(presentationPath, "slides.md"))
t.Execute(w, "")
})
// Handle images.
http.HandleFunc("/img/", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, path.Join(presentationPath, r.URL.Path))
})
// Handle reveal.js files.
http.Handle("/reveal.js/css/", http.FileServer(&assetfs.AssetFS{Asset, AssetDir, ""}))
http.Handle("/reveal.js/js/", http.FileServer(&assetfs.AssetFS{Asset, AssetDir, ""}))
http.Handle("/reveal.js/lib/", http.FileServer(&assetfs.AssetFS{Asset, AssetDir, ""}))
http.Handle("/reveal.js/plugin/", http.FileServer(&assetfs.AssetFS{Asset, AssetDir, ""}))
// Handle the website.
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
opt := &Option{Markdown: "slides.md", Master: master}
indexHTML, _ := Asset("assets/index.html")
indexTemplate := template.Must(template.New("index").Parse(string(indexHTML)))
indexTemplate.Execute(w, opt)
})
fmt.Println("Opening browser and redirecting to the presentation ...")
browser.OpenURL("http://localhost:8989")
err := http.ListenAndServe(":8989", nil)
panic("Error while serving slides: " + err.Error())
}
示例13: init
defer api.Close()
url, err := cluster.GetServiceURL(api, namespace, service, serviceURLTemplate)
if err != nil {
fmt.Fprintln(os.Stderr, err)
if _, ok := err.(cluster.MissingNodePortError); !ok {
fmt.Fprintln(os.Stderr, "Check that minishift is running and that you have specified the correct namespace (-n flag).")
}
os.Exit(1)
}
if https {
url = strings.Replace(url, "http", "https", 1)
}
if serviceURLMode {
fmt.Fprintln(os.Stdout, url)
} else {
fmt.Fprintln(os.Stdout, "Opening kubernetes service "+namespace+"/"+service+" in default browser...")
browser.OpenURL(url)
}
},
}
func init() {
serviceCmd.Flags().StringVarP(&namespace, "namespace", "n", "default", "The service namespace")
serviceCmd.Flags().BoolVar(&serviceURLMode, "url", false, "Display the kubernetes service URL in the CLI instead of opening it in the default browser")
serviceCmd.PersistentFlags().StringVar(&serviceURLFormat, "format", "http://{{.IP}}:{{.Port}}", "Format to output service URL in")
serviceCmd.Flags().BoolVar(&https, "https", false, "Open the service URL with https instead of http")
RootCmd.AddCommand(serviceCmd)
}
示例14: main
func main() {
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage of %s: command <args>...\n", os.Args[0])
flag.PrintDefaults()
}
var pipeRead io.ReadCloser
var subcommand *SubCommand
flag.Parse()
if len(flag.Args()) < 1 {
if terminal.IsTerminal(int(os.Stdin.Fd())) {
flag.Usage()
return
} else {
pipeRead = os.Stdin
}
} else {
subcommand = NewSubCommand(flag.Args())
pipeRead = subcommand.PipeRead
go subcommand.Run()
}
parser := NewParser(pipeRead)
gcvisGraph := NewGraph(strings.Join(flag.Args(), " "), GCVIS_TMPL)
server := NewHttpServer(*iface, *port, &gcvisGraph)
go parser.Run()
go server.Start()
url := server.Url()
if *openBrowser {
log.Printf("opening browser window, if this fails, navigate to %s", url)
browser.OpenURL(url)
} else {
log.Printf("server started on %s", url)
}
for {
select {
case gcTrace := <-parser.GcChan:
gcvisGraph.AddGCTraceGraphPoint(gcTrace)
case scvgTrace := <-parser.ScvgChan:
gcvisGraph.AddScavengerGraphPoint(scvgTrace)
case output := <-parser.NoMatchChan:
fmt.Fprintln(os.Stderr, output)
case <-parser.done:
if parser.Err != nil {
fmt.Fprintf(os.Stderr, parser.Err.Error())
os.Exit(1)
}
break
}
}
if subcommand != nil && subcommand.Err() != nil {
fmt.Fprintf(os.Stderr, subcommand.Err().Error())
os.Exit(1)
}
os.Exit(0)
}
示例15: handleEvents
func handleEvents(eventChan chan termbox.Event) {
for ev := range eventChan {
switch ev.Type {
case termbox.EventKey:
switch ev.Key {
case termbox.KeyArrowUp:
case termbox.KeyArrowDown:
case termbox.KeySpace:
// page down
lock.Lock()
totalN := len(events)
lock.Unlock()
if selectedRow >= totalN-1 {
// the last event
continue
}
if !detailView {
if selectedRow/pageSize == totalN/pageSize {
// already the last page, do nothing
continue
}
selectedRow += pageSize
if selectedRow > totalN-1 {
// can't be beyond the range
selectedRow = totalN - 1
}
page++
redrawAll()
}
continue
case termbox.KeyEnter:
if detailView {
browser.OpenURL(currentWebHook.Commits[len(currentWebHook.Commits)-selectedCommit-1].Url)
}
continue
case termbox.KeyCtrlD:
// dashboard page
if dashboardView {
redrawAll()
} else {
drawDashboardByHour()
}
dashboardView = !dashboardView
case termbox.KeyCtrlP:
if projectSummaryView {
redrawAll()
} else {
drawDashboardByProject()
}
projectSummaryView = !projectSummaryView
case termbox.KeyCtrlU:
if userSummaryView {
redrawAll()
} else {
drawDashboardByUser()
}
userSummaryView = !userSummaryView
case termbox.KeyEsc:
if detailView {
detailView = false
redrawAll()
} else {
termbox.Close()
os.Exit(0)
}
}
switch ev.Ch {
case 'j':
if detailView {
if selectedCommit < len(currentWebHook.Commits)-1 {
selectedCommit++
} else {
selectedCommit = 0 // rewind
}
drawDetail()
} else {
lock.Lock()
totalN := len(events)
lock.Unlock()
if selectedRow < totalN-1 {
selectedRow++
if selectedRow%pageSize == 0 {
page++
}
redrawAll()
}
}
//.........这里部分代码省略.........