當前位置: 首頁>>代碼示例>>Golang>>正文


Golang webbrowser.Open函數代碼示例

本文整理匯總了Golang中github.com/toqueteos/webbrowser.Open函數的典型用法代碼示例。如果您正苦於以下問題:Golang Open函數的具體用法?Golang Open怎麽用?Golang Open使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Open函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Download

func (f *FileManager) Download(request *messaging.FileRequest) messaging.FileResponse { // save the file to ftp and download via ftp on browser
	fileResponse := messaging.FileResponse{}

	if len(request.Body) == 0 {

	} else {
		var saveServerPath string = request.RootSavePath
		var accessServerPath string = request.RootGetPath

		fmt.Println(request.RootSavePath)
		fmt.Println(request.RootGetPath)

		file := FileData{}
		json.Unmarshal(request.Body, &file)

		temp := common.DecodeFromBase64(file.Body)
		ioutil.WriteFile((saveServerPath + request.FilePath + file.FileName), []byte(temp), 0666)
		err := webbrowser.Open(accessServerPath + request.FilePath + file.FileName)
		if err != nil {
			fileResponse.IsSuccess = false
			fileResponse.Message = "Downloading Failed!" + err.Error()
		} else {
			fileResponse.IsSuccess = true
			fileResponse.Message = "Downloading file successfully completed"
		}

	}

	return fileResponse
}
開發者ID:sajeetharan,項目名稱:v6engine,代碼行數:30,代碼來源:FileManager.go

示例2: StartWeb

func StartWeb(wg sync.WaitGroup) {
	defer wg.Done()

	cfg := config.Read()
	listenUri := fmt.Sprintf("%s:%d", cfg.Server.Host, cfg.Server.Port)

	mux := http.NewServeMux()

	mux.HandleFunc("/creds/info", web.RawCredHandler)
	mux.HandleFunc("/creds/info/", web.InfoCredHandler)
	mux.HandleFunc("/creds", CredHandler)

	mux.HandleFunc("/users/", UsersHandler)

	mux.HandleFunc("/connect", ConnectHandler)
	mux.HandleFunc("/ping", PingHandler)
	mux.HandleFunc("/protocol-handler", ProtocolHandlerHandler)

	static := http.FileServer(http.Dir(config.AssetDir("htdocs")))
	mux.Handle("/", static)

	server := &http.Server{
		Addr:    listenUri,
		Handler: mux,
	}

	log.Println("Webservice will start on", listenUri)
	if cfg.Application.OpenWebUIOnStart {
		log.Println("Opening web browser…")
		// TODO: Create proper welcome page
		webbrowser.Open(fmt.Sprintf("%s", listenUri))
	}
	panic(server.ListenAndServe())
}
開發者ID:jphastings,項目名稱:credence,代碼行數:34,代碼來源:server.go

示例3: Initialize

func Initialize(newAddressList *addresslist.SafeIPList,
	newSandwichSettings *settings.Settings,
	newShutdown func(fileindex.FileManifest)) {
	addressList = newAddressList
	sandwichSettings = newSandwichSettings
	shutdown = newShutdown
	go downloadThread()
	go downloadThread()
	go downloadThread()
	go downloadThread()
	DownloadQueue = make(chan *IPFilePair, 1000)
	file, err := os.Open(util.ConfPath("manifest-cache.json"))
	if err != nil && os.IsNotExist(err) {
		fileManifest = client.BuildFileManifest()
	} else if err != nil {
		log.Println(err)
		fileManifest = client.BuildFileManifest()
	} else if xml, err := ioutil.ReadAll(file); err != nil {
		log.Println(err)
		fileManifest = client.BuildFileManifest()
		file.Close()
	} else if fileManifest, err = fileindex.UnmarshalManifest(xml); err != nil {
		fileManifest = client.BuildFileManifest()
	} else {
		fileManifest = client.CleanManifest(fileManifest)
		file.Close()
	}
	go InitializeFancyStuff()
	if !sandwichSettings.DontOpenBrowserOnStart {
		webbrowser.Open("http://localhost:" + sandwichSettings.LocalServerPort)
	}
}
開發者ID:sandwich-share,項目名稱:sandwich-go,代碼行數:32,代碼來源:front-end.go

示例4: openIssue

func openIssue(issue *github.Issue) error {
	task := fmt.Sprintf("Open issue #%v in the browser", *issue.Number)
	if err := webbrowser.Open(*issue.HTMLURL); err != nil {
		return errs.NewError(task, err)
	}
	return nil
}
開發者ID:jkotrlik,項目名稱:salsaflow,代碼行數:7,代碼來源:code_review_tool.go

示例5: ServeTestGin

func (jts *JobTypeServer) ServeTestGin( //--port int,
	htmlFiles_l []string) error {
	router := jts.mkGinEngine(htmlFiles_l)
	server := httptest.NewServer(router)
	defer server.Close()
	url := server.URL

	//	port_s := ""
	//	if port > 0 && port < 65536 {
	//		port_s = fmt.Sprintf(":%d", port)
	//	}
	//	url := fmt.Sprintf("http://localhost%s/", port_s)

	go func() {
		time.Sleep(100 * time.Millisecond)
		err := webbrowser.Open(url)
		if err != nil {
			log.Error("FAILED to open url in browser", "err", err)
		}
	}()

	//	server.Start()
	time.Sleep(3 * time.Second)
	return nil
	//	router := jts.mkGinEngine(htmlFiles_l)
	//	return router.Run(port_s) // listen and server on 0.0.0.0:8080
}
開發者ID:ContiGuy,項目名稱:conti-gui,代碼行數:27,代碼來源:srvgin.go

示例6: main

func main() {

	var home RefHandler
	var search SearchHandler
	var login LoginHandler
	var logout LogoutHandler
	var admin AdminViewHandler
	var searchAdmin SearchAdminHandler
	var edit EditHandler
	var delete DeleteHandler
	var new NewHandler

	port := ":8080"
	log.Println("Starting Web Server 127.0.0.1" + port)
	go Exit()

	webbrowser.Open("http://localhost" + port)

	mux := mux.NewRouter()

	mux.Handle("/", home).Name("home")
	mux.Handle("/search", search)
	mux.Handle("/login", login).Methods("POST")
	mux.Handle("/logout", logout)
	mux.Handle("/admin", admin)
	mux.Handle("/admin/search", searchAdmin)
	mux.Handle("/admin/new", new)
	mux.Handle("/admin/edit/{id}", edit)
	mux.Handle("/admin/delete/{id}", delete)

	err := http.ListenAndServe(port, mux)
	check(err)
}
開發者ID:kameleon83,項目名稱:referentiel-go,代碼行數:33,代碼來源:annuaire.go

示例7: ServeGin

func ServeGin(port int, baseDir string, htmlFiles_l []string) error {
	router := gin.Default()

	router.GET("/", func(c *gin.Context) {
		eh := errHandler_T{}
		var index_b []byte
		eh.safe(func() {
			for _, fn := range htmlFiles_l {
				index_b, eh.err = ioutil.ReadFile(fn)
				if eh.err == nil {
					var n int64
					n, eh.err = io.Copy(c.Writer, bytes.NewBuffer(index_b))
					log.Info("serving local file index.html", "file", fn, "size", n, "err", eh.err)
					break
				}
			}
			if len(index_b) == 0 {
				eh.err = wui.WriteWuiHtml(c.Writer)
				log.Info("serving builtin index.html", "err", eh.err)
			}
		})

		eh.ifErr(func() { c.AbortWithError(http.StatusBadRequest, eh.err) })
	})

	router.POST("/jobs/:jobType", func(c *gin.Context) {
		//		time.Sleep(300 * time.Millisecond)
		eh := errHandler_T{}
		eh.handleJobPost(baseDir, c)
	})

	router.GET("/jobs/:jobType", func(c *gin.Context) {
		//		time.Sleep(300 * time.Millisecond)
		eh := errHandler_T{}
		eh.handleJobList(baseDir, c)
	})

	router.GET("/ping", func(c *gin.Context) {
		c.JSON(200, gin.H{
			"message": "pong",
		})
	})

	port_s := ""
	if port > 0 && port < 65536 {
		port_s = fmt.Sprintf(":%d", port)
	}
	url := fmt.Sprintf("http://localhost%s/", port_s)

	go func() {
		time.Sleep(100 * time.Millisecond)
		err := webbrowser.Open(url)
		if err != nil {
			log.Error("FAILED to open url in browser", "err", err)
		}
	}()

	return router.Run(port_s) // listen and server on 0.0.0.0:8080
}
開發者ID:ContiGuy,項目名稱:conti-gui,代碼行數:59,代碼來源:srvVersions.go

示例8: browserOutput

