Skip to content

Instantly share code, notes, and snippets.

@mackee
Last active August 29, 2015 14:10
Show Gist options
  • Save mackee/7d1e97a0502b39927d66 to your computer and use it in GitHub Desktop.
Save mackee/7d1e97a0502b39927d66 to your computer and use it in GitHub Desktop.
takashi command
package main
import (
"fmt"
"github.com/codegangsta/cli"
"log"
"net/http"
"os"
"time"
)
const endpoint = "http://takashicompany.com/api/im/?message=%s"
var Commands = []cli.Command{
commandSend,
}
var commandSend = cli.Command{
Name: "send",
Usage: "send message to takashi",
Description: `
たかしにメッセージを送るコマンド
`,
Action: doSend,
Flags: []cli.Flag{
cli.DurationFlag{
Name: "after",
Usage: "指定時間sleepした後に送信 数字にs/m/hなどつける",
Value: 0,
},
},
}
func debug(v ...interface{}) {
if os.Getenv("DEBUG") != "" {
log.Println(v...)
}
}
func assert(err error) {
if err != nil {
log.Fatal(err)
}
}
func doSend(c *cli.Context) {
after := c.Duration("after")
message := c.Args().First()
sendAfterSleep(after, message)
}
func sendAfterSleep(d time.Duration, m string) {
time.Sleep(d)
_, err := http.Get(fmt.Sprintf(endpoint, m))
if err != nil {
log.Fatalf("send error: %s", err)
}
}
This file has been truncated, but you can view the full file.
View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment