• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang open.Run函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/skratchdot/open-golang/open.Run函数的典型用法代码示例。如果您正苦于以下问题:Golang Run函数的具体用法?Golang Run怎么用?Golang Run使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Run函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: output

func (t *Terminal) output() bool {
	if t.printQuery {
		fmt.Println(string(t.input))
	}
	if len(t.expect) > 0 {
		fmt.Println(t.pressed)
	}
	found := len(t.selected) > 0
	if !found {
		cnt := t.merger.Length()
		if cnt > 0 && cnt > t.cy {
			desc := t.merger.Get(t.cy).AsString(t.ansi)
			pair := strings.Split(desc, " - ")
			err := open.Run(pair[1])
			if err != nil {
				println(err)
			}
			found = true
		}
	} else {
		sels := make([]selectedItem, 0, len(t.selected))
		for _, sel := range t.selected {
			sels = append(sels, sel)
		}
		sort.Sort(byTimeOrder(sels))
		for _, sel := range sels {
			open.Run(*sel.text)
			//fmt.Println(*sel.text)
		}
	}
	return found
}
开发者ID:jondot,项目名称:fzf,代码行数:32,代码来源:terminal.go


示例2: display

func display(plan string) {
	handler := func(w http.ResponseWriter, r *http.Request) {
		defer func() {
			if recover_string := recover(); recover_string != nil {
				error_handler(w, r, http.StatusNotFound)
			}
		}()
		var fileName string
		if r.URL.Path == "/" {
			fileName = "2048/index.html"
		} else {
			fileName = "2048/" + r.URL.Path[1:]
		}
		if _, err := os.Stat(fileName); err == nil {
			// File exists
			http.ServeFile(w, r, fileName)
		} else {
			panic(fmt.Sprintf("File not found %s", fileName))
		}

	}
	http.HandleFunc("/", handler)
	wg := &sync.WaitGroup{}
	wg.Add(1)
	go http.ListenAndServe("localhost:8080", nil)
	open.Run("http://localhost:8080")
	wg.Wait()
}
开发者ID:muhammedabuali,项目名称:AI2048,代码行数:28,代码来源:display.go


示例3: HelpCreateToken

func (l *Login) HelpCreateToken(e *Env) (string, error) {
	for i := 0; i < 4; i++ {
		fmt.Fprintf(e.Out, `
Input your account key or press ENTER to generate a new one.
NOTE: on pressing ENTER we'll try to open the url:
	%q
in default browser.
`,
			keysURL,
		)
		fmt.Fprintf(e.Out, `Account Key: `)

		var token string
		fmt.Fscanf(e.In, "%s\n", &token)
		token = strings.TrimSpace(token)
		if token != "" {
			return token, nil
		}

		err := open.Run(keysURL)
		if err != nil {
			fmt.Fprintf(e.Err,
				`Sorry, we couldn’t open the browser for you.
Go here to generate an account key: %q
`,
				keysURL,
			)
		}
	}
	return "", stackerr.New("Account key cannot be empty. Please try again.")
}
开发者ID:swhitley,项目名称:parse-cli,代码行数:31,代码来源:login.go


示例4: openExternalUrl

// openExternalUrl opens an external URL of one of our partners automatically
// at startup if configured to do so. It should only open the first time in
// a given session that Lantern is opened.
func openExternalUrl() {
	if openedExternal {
		log.Debugf("Not opening external URL again")
		return
	}
	defer func() {
		openedExternal = true
	}()

	path, s, err := packaged.ReadSettings()
	if err != nil {
		// Let packaged itself log errors as necessary.
		log.Debugf("Could not read yaml from %v: %v", path, err)
		return
	}

	var url string
	if s.StartupUrl == "" {
		return
	} else if strings.HasPrefix(s.StartupUrl, "https://www.facebook.com/manototv") {
		// Here we make sure to override any old manoto URLs with the latest.
		url = "https://www.facebook.com/manototv/app_128953167177144"
	} else {
		url = s.StartupUrl
	}
	time.Sleep(4 * time.Second)
	err = open.Run(url)
	if err != nil {
		log.Errorf("Error opening external page to `%v`: %v", uiaddr, err)
	}
}
开发者ID:kidaa,项目名称:lantern,代码行数:34,代码来源:ui.go


示例5: Show

// Show opens the UI in a browser. Note we know the UI server is
// *listening* at this point as long as Start is correctly called prior
// to this method. It may not be reading yet, but since we're the only
// ones reading from those incoming sockets the fact that reading starts
// asynchronously is not a problem.
func Show() {
	go func() {
		err := open.Run(uiaddr)
		if err != nil {
			log.Errorf("Error opening page to `%v`: %v", uiaddr, err)
		}
		if externalUrl != "NO"+"_URL" && !openedExternal {
			time.Sleep(4 * time.Second)
			err = open.Run(externalUrl)
			if err != nil {
				log.Errorf("Error opening external page to `%v`: %v", uiaddr, err)
			}
			openedExternal = true
		}
	}()
}
开发者ID:shizhh,项目名称:lantern,代码行数:21,代码来源:ui.go


示例6: getAccessToken

func getAccessToken(consumerKey, consumerSecret string) (a AccessToken, err error) {
	c := oauth.NewConsumer(
		consumerKey,
		consumerSecret,
		oauth.ServiceProvider{
			RequestTokenUrl:   "https://api.twitter.com/oauth/request_token",
			AuthorizeTokenUrl: "https://api.twitter.com/oauth/authorize",
			AccessTokenUrl:    "https://api.twitter.com/oauth/access_token",
		})

	requestToken, url, err := c.GetRequestTokenAndUrl("oob")
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println("(1) Go to: " + url)
	fmt.Println("(2) Grant access, you should get back a verification code.")
	open.Run(url)
	fmt.Print("(3) Enter that verification code here: ")

	verificationCode := ""
	fmt.Scanln(&verificationCode)

	authToken, err := c.AuthorizeToken(requestToken, verificationCode)
	if err != nil {
		log.Fatal(err)
	}
	a.Token = authToken.Token
	a.Secret = authToken.Secret

	err = saveAccessToken(a)

	return
}
开发者ID:upamune,项目名称:block,代码行数:34,代码来源:oauth.go


示例7: main

func main() {
	err := open.Run(DuckDuckGo + strings.Join(os.Args[1:], Sep))

	if err != nil {
		log.Panic(err)
	}
}
开发者ID:mcandre,项目名称:mcandre,代码行数:7,代码来源:main.go


示例8: readDropBoxAppConfig

func readDropBoxAppConfig(appName string) (*DropBoxAppConfig, error) {
	s := scan.CliScan{
		Scans: []scan.Scan{
			{Name: "token",
				Value: "",
				Usage: "please your dropbox accessToken",
				Env:   "",
			},
		},
	}

	ac := appConfig.NewDefaultAppConfig(appName)
	data, err := ac.ReadAppConfig()
	accessToken := string(data)
	if err != nil || accessToken == "" {

		// OAuth jump
		open.Run(accessTokenURL)

		// Scan accessToken
		accessToken = s.Scan("token")

		// config write
		if err := ac.WriteAppConfig([]byte(accessToken)); err != nil {
			return nil, err
		}
	}

	return &DropBoxAppConfig{*ac}, nil
}
开发者ID:kyokomi,项目名称:quick-image-cli,代码行数:30,代码来源:commands.go


示例9: main

func main() {
	flag.Parse()

	if flag.NArg() != 1 {
		print_usage(os.Args[0])
		os.Exit(1)
	}

	remotes, err := DetectRemote(flag.Arg(0))
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error: %s\n", err.Error())
		os.Exit(1)
	}

	for _, r := range remotes {
		url, err := MangleURL(r.Url)
		if err != nil {
			fmt.Fprintf(os.Stderr, "remote:%s, %s\n", r.Name, err.Error())
			continue
		}

		open.Run(url)
		break
	}
}
开发者ID:hatanakay,项目名称:gh-open,代码行数:25,代码来源:main.go


示例10: runServiceOpen

func (plugin OpenPlugin) runServiceOpen(cliConnection plugin.CliConnection, args []string) {
	output, err := cliConnection.CliCommandWithoutTerminalOutput("service", args[1], "--guid")
	if err != nil {
		fmt.Fprintln(os.Stdout, "error: service does not exist")
		os.Exit(1)
	}
	serviceInstanceGUID := strings.TrimSpace(output[0])

	output, err = cliConnection.CliCommandWithoutTerminalOutput("curl", fmt.Sprintf("/v2/service_instances/%s", serviceInstanceGUID))
	if err != nil {
		fmt.Fprintln(os.Stdout, "error: service does not exist")
		os.Exit(1)
	}
	jsonStr := ""
	for _, line := range output {
		jsonStr += line + "\n"
	}

	response := serviceInstanceResponse{}
	json.Unmarshal([]byte(jsonStr), &response)

	url := response.Entity.DashboardURL
	if url == "" {
		fmt.Println("No dashboard available")
	} else {
		open.Run(url)
	}
}
开发者ID:whitfiea,项目名称:cf-plugin-open,代码行数:28,代码来源:open.go


示例11: init

