mirror-nourybot/pkg/db/addchannel.go

33 lines
524 B
Go
Raw Normal View History

2021-10-28 15:13:39 +02:00
package db
import (
"context"
"time"
log "github.com/sirupsen/logrus"
)
func AddChannel(channelName string) {
// Interact with data
client := Connect()
2021-10-28 15:22:19 +02:00
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
2021-10-28 15:13:39 +02:00
/*
Get my collection instance
*/
collection := client.Database("nourybot").Collection("channels")
2021-10-28 16:16:11 +02:00
// Channel
chnl := Channel{channelName, true}
2021-10-28 15:13:39 +02:00
res, insertErr := collection.InsertOne(ctx, chnl)
if insertErr != nil {
log.Error(insertErr)
}
log.Info(res)
}