本文整理汇总了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
}
示例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())
}
示例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)
}
}
示例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
}
示例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
}
示例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)
}
示例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
}
示例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
}
示例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
}
示例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)
}
示例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)
}
}
示例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)
}
}
示例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)
}
示例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 {}
}
示例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)
}