upd
This commit is contained in:
parent
09439ce697
commit
a465276246
4
bot.go
4
bot.go
|
@ -1,10 +1,10 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"time"
|
||||
"log"
|
||||
"fmt"
|
||||
tb "gopkg.in/tucnak/telebot.v2"
|
||||
"log"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
8
main.go
8
main.go
|
@ -1,14 +1,14 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"time"
|
||||
"log"
|
||||
"database/sql"
|
||||
"flag"
|
||||
"fmt"
|
||||
"database/sql"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"gopkg.in/gcfg.v1"
|
||||
tb "gopkg.in/tucnak/telebot.v2"
|
||||
"log"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
|
@ -81,7 +81,7 @@ func main() {
|
|||
log.Println("SQL connection initialized")
|
||||
}
|
||||
|
||||
if (*initdb) {
|
||||
if *initdb {
|
||||
initDB()
|
||||
}
|
||||
|
||||
|
|
49
mq.go
Normal file
49
mq.go
Normal file
|
@ -0,0 +1,49 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/streadway/amqp"
|
||||
)
|
||||
|
||||
func MQMainReceive() {
|
||||
conn, err := amqp.Dial("amqp://shoopea:UmDd5g4WRa2MzqOHsG2T@localhost:5672/chatwars")
|
||||
failOnError(err, "MQMainReceive : Failed to connect to RabbitMQ")
|
||||
defer conn.Close()
|
||||
|
||||
ch, err := conn.Channel()
|
||||
failOnError(err, "MQMainReceive : Failed to open a channel")
|
||||
defer ch.Close()
|
||||
|
||||
q, err := ch.QueueDeclare(
|
||||
"msg", // name
|
||||
false, // durable
|
||||
false, // delete when unused
|
||||
false, // exclusive
|
||||
false, // no-wait
|
||||
nil, // arguments
|
||||
)
|
||||
failOnError(err, "MQMainReceive : Failed to declare a queue")
|
||||
|
||||
msgs, err := ch.Consume(
|
||||
q.Name, // queue
|
||||
"", // consumer
|
||||
true, // auto-ack
|
||||
false, // exclusive
|
||||
false, // no-local
|
||||
false, // no-wait
|
||||
nil, // args
|
||||
)
|
||||
failOnError(err, "MQMainReceive : Failed to register a consumer")
|
||||
|
||||
forever := make(chan bool)
|
||||
|
||||
go func() {
|
||||
for d := range msgs {
|
||||
log.Printf("MQMainReceive : Received a message: %s", d.Body)
|
||||
}
|
||||
}()
|
||||
|
||||
<-forever
|
||||
|
||||
}
|
3
sql.go
3
sql.go
|
@ -2,10 +2,8 @@ package main
|
|||
|
||||
import (
|
||||
"log"
|
||||
|
||||
)
|
||||
|
||||
|
||||
func initDB() {
|
||||
log.Println("Setting up database...")
|
||||
|
||||
|
@ -79,4 +77,3 @@ func initDB() {
|
|||
|
||||
log.Println("Database set up")
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user