This package divided into three different packages which includes Telegram, Slack and Discord. Let's begin with Discord
To use discord you need to initial it first, like:
import (
"fmt"
"git.coryptex.com/sdk/discord-go/dicord"
)
discordLogger, _ := dicord.NewDiscordLogger(&dicord.Config{
Webhooks: []string{
"https://discord.com/api/webhooks/you_webhook",
},
Title: "Oauth server",
})
if err != nil {
fmt.Println("Error: ", err)
}
err := discordLogger.Info("key 1", "val 1")
if err != nil {
fmt.Println("Error: ", err)
}
Your message sent! :)
The discordLogger
variable contains all the methods you need to call to send your message to the discord channel. The following methods are:
discordLogger.Info("key 1", "val 1", "key 2", "val 2")
discordLogger.Debug("key 1", "val 1", "key 2", "val 2")
discordLogger.Warn("key 1", "val 1", "key 2", "val 2")
discordLogger.Error("key 1", "val 1", "key 2", "val 2")
discordLogger.Fatal("key 1", "val 1", "key 2", "val 2")
discordLogger.Trace("key 1", "val 1", "key 2", "val 2")
discordLogger.Panic("key 1", "val 1", "key 2", "val 2")
Note: You have to pass key and value after another. In some cases if you didn't pass the value of a key the value will be an empty string.
If you want to set a custom color you can pass a key named color
and the value must be a color number, like: 99999
which is blue
err := discordLogger.Info("key 1", "val 1", "key 2", "val 2", "color", "99999")
if err != nil {
fmt.Println("Error: ", err)
}
Simply as above code! you just need to pass description
as key and pass the value:
err := discordLogger.Info("key 1", "val 1", "key 2", "val 2", "color", "99999", "description", "This is a description")
if err != nil {
fmt.Println("Error: ", err)
}
Have fun!