// opens browser with Subreddits representation
func browserOutput(subreddits []*Subreddit, port string) {

	viewHandler := func(w http.ResponseWriter, r *http.Request) {
		page := `<html>
			<head>
				<style type="text/css">
					body {margin: 0 auto; max-width: 640px; background: black; color: #CCC; font-family: Courier New, Courier; line-height: 1.2em;}
					.content {padding: 10px;}
					.entry {margin-bottom: 20px;}
					.entry-title a:link, .entry-title a:visited {color: #9df; text-decoration: none;}
					.entry-permalink a:link, .entry-permalink a:visited {color: #CCC; text-decoration: none; font-size: 0.8em;}
					.entry a:hover {color: #6cf;}
					.entry-image {width: 100%; margin-top: 10px;}
				</style>
			</head>
		  	<body>
		  		<div class="content">
				    {{ range . }}
						<h1>{{ .Name }}</h1>
						<div class="subreddit">
						{{ range .Entries }}
							<div class="entry">
								<span class="entry-score">{{ .Score }}<span>
								<span class="entry-title"><a target="_blank" href="{{ .URL }}">{{ .Title }}</a><span>
								<span class="entry-permalink"><a target="_blank" href="http://www.reddit.com{{ .Permalink }}">comments</a><span>
								{{ if .IsImage }}
								    <br /><img class="entry-image" src="{{ .URL }}" alt="" />
								{{ end }}
								{{ if .HasEmbed }}
									<br />{{ .EmbedHtml }}
								{{ end }}
							</div>
						{{ end }}
						</div>
				    {{ end }}
			    </div>
		  	</body>
		</html>`

		t := template.New("browser")
		t, _ = t.Parse(page)
		t.Execute(w, subreddits)
	}

	wait := make(chan bool)
	http.HandleFunc("/", viewHandler)
	log.Println("HTTP server starting, go to http://localhost:" + port)
	go func() {
		if err := http.ListenAndServe(":"+port, nil); err != nil {
			log.Fatal("ListenAndServe: ", err)
		}
		wait <- true
	}()
	webbrowser.Open("http://localhost:" + port)
	<-wait
}
開發者ID:sara62,項目名稱:fire,代碼行數:57,代碼來源:fire.go

示例9: main

func main() {
	noBrowser := false
	flag.BoolVar(&noBrowser, "noBrowser", false, "If set, no browser is opened automatically.")
	flag.Parse()
	done := make(chan bool, 1)

	go bowieweb.Serve(done)
	// start web browser
	if !noBrowser {
		webbrowser.Open("http://localhost:8000")
	}
	// wait for bowieweb to finish serving
	<-done
}
開發者ID:Schokomuesl1,項目名稱:bowie,代碼行數:14,代碼來源:bowieMain.go

示例10: main

func main() {
  ​anaconda.SetConsumerKey("j62kyFWBVqCiJElWSHvofSz59")
  anaconda.SetConsumerSecret("FmA9RF7MAEwLbvXfvYRgZMMstinToo6kbR7CcwfpdhWrsEPyrg")
  // webbrowser.Open()
	url, cred, _ := anaconda.AuthorizationURL("")
	webbrowser.Open(url)

	var pincode int64
	fmt.Scan(&pincode)

	newcred, _, _ := anaconda.GetCredentials(cred, strconv.FormatInt(pincode, 10))

	fmt.Printf("%v\n%v\n", newcred.Token, newcred.Secret)
}
開發者ID:KazushiSakashita,項目名稱:MAOUVS,代碼行數:14,代碼來源:testn.go

示例11: main

func main() {
	data, err := ioutil.ReadFile(*googleConfigJSON)
	if err != nil {
		log.Panic(err)
	}
	conf, err := Oauth2ConfigFromJSON(data)
	if err != nil {
		log.Panic(err)
	}

	// Redirect user to consent page to ask for permission
	// for the scopes specified above.
	url := conf.AuthCodeURL("state", oauth2.AccessTypeOffline)
	fmt.Printf("Enter the code returned after authorising access: ")
	webbrowser.Open(url)

	// Use the authorization code that is pushed to the redirect URL.
	// NewTransportWithCode will do the handshake to retrieve
	// an access token and initiate a Transport that is
	// authorized and authenticated by the retrieved token.
	var code string
	if _, err := fmt.Scan(&code); err != nil {
		log.Panic(err)
	}
	tok, err := conf.Exchange(oauth2.NoContext, code)
	if err != nil {
		log.Panic(err)
	}

	ac := gads.AuthConfig{
		OAuth2Config: conf,
		OAuth2Token:  tok,
		Auth: gads.Auth{
			CustomerId:     "INSERT_YOUR_CLIENT_CUSTOMER_ID_HERE",
			DeveloperToken: "INSERT_YOUR_DEVELOPER_TOKEN_HERE",
			UserAgent:      "tests (Golang 1.4 github.com/emiddleton/gads)",
		},
	}
	configData, err := json.MarshalIndent(&ac, "", "    ")
	if err != nil {
		log.Panic(err)
	}
	err = ioutil.WriteFile(*newConfigJSON, configData, 0600)
	if err != nil {
		log.Panic(err)
	}
}
開發者ID:Nyarum,項目名稱:gads,代碼行數:47,代碼來源:setup_oauth2.go

示例12: WaitForServer

func WaitForServer() {
	log.Printf("Waiting for listener on port %d", *args.Port)
	url := fmt.Sprintf("http://localhost:%d/edit/%s", *args.Port, url.QueryEscape(*args.File))
	for {
		time.Sleep(time.Millisecond * 50)
		resp, err := http.Get(url)
		if err != nil {
			continue
		}
		resp.Body.Close()
		break
	}
	log.Println("Opening " + url)
	if err := webbrowser.Open(url); err != nil {
		log.Printf("Possible error while opening browser: %s", err)
	}
}
開發者ID:nochso,項目名稱:gomd,代碼行數:17,代碼來源:gomd.go

示例13: main

func main() {
	go func() {
		fmt.Println("Création du .json le ", time.Now())
		fmt.Println("Veuillez patienter quelques instants. Une fois fini, un message vous l'indiquera.")
		createFile(filenameCsv)

		if err := filepath.Walk(root, walkpath); err == nil {
			if err := jsonWrite(filenameCsv); err == nil {
				webbrowser.Open("http://localhost:8080")
			}
		}
	}()
	log.Println("Le serveur est bien démarré")
	http.Handle("/", http.StripPrefix("/", http.FileServer(http.Dir("."))))

	http.ListenAndServe(":8080", nil)

}
開發者ID:kameleon83,項目名稱:searchWordsPagesStatic,代碼行數:18,代碼來源:generate-search.go

示例14: view

func view(cmd string, args []string) {
	desc := "view listed pictures in browser-based gallery (or piped from stdin)"
	fs := newFlagSet(cmd, "[PIC-ID...]", desc)
	fs.BoolVar(&noedit, "noedit", false, "don't allow editing of anything in library")
	fs.StringVar(&addr, "addr", "127.0.0.1:", "ip and port to serve gallery at")
	fs.BoolVar(&all, "all", false, "true to view every file in the library")
	fs.Parse(args)

	l, err := net.Listen("tcp", addr)
	check(err)
	addr = l.Addr().String()
	go runserve(l, fs.Args())
	log.Printf("serving on address %v", addr)

	err = webbrowser.Open(addr)
	check(err)

	select {}
}
開發者ID:rwcarlsen,項目名稱:gallery,代碼行數:19,代碼來源:pics.go

示例15: main

func main() {
	app := cli.NewApp()
	app.Name = "go-pr"
	app.Usage = "Create a Pull Request for the current branch"
	app.UsageText = `
    go-pr @target-branch # default target-user to your Github user
    go-pr target-user/[email protected]
    go-pr target-user/target-repo # default target-branch to master
    go-pr target-user # default target-branch to master and target-repo to the name of your Github repo
    `
	app.Version = "0.0.1"
	app.Author = "Bao Pham"
	app.Email = "[email protected]"

	app.Before = func(c *cli.Context) error {
		if len(c.Args()) < 1 {
			return errors.New("Target is required")
		}

		return nil
	}

	app.Action = func(c *cli.Context) {
		remote := getRemote()

		branch := getBranch()

		currentRepo := NewRepo(remote, branch)

		target := parseTarget(c.Args().First(), currentRepo)

		if !currentRepo.IsGithub() {
			println("Only support Github for now")
			os.Exit(1)
		}

		webbrowser.Open(fmt.Sprintf("https://github.com/%s/%s/compare/%s...%s:%s",
			target.username, target.name, target.branch,
			currentRepo.username, currentRepo.branch))
	}

	app.Run(os.Args)
}
開發者ID:baopham,項目名稱:go-pr,代碼行數:43,代碼來源:main.go


注:本文中的github.com/toqueteos/webbrowser.Open函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。