Last active
August 29, 2015 14:10
-
-
Save mackee/7d1e97a0502b39927d66 to your computer and use it in GitHub Desktop.
takashi command
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |
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