func init() {
	// Filters is the default set of global filters.
	revel.Filters = []revel.Filter{
		revel.PanicFilter,             // Recover from panics and display an error page instead.
		revel.RouterFilter,            // Use the routing table to select the right Action
		revel.FilterConfiguringFilter, // A hook for adding or removing per-Action filters.
		revel.ParamsFilter,            // Parse parameters into Controller.Params.
		revel.SessionFilter,           // Restore and write the session cookie.
		revel.FlashFilter,             // Restore and write the flash cookie.
		revel.ValidationFilter,        // Restore kept validation errors and save new ones from cookie.
		revel.I18nFilter,              // Resolve the requested language
		HeaderFilter,                  // Add some security based headers
		revel.InterceptorFilter,       // Run interceptors around the action.
		revel.CompressFilter,          // Compress the result.
		revel.ActionInvoker,           // Invoke the action.
	}

	// register startup functions with OnAppStart
	// ( order dependent )
	// revel.OnAppStart(InitDB)
	// revel.OnAppStart(FillCache)
	// Create a link back to node-webkit using the environment variable
	// populated by golang-nw's node-webkit code
	revel.OnAppStart(func() { open.Run("http://localhost:9000") })

}
开发者ID:browning,项目名称:gospider,代码行数:26,代码来源:init.go


示例12: main

func main() {
	var path string

	flag.Parse()

	if flag.NArg() != 1 {
		path = "./"
		// print_usage(os.Args[0])
		// os.Exit(1)
	} else {
		path = flag.Arg(0)
	}

	// remotes, err := DetectRemote(flag.Arg(0))
	remotes, err := DetectRemote(path)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error: %s\n", err.Error())
		os.Exit(1)
	}

	for _, r := range remotes {
		url, err := MangleURL(r.Url)
		if err != nil {
			fmt.Fprintf(os.Stderr, "remote:%s, %s\n", r.Name, err.Error())
			continue
		}

		open.Run(url)
		break
	}
}
开发者ID:theoden9014,项目名称:gh-open,代码行数:31,代码来源:main.go


示例13: main

func main() {
	input := bufio.NewScanner(os.Stdin)

	config := Config{}
	config_source, err := ioutil.ReadFile("config.json")
	if err != nil {
		fmt.Fprintf(os.Stderr, "Can't read config.json: %v\n", err.Error())
		os.Exit(1)
	}
	if err := json.Unmarshal([]byte(config_source), &config); err != nil {
		fmt.Fprintf(os.Stderr, "Can't decode config.json: %v\n", err.Error())
		os.Exit(1)
	}

	if config.ClientId == "" {
		fmt.Fprintf(os.Stderr, "Invalid client_id in config.json\n")
		os.Exit(1)
	}

	open.Run(fmt.Sprintf("https://oauth.vk.com/authorize?client_id=%s&scope=audio"+
		"&redirect_uri=https://oauth.vk.com/blank.html&display=page&response_type=token", config.ClientId))
	fmt.Printf("Enter url from browser window:\n")
	input.Scan()
	oauthResponse := input.Text()
	if access_token, err := parseOauthResponse(oauthResponse); err == nil {
		downloadMusic(access_token)
	} else {
		fmt.Fprintf(os.Stderr, "Error: %v\n", err.Error())
		os.Exit(1)
	}

}
开发者ID:Komly,项目名称:GoMusic,代码行数:32,代码来源:main.go


示例14: openInTatwebui

func (ui *tatui) openInTatwebui() {
	msg := ui.currentListMessages[ui.selectedPaneMessages][ui.uilists[uiMessages][ui.selectedPaneMessages].position]
	base := strings.TrimSpace(viper.GetString("tatwebui-url"))

	if base == "" {
		ui.msg.Text = "You need to set TatWebui URL in your config file, see /set-tatwebui-url"
		ui.render()
		return
	}

	view := "standardview"

	// search view setted on topic parameters
	for _, p := range ui.currentTopic.Parameters {
		if p.Key == "tatwebui.view.restricted" && p.Value != "" {
			view = strings.TrimSpace(strings.Replace(p.Value, "-list", "", 1))
			break
		} else if p.Key == "tatwebui.view.default" && p.Value != "" {
			view = strings.TrimSpace(strings.Replace(p.Value, "-list", "", 1))
		}
	}
	if !strings.HasSuffix(base, "/") {
		view = "/" + view
	}
	url := fmt.Sprintf("%s%s/list%s?idMessage=%s", base, view, ui.currentTopic.Topic, msg.ID)
	open.Run(url)
}
开发者ID:ovh,项目名称:tatcli,代码行数:27,代码来源:events.go


示例15: handle

func handle(conn net.Conn) {
	defer conn.Close()
	log.Printf("Request from %s", conn.RemoteAddr())

	if !firewall.IsAllowed(conn.RemoteAddr()) {
		fmt.Fprintf(conn, "Connect is not allowed from %s", conn.RemoteAddr())
		return
	}

	line, err := bufio.NewReader(conn).ReadString('\000')

	if err != nil {
		log.Println(err)
		conn.Write([]byte(err.Error()))
		return
	}
	body := line[:len(line)-1]

	err = open.Run(string(body))
	if err != nil {
		log.Println(err)
		conn.Write([]byte(err.Error()))
		return
	}
}
开发者ID:pocke,项目名称:remote-open,代码行数:25,代码来源:main.go


示例16: doOpen

func doOpen(c *cli.Context) {
	remote := c.Args().Get(0)
	tree := c.Args().Get(1)

	gitconfig, configErr := NewGitConfig()
	if configErr != nil {
		fmt.Println(configErr)
		return
	}

	if remote == "" {
		result, currentBranchErr := gitconfig.RemoteURLFromCurrentBranch()
		if currentBranchErr != nil {
			fmt.Println(currentBranchErr)
			return
		}
		remote = result
	}

	githubUrl, remoteURLErr := gitconfig.RemoteURL(remote)
	if remoteURLErr != nil {
		fmt.Println(remoteURLErr)
	}

	var openURL string
	if tree != "" {
		openURL = fmt.Sprintf("%s/tree/%s", githubUrl, tree)
	} else {
		openURL = githubUrl
	}
	openErr := open.Run(openURL)
	if openErr != nil {
		fmt.Println(openErr)
	}
}
开发者ID:kaz3439,项目名称:ghrepo,代码行数:35,代码来源:command.go


示例17: main

func main() {
	port := flag.Int("p", 8080, "port to listen on")
	cache := flag.Bool("c", false, "enable caching")
	browser := flag.Bool("b", false, "open browser")

	flag.Parse()

	directory := flag.Arg(0)
	dirPath, err := filepath.Abs(directory)
	if err != nil {
		panic(err)
	}

	address := fmt.Sprintf(":%d", *port)

	ip, err := externalIP()
	if err != nil {
		fmt.Println(err)
		ip = "0.0.0.0"
	}

	url := fmt.Sprintf("http://%s%s", ip, address)
	fmt.Printf("Serving '%s/' on '%s'\n", dirPath, url)
	if *browser {
		open.Run(url)
	}
	// Blocks here
	log.Fatal(ServeDir(dirPath, address, *cache))
}
开发者ID:kaihendry,项目名称:serve,代码行数:29,代码来源:main.go


示例18: main

func main() {

	flag.Parse()

	data := Data{
		"SVG -> PDF",
		time.Now().Format("_2 Jan 2006 15:04:05"),
		20150803,
		"Строка кириллицей",
		true,
	}

	var err error

	// Load template from file
	template, err := template.ParseFiles(*inputFile)
	chk(err)

	// Store template to buffer
	buf := new(bytes.Buffer)
	err = template.Execute(buf, data)
	chk(err)

	// Convert via external application
	// Install before use
	// # apt-get install librsvg2-bin
	// or
	// # apt-get install inkscape
	var cmd *exec.Cmd

	if *converter == "inkscape" {
		fmt.Println("Generate via inkscape")
		cmd = exec.Command("inkscape", "--without-gui", "/dev/stdin", "--export-pdf=/dev/stdout")
		if *outputPng != "" {
			cmd.Args = append(cmd.Args, "--export-png", *outputPng)
		}
	} else {
		fmt.Println("Generate via rsvg-convert")
		cmd = exec.Command("rsvg-convert", "-f", "pdf")
	}
	cmd.Stdin = bytes.NewReader(buf.Bytes())

	// Write pdf to file
	out, err := os.OpenFile(*outputFile, os.O_CREATE|os.O_WRONLY, 0666)
	chk(err)
	defer out.Close()
	cmd.Stdout = out

	timeStart := time.Now().UnixNano()
	err = cmd.Run() // Syncronous run external application
	chk(err)
	timeEnd := time.Now().UnixNano()

	fmt.Println("Conversion time (ms)", (timeEnd-timeStart)/1000000)

	// Open output file using the OS's default application
	open.Run(*outputFile)

}
开发者ID:plumbum,项目名称:go-samples,代码行数:59,代码来源:svgTemplateToPdf.go


示例19: main

func main() {
	cmd := exec.Command("git", "rev-parse", "--abbrev-ref", "HEAD")
	out, e := cmd.Output()
	failOnError(e)

	val := strings.Trim(string(out), "f/#")
	open.Run("https://192.168.100.1/redmine/issues/" + val)
}
开发者ID:zimathon,项目名称:rmhub,代码行数:8,代码来源:seebr.go


示例20: Open

func (u *URI) Open(param *param.OpenParam, _ *struct{}) error {
	conn := <-connCh
	uri := param.URI
	if param.TransLoopback {
		uri = u.translateLoopbackIP(param.URI, conn)
	}
	return open.Run(uri)
}
开发者ID:pocke,项目名称:lemonade,代码行数:8,代码来源:uri.go



注:本文中的github.com/skratchdot/open-golang/open.Run函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang open.Start函数代码示例发布时间:2022-05-28
下一篇:
Golang draw.Canvas类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap