本文整理汇总了Golang中github.com/skratchdot/open-golang/open.Start函数的典型用法代码示例。如果您正苦于以下问题:Golang Start函数的具体用法?Golang Start怎么用?Golang Start使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Start函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
usr, err := user.Current()
if err != nil {
log.Fatal(err)
}
cache := filepath.Join(usr.HomeDir, ".ak", "news")
flag.Parse()
if flag.NArg() > 0 {
idx, e := strconv.ParseInt(flag.Arg(0), 0, 0)
if e != nil {
// not int
}
item := getItem(cache, idx)
if comment {
open.Start(fmt.Sprintf("%s%s%d", HACKERWEB, "/#/item/", item.ID))
} else {
open.Start(item.URL)
}
} else {
if next {
var news []Item
res, err := http.Get(NEWS2)
if err != nil {
log.Fatal(err)
}
bytes, err := ioutil.ReadAll(res.Body)
if err != nil {
log.Fatal(err)
}
res.Body.Close()
populateCache(cache, bytes)
contents := string(bytes)
err = json.NewDecoder(strings.NewReader(contents)).Decode(&news)
if err != nil {
log.Fatal(err)
}
showNewsList(news)
} else {
var news []Item
res, err := http.Get(NEWS)
if err != nil {
log.Fatal(err)
}
bytes, err := ioutil.ReadAll(res.Body)
if err != nil {
log.Fatal(err)
}
res.Body.Close()
populateCache(cache, bytes)
contents := string(bytes)
err = json.NewDecoder(strings.NewReader(contents)).Decode(&news)
showNewsList(news)
}
}
}
示例2: main
// Our programs starts executing here
func main() {
// We need exactly 2 parameters: the first one is the program name,
// the second one should be the photo we want to operate on
if len(os.Args) != 2 {
fmt.Println("Please give a single file name as an argument!")
os.Exit(1)
}
// Retrieve the photo file name from the arguments array
fileName := os.Args[1]
// Try to opern the given file, error out on failure
file, err := os.Open(fileName)
exitOnError(err, "Couldn't open file")
// Try to extract the EXIF data, error out on failure
exifData, err := exif.Decode(file)
exitOnError(err, "Couldn't find EXIF data")
// Try to find a GPS coordinates entry in the EXIF data structure.
// Error out on failure
lat, long, err := exifData.LatLong()
exitOnError(err, "Couldn't read GPS coordinates")
// Create the final URL by using the Google Maps URL template
url := fmt.Sprintf(googleMapsURLTemplate, lat, long)
// Try to start the default browser for the current OS.
// Show the computer URL on error, so that the user can still
// access it manually
err = open.Start(url)
exitOnError(err, fmt.Sprintf(
"Couldn't start the default browser, please visit %v manually", url))
}
示例3: QR
func (g *Commands) QR(byId bool) error {
kvChan := g.urler(byId, g.opts.Sources)
address := DefaultQRShareServer
if g.opts.Meta != nil {
meta := *(g.opts.Meta)
if retrAddress, ok := meta[AddressKey]; ok && len(retrAddress) >= 1 {
address = retrAddress[0]
}
}
address = strings.TrimRight(address, "/")
if envKeySet.PublicKey == "" {
envKeySet.PublicKey = "5160897b3586461e83e7279c10352ac4"
}
if envKeySet.PrivateKey == "" {
envKeySet.PrivateKey = "5a3451dadab74f75b16f754c0a931949"
}
for kv := range kvChan {
switch kv.value.(type) {
case error:
g.log.LogErrf("%s: %s\n", kv.key, kv.value)
continue
}
fileURI, ok := kv.value.(string)
if !ok {
continue
}
curTime := time.Now()
pl := meddler.Payload{
URI: fileURI,
RequestTime: curTime.Unix(),
Payload: fmt.Sprintf("%v%v", rand.Float64(), curTime),
PublicKey: envKeySet.PublicKey,
ExpiryTime: curTime.Add(time.Hour).Unix(),
}
plainTextToSign := pl.RawTextForSigning()
pl.Signature = fmt.Sprintf("%s", envKeySet.Sign([]byte(plainTextToSign)))
uv := pl.ToUrlValues()
encodedValues := uv.Encode()
fullUrl := fmt.Sprintf("%s/qr?%s", address, encodedValues)
if g.opts.Verbose {
g.log.Logf("%q => %q\n", kv.key, fullUrl)
}
if err := open.Start(fullUrl); err != nil {
g.log.Logf("qr: err %v %q\n", err, fullUrl)
}
}
return nil
}
示例4: showQRImage
func showQRImage(uuid string) (err error) {
qrUrl := `https://login.weixin.qq.com/qrcode/` + uuid
params := url.Values{}
params.Set("t", "webwx")
params.Set("_", strconv.FormatInt(time.Now().Unix(), 10))
req, err := http.NewRequest("POST", qrUrl, strings.NewReader(params.Encode()))
if err != nil {
return
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.Header.Set("Cache-Control", "no-cache")
resp, err := Client.Do(req)
if err != nil {
return
}
defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
return
}
if err = createFile(QRImagePath, data, false); err != nil {
return
}
return open.Start(QRImagePath)
}
示例5: Open
func (g *Commands) Open(ot OpenType) error {
byId := (ot & IdOpen) != 0
kvChan := g.urler(byId)
for kv := range kvChan {
switch kv.value.(type) {
case error:
g.log.LogErrf("%s: %s\n", kv.key, kv.value)
continue
}
openArgs := []string{}
canAddUrl := (ot & BrowserOpen) != 0
if byId {
canAddUrl = true
} else if (ot & FileManagerOpen) != 0 {
openArgs = append(openArgs, g.context.AbsPathOf(kv.key))
}
if canAddUrl {
if castKey, ok := kv.value.(string); ok {
openArgs = append(openArgs, castKey)
}
}
for _, arg := range openArgs {
open.Start(arg)
}
}
return nil
}
示例6: run
func run(dir, port, host string) {
open.Start(host)
fmt.Println("-> Listening on ", host)
fmt.Println("-> Press ctrl-c to kill process")
http.CloseIdleConnections()
log.Fatal(http.ListenAndServe(port, http.FileServer(http.Dir(dir))))
}
示例7: setupSysTrayReal
func setupSysTrayReal() {
systray.SetIcon(icon.Data)
mUrl := systray.AddMenuItem("Go to Arduino Create (staging)", "Arduino Create")
mDebug := systray.AddMenuItem("Open debug console", "Debug console")
menuVer := systray.AddMenuItem("Agent version "+version+"-"+git_revision, "")
mPause := systray.AddMenuItem("Pause Plugin", "")
//mQuit := systray.AddMenuItem("Quit Plugin", "")
menuVer.Disable()
go func() {
<-mPause.ClickedCh
ports, _ := serial.GetPortsList()
for _, element := range ports {
spClose(element)
}
systray.Quit()
*hibernate = true
log.Println("Restart becayse setup went wrong?")
restart("")
}()
// go func() {
// <-mQuit.ClickedCh
// systray.Quit()
// exit()
// }()
go func() {
for {
<-mDebug.ClickedCh
logAction("log on")
open.Start("http://localhost" + port)
}
}()
// We can manipulate the systray in other goroutines
go func() {
for {
<-mUrl.ClickedCh
open.Start("http://create-staging.arduino.cc")
}
}()
}
示例8: main
func main() {
nc, _ := nats.Connect("nats://yourhost:4222")
defer nc.Close()
nc.QueueSubscribe(TOPIC, QUEUE, func(m *nats.Msg) {
fmt.Println(string(m.Data))
open.Start(string(m.Data))
})
select {}
}
示例9: main
func main() {
flag.Parse()
url := template.URLQueryEscaper(flag.Args())
url = fmt.Sprintf("http://52.68.184.19:8080/search/%s", url)
fmt.Printf("open %s\n", url)
open.Start(url)
}
示例10: webui
func webui() {
goji.Get("/", index)
goji.Get("/result/diff.txt", generateResult)
goji.Post("/diff", PostDiff)
//Fully backwards compatible with net/http's Handlers
//goji.Get("/result", http.RedirectHandler("/", 301))
if os.Getenv("DEBUG") == "" {
time.AfterFunc(500*time.Millisecond, func() {
open.Start("http://localhost:8000")
})
}
goji.Serve()
}
示例11: docPlugin
func docPlugin(c *cli.Context) {
if len(c.Args()) != 1 {
fmt.Printf("Which documentation do you want to open? Try 'apiplexy plugin-doc <plugin-name>'.\n")
os.Exit(1)
}
plugin, ok := apiplexy.AvailablePlugins()[c.Args()[0]]
if !ok {
fmt.Printf("Plugin '%s' not found. Try 'apiplexy plugins' to list available ones.\n", c.Args()[0])
os.Exit(1)
}
fmt.Printf("Opening documentation for '%s' at: %s\n", plugin.Name, plugin.Link)
open.Start(plugin.Link)
}
示例12: doOpen
func doOpen(flags *flag.FlagSet) {
args := flags.Args()
branch, err := getBranchFromArgs(args)
checkError(err)
remote, err := git.GetRemoteURL("origin")
checkError(err)
cr, err := circle.GetTree(remote.Path, remote.RepoName, branch)
checkError(err)
if len(*cr) == 0 {
fmt.Printf("No results, are you sure there are tests for %s/%s?\n",
remote.Path, remote.RepoName)
return
}
latestBuild := (*cr)[0]
open.Start(latestBuild.BuildURL)
}
示例13: main
func main() {
title := flag.String("title", "", "Optional Title")
script := flag.String("script", "", "lua script to filter/enrich data")
laddr := flag.String("addr", "", "Address on which to serve up the map")
flag.Usage = func() {
fmt.Fprintln(os.Stderr, usage)
flag.PrintDefaults()
}
flag.Parse()
if *script != "" {
if _, err := os.Stat(*script); os.IsNotExist(err) {
log.Fatal(err)
}
}
http.HandleFunc("/gidata", handleGIData)
http.Handle("/resources/", http.FileServer(rice.MustFindBox("public").HTTPBox()))
http.HandleFunc("/", serveIndex(*title))
/* Get the address from the command line or the environment */
address := *laddr
if "" == address {
address = os.Getenv("GIM_ADDR")
}
/* Failing that, use an ephemeral port on loopback */
if "" == address {
address = "127.0.0.1:0"
}
/* If it's a single port, prepend a localhost */
if _, err := strconv.Atoi(address); nil == err {
address = "127.0.0.1:" + address
}
go readStdin(*script)
l, err := net.Listen("tcp", address)
if err != nil {
log.Fatal(err)
}
go func() {
addr := fmt.Sprintf("http://%s", l.Addr())
log.Printf("Listening on %v\n", addr)
open.Start(addr)
}()
log.Fatal(http.Serve(l, nil))
}
示例14: execCmd
func execCmd(c *cli.Context) {
if len(c.Args()) < 1 {
fmt.Println("Specify Markdown file")
return
}
/* open webbrowser */
open.Start("http://0.0.0.0:8089")
ch := make(chan string)
gChan = make(chan string)
targetFileName = c.Args()[0]
go fileWatcher(ch)
/* for static files */
staticFilePath := path.Join(os.Getenv("GOPATH"), "src/github.com/hhatto/ftcat/static")
fs := http.FileServer(http.Dir(staticFilePath))
http.Handle("/static/", http.StripPrefix("/static/", fs))
/* index */
http.HandleFunc("/", indexHandler)
/* server sent events */
es := eventsource.New(nil, nil)
defer es.Close()
http.Handle("/events", es)
/* message broker */
go func() {
id := 1
for {
select {
case n := <-ch:
es.SendEventMessage(n, "cre", strconv.Itoa(id))
id++
case n := <-gChan:
es.SendEventMessage(n, "cre", strconv.Itoa(id))
id++
}
}
}()
log.Fatal(http.ListenAndServe(":8089", nil))
}
示例15: DoOpen
func DoOpen(c *cli.Context) {
useOptions(c)
dest := c.Args().First()
log.Debugf("Open destination: %s", dest)
url := ""
message := ""
switch dest {
default:
fallthrough
case "deployed":
app, err := account.GetCurrentApp()
if err != nil {
message = "Sorry, could not find a deployed app to open."
}
url = "http://" + app.HostingSubdomain + ".appstax.io"
break
case "admin":
url = "http://appstax.com/admin/#/dashboard"
break
case "local":
url = "http://localhost:9000/"
break
}
if url != "" {
term.Printf("Opening %s in your browser.\n", url)
err := open.Start(url)
if err != nil {
message = "Ooops! Something went wrong."
}
}
if message != "" {
term.Section()
term.Println(message)
}
}