func main() { rand.Seed(time.Now().UnixNano()) cards, err := mtgprice.Open(mtgprice.Opts{Filename: "mtgprice.kv", CardData: "AllCards.json"}) if err != nil { log.Fatal("loading cards:", err) } closeOnTerm(cards) bot, err := telebot.NewBot(os.Getenv("TOKEN")) if err != nil { log.Fatal(err) } messages := make(chan telebot.Message) bot.Listen(messages, 1*time.Minute) for msg := range messages { if err := handleMessage(cards, bot, msg); err != nil { log.Printf("Error handling message %v: %v", msg, err) } } }
func main() { staticDir, err := staticDir() if err != nil { log.Fatalf("could not find static dir") } c, err := mtgprice.Open(mtgprice.Opts{ Filename: "mtgprice.db", CardData: filepath.Join(staticDir, "AllCards.json"), }) if err != nil { log.Fatalf("could not open db: %v", err) } client = c handleInterrupt() http.Handle("/", serveFile(filepath.Join(staticDir, "index.html"))) http.Handle("/static", http.StripPrefix("static", http.FileServer(http.Dir(staticDir)))) http.HandleFunc("/api/price", priceHandler) http.HandleFunc("/api/info", infoHandler) log.Fatal(http.ListenAndServe(":8080", nil)) }