diff --git a/docker.go b/docker.go
index 4789364..f1c4a7e 100644
--- a/docker.go
+++ b/docker.go
@@ -12,7 +12,7 @@ import (
"github.com/rs/zerolog/log"
)
-// Docker represents a docker client
+// Docker represents a docker client.
type Docker struct {
cli *client.Client
ctx context.Context
@@ -81,8 +81,8 @@ func (d *Docker) inspect(containerID string) (*types.ContainerJSON, error) {
func (d *Docker) logs(containerID string, tail string) ([]string, error) {
var (
- bytes []byte = make([]byte, 3000) // Telegram message length limit
- logs []string = nil
+ bytes = make([]byte, 3000) // Telegram message length limit
+ logs []string
)
if tail != "all" && !isNumber(tail) {
tail = "10"
diff --git a/handlers.go b/handlers.go
index ca56e81..7109620 100644
--- a/handlers.go
+++ b/handlers.go
@@ -22,9 +22,9 @@ var state = map[string]emoji.Emoji{
"dead": emoji.Skull,
}
-const FORMATED_STR = "%v
"
+const FormatedStr = "%v
"
-// handleStart triggers when /start is sent on private
+// handleStart triggers when /start is sent on private.
func (t *Telegram) handleStart(m *tb.Message) {
if !m.Private() {
return
@@ -33,7 +33,7 @@ func (t *Telegram) handleStart(m *tb.Message) {
t.send(m.Chat, "Telegram bot made by MrMarble")
}
-// handleList triggers when the ps command is sent
+// handleList triggers when the ps command is sent.
func (t *Telegram) handleList(m *tb.Message) {
if !t.isSuperAdmin(m.Sender) {
return
@@ -42,7 +42,7 @@ func (t *Telegram) handleList(m *tb.Message) {
t.send(m.Chat, strings.Join(resultMsg, "\n\n"))
}
-// handleList triggers when the psa command is sent
+// handleList triggers when the psa command is sent.
func (t *Telegram) handleListAll(m *tb.Message) {
if !t.isSuperAdmin(m.Sender) {
return
@@ -117,9 +117,9 @@ func (t *Telegram) handleInspect(m *tb.Message) {
}
for index, chunk := range chunkString(response, 3000) {
if index == 0 {
- t.reply(m, fmt.Sprintf(FORMATED_STR, chunk), tb.ModeHTML)
+ t.reply(m, fmt.Sprintf(FormatedStr, chunk), tb.ModeHTML)
} else {
- t.send(m.Chat, fmt.Sprintf(FORMATED_STR, chunk), tb.ModeHTML)
+ t.send(m.Chat, fmt.Sprintf(FormatedStr, chunk), tb.ModeHTML)
}
time.Sleep(100 * time.Millisecond)
}
@@ -143,7 +143,7 @@ func (t *Telegram) handleLogs(m *tb.Message) {
if containerID == "" || !docker.isValidID(containerID) {
t.askForContainer(m, types.ContainerListOptions{All: true}, "logs")
} else {
- var tail string = "10"
+ tail := "10"
if len(payload) > 1 {
tail = payload[1]
}
@@ -155,9 +155,9 @@ func (t *Telegram) handleLogs(m *tb.Message) {
}
for index, chunk := range logs {
if index == 0 {
- t.reply(m, fmt.Sprintf(FORMATED_STR, chunk), tb.ModeHTML)
+ t.reply(m, fmt.Sprintf(FormatedStr, chunk), tb.ModeHTML)
} else {
- t.send(m.Chat, fmt.Sprintf(FORMATED_STR, chunk), tb.ModeHTML)
+ t.send(m.Chat, fmt.Sprintf(FormatedStr, chunk), tb.ModeHTML)
}
time.Sleep(100 * time.Millisecond)
}
diff --git a/main.go b/main.go
index 3c60449..260e245 100644
--- a/main.go
+++ b/main.go
@@ -10,9 +10,9 @@ import (
)
var (
- bot *Telegram = nil
- superAdmins []int64 = []int64{}
- docker *Docker = nil
+ bot *Telegram
+ superAdmins = []int64{}
+ docker *Docker
)
func main() {
diff --git a/telegram.go b/telegram.go
index 9889d0c..e3c8fd5 100644
--- a/telegram.go
+++ b/telegram.go
@@ -9,13 +9,13 @@ import (
"github.com/rs/zerolog/log"
)
-// Telegram represents the telegram bot
+// Telegram represents the telegram bot.
type Telegram struct {
bot *tb.Bot
handlersRegistered bool
}
-// Command represent a telegram command
+// Command represent a telegram command.
type Command struct {
Cmd string
Aliases []string
@@ -23,7 +23,7 @@ type Command struct {
Handler interface{}
}
-// NewBot returns a Telegram bot
+// NewBot returns a Telegram bot.
func NewBot(token string) (*Telegram, error) {
bot, err := tb.NewBot(tb.Settings{
Token: token,
@@ -42,7 +42,7 @@ func NewBot(token string) (*Telegram, error) {
return &Telegram{bot: bot}, nil
}
-// Start starts polling for telegram updates
+// Start starts polling for telegram updates.
func (t *Telegram) Start() {
t.registerHandlers()
@@ -50,7 +50,7 @@ func (t *Telegram) Start() {
t.bot.Start()
}
-// RegisterHandlers registers all the handlers
+// RegisterHandlers registers all the handlers.
func (t *Telegram) registerHandlers() {
if t.handlersRegistered {
return
@@ -142,7 +142,7 @@ func (t *Telegram) isSuperAdmin(user *tb.User) bool {
return false
}
-// send sends a message with error logging and retries
+// send sends a message with error logging and retries.
func (t *Telegram) send(to tb.Recipient, what interface{}, options ...interface{}) *tb.Message {
hasParseMode := false
for _, opt := range options {
@@ -175,7 +175,7 @@ func (t *Telegram) send(to tb.Recipient, what interface{}, options ...interface{
}
}
-// reply replies a message with error logging and retries
+// reply replies a message with error logging and retries.
func (t *Telegram) reply(to *tb.Message, what interface{}, options ...interface{}) *tb.Message {
hasParseMode := false
for _, opt := range options {
diff --git a/utils.go b/utils.go
index 0a029c7..53624cd 100644
--- a/utils.go
+++ b/utils.go
@@ -15,10 +15,10 @@ import (
tb "gopkg.in/tucnak/telebot.v2"
)
-const COMPOSE_LABEL = "com.docker.compose.project"
-const FORMATED_STR_PADDED = " %-8v
%v
"
+const ComposeLabel = "com.docker.compose.project"
+const FormatedStrPadded = " %-8v
%v
"
-// parseInt64 parses a string and converts it to int64
+// parseInt64 parses a string and converts it to int64.
func parseInt64(s string) (int64, error) {
i, err := strconv.ParseInt(s, 10, 64)
@@ -43,12 +43,12 @@ func parseList(options types.ContainerListOptions) []string {
for _, container := range containers {
message := []string{
fmt.Sprintf("%v %v", state[container.State], container.Names[0][1:]),
- fmt.Sprintf(FORMATED_STR_PADDED, "ID:", container.ID[:12]),
- fmt.Sprintf(FORMATED_STR_PADDED, "STATUS:", container.Status),
- fmt.Sprintf(FORMATED_STR_PADDED, "IMAGE:", container.Image),
+ fmt.Sprintf(FormatedStrPadded, "ID:", container.ID[:12]),
+ fmt.Sprintf(FormatedStrPadded, "STATUS:", container.Status),
+ fmt.Sprintf(FormatedStrPadded, "IMAGE:", container.Image),
}
- if stack, ok := container.Labels[COMPOSE_LABEL]; ok {
- message = append(message, fmt.Sprintf(FORMATED_STR_PADDED, "STACK:", stack))
+ if stack, ok := container.Labels[ComposeLabel]; ok {
+ message = append(message, fmt.Sprintf(FormatedStrPadded, "STACK:", stack))
}
resultMsg = append(resultMsg, strings.Join(message, "\n"))
}
@@ -72,10 +72,10 @@ func getStacks() map[string][]types.Container {
filters = filters.NewArgs()
stacks = map[string][]types.Container{}
)
- filters.Add("label", COMPOSE_LABEL)
+ filters.Add("label", ComposeLabel)
containers := docker.list(types.ContainerListOptions{All: true, Filters: filters})
for _, container := range containers {
- stacks[container.Labels[COMPOSE_LABEL]] = append(stacks[container.Labels[COMPOSE_LABEL]], container)
+ stacks[container.Labels[ComposeLabel]] = append(stacks[container.Labels[ComposeLabel]], container)
}
return stacks
}
@@ -89,7 +89,7 @@ func parseStacks() []string {
for stackName, stack := range stacks {
resultMsg = append(resultMsg, strings.Join([]string{
fmt.Sprintf("%v", stackName),
- fmt.Sprintf(FORMATED_STR_PADDED, "SERVICES:", len(stack)),
+ fmt.Sprintf(FormatedStrPadded, "SERVICES:", len(stack)),
}, "\n"))
}
return resultMsg
@@ -185,9 +185,9 @@ func handleInspect(t *Telegram, c *tb.Callback, payload string) {
}
for index, chunk := range chunkString(response, 3000) {
if index == 0 {
- callbackResponse(t, c, err, payload, fmt.Sprintf(FORMATED_STR, chunk))
+ callbackResponse(t, c, err, payload, fmt.Sprintf(FormatedStr, chunk))
} else {
- t.send(c.Message.Chat, fmt.Sprintf(FORMATED_STR, chunk), tb.ModeHTML)
+ t.send(c.Message.Chat, fmt.Sprintf(FormatedStr, chunk), tb.ModeHTML)
}
time.Sleep(250 * time.Millisecond)
}
@@ -201,10 +201,10 @@ func handleLog(t *Telegram, c *tb.Callback, payload string) {
}
for index, chunk := range logs {
if index == 0 {
- callbackResponse(t, c, err, payload, fmt.Sprintf(FORMATED_STR, chunk))
+ callbackResponse(t, c, err, payload, fmt.Sprintf(FormatedStr, chunk))
}
if index != 0 && chunk != "" {
- t.send(c.Message.Chat, fmt.Sprintf(FORMATED_STR, chunk), tb.ModeHTML)
+ t.send(c.Message.Chat, fmt.Sprintf(FormatedStr, chunk), tb.ModeHTML)
}
time.Sleep(100 * time.Millisecond)
}