add hot-reload & debugger
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Pavel 2024-05-13 16:57:55 +03:00
parent 1c37735dea
commit 2cd46585a8
11 changed files with 58 additions and 17 deletions

10
.air.toml Normal file
View File

@ -0,0 +1,10 @@
root = "."
[build]
exclude_regex = ["_test\\.go"]
bin = "/usr/bin/make debug"
cmd = "/usr/bin/make build"
kill_delay = 0
log = "build-errors.log"
send_interrupt = true
stop_on_error = true

View File

@ -19,3 +19,5 @@ steps:
trigger: trigger:
event: event:
- push - push
branch:
- master

2
.gitignore vendored
View File

@ -22,6 +22,8 @@ vendor/
# Go workspace file # Go workspace file
go.work go.work
.idea/ .idea/
.config/
tmp/
# Env files # Env files
.env .env

View File

@ -2,20 +2,37 @@ SHELL = /bin/bash -o pipefail
export PATH := $(shell go env GOPATH)/bin:$(PATH) export PATH := $(shell go env GOPATH)/bin:$(PATH)
ROOT_DIR=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) ROOT_DIR=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
BIN=$(ROOT_DIR)/build/vegapokerbot BIN_NAME=vegapokerbot
BIN=$(ROOT_DIR)/build/$(BIN_NAME)
GO_VERSION=$(shell go version | sed -e 's/go version //') GO_VERSION=$(shell go version | sed -e 's/go version //')
BIN_DIR=$(ROOT_DIR)/build BIN_DIR=$(ROOT_DIR)/build
build: deps fmt build: deps fmt
@echo "> building with ${GO_VERSION}" ifeq ($(DEBUG), true)
@echo "> building debug with ${GO_VERSION}"
@CGO_ENABLED=0 go build -buildvcs=false -gcflags "all=-N -l" -tags=release -o $(BIN) .
else
@echo "> building release with ${GO_VERSION}"
@CGO_ENABLED=0 go build -buildvcs=false -tags=release -o $(BIN) . @CGO_ENABLED=0 go build -buildvcs=false -tags=release -o $(BIN) .
endif
@echo $(BIN) @echo $(BIN)
docker: docker:
@docker buildx build --platform linux/amd64 --tag $CI_APP_IMAGE --file Dockerfile . @docker buildx build --platform linux/amd64 --tag $CI_APP_IMAGE --file Dockerfile .
run: run:
ifeq ($(DEBUG), true)
@killall -s 9 dlv > /dev/null 2>&1 || true
@killall -s 9 ${BIN_NAME} > /dev/null 2>&1 || true
@air
else
@${BIN} run @${BIN} run
endif
debug:
@echo "> starting under delve"
@dlv --listen=:40000 --headless=true --api-version=2 --accept-multiclient --log exec ${BIN} run
fmt: fmt:
@echo "> fmt" @echo "> fmt"
@gofmt -l -s -w `go list -buildvcs=false -f '{{.Dir}}' ${ROOT_DIR}/... | grep -v /vendor/` @gofmt -l -s -w `go list -buildvcs=false -f '{{.Dir}}' ${ROOT_DIR}/... | grep -v /vendor/`

View File

@ -1,29 +1,23 @@
services: services:
db: db:
image: postgres:latest image: postgres:latest
restart: always
environment: environment:
POSTGRES_USER: app POSTGRES_USER: app
POSTGRES_PASSWORD: app POSTGRES_PASSWORD: app
POSTGRES_DATABASE: app POSTGRES_DATABASE: app
networks:
- default
app: app:
image: "gitea.neur0tx.site/neur0toxine/vegapokerbot:latest" image: "gitea.neur0tx.site/neur0toxine/vegapokerbot:latest"
networks:
- default
links: links:
- db - db
env_file: env_file:
- .env - .env
restart: always
labels: labels:
traefik.enable: "true" traefik.enable: "true"
traefik.http.routers.vegapokerbot.rule: Host(`vegapokerbot.neur0tx.site`) && PathPrefix(`/webhook8c31c4b2d65a87b4f3a6f10f8eb166fba9a2e5dc7696bc5291a7e69641dc5c21`) traefik.http.routers.vegapokerbot.rule: Host(`vegapokerbot.example.com`) && PathPrefix(`/webhook`)
traefik.http.routers.vegapokerbot.entrypoints: websecure traefik.http.routers.vegapokerbot.entrypoints: websecure
traefik.http.services.vegapokerbot.loadbalancer.server.port: "3333" traefik.http.services.vegapokerbot.loadbalancer.server.port: "3333"
traefik.http.routers.vegapokerbot.tls: true traefik.http.routers.vegapokerbot.tls: true
traefik.http.routers.vegapokerbot.tls.certresolver: letsencrypt traefik.http.routers.vegapokerbot.tls.certresolver: letsencrypt
networks:
default:
driver: bridge

View File

@ -22,8 +22,10 @@ services:
- db - db
environment: environment:
GOCACHE: /go GOCACHE: /go
DEBUG: true # Set to false to disable hot-reload & debugger.
ports: ports:
- 3333:3333 - 3333:3333
- 40000:40000
command: make build run command: make build run
networks: networks:

View File

@ -30,10 +30,6 @@ func (h *MessageHandler) Handle(wh telego.Update) error {
return group.NewPoll(h.App, wh.Message.From.ID, wh.Message.Chat.ID).Handle(wh) return group.NewPoll(h.App, wh.Message.From.ID, wh.Message.Chat.ID).Handle(wh)
} }
if util.MatchCommand("start", wh.Message) {
return wizard.NewRegister(h.App, wh.Message.From.ID, wh.Message.Chat.ID).Handle(wh)
}
setup, found := store.RedmineSetups.Get(wh.Message.Chat.ID) setup, found := store.RedmineSetups.Get(wh.Message.Chat.ID)
if found { if found {
return wizard.NewRedmineSetup(h.App, wh.Message.From.ID, wh.Message.Chat.ID, setup).Handle(wh) return wizard.NewRedmineSetup(h.App, wh.Message.From.ID, wh.Message.Chat.ID, setup).Handle(wh)

View File

@ -8,3 +8,10 @@ import (
func MatchCommand(command string, msg *telego.Message) bool { func MatchCommand(command string, msg *telego.Message) bool {
return th.CommandEqual(command)(telego.Update{Message: msg}) return th.CommandEqual(command)(telego.Update{Message: msg})
} }
func HasCommand(msg *telego.Message) bool {
if msg == nil {
return false
}
return th.CommandRegexp.MatchString(msg.Text)
}

View File

@ -0,0 +1,2 @@
// Package wizard contains setup wizard implementation.
package wizard

View File

@ -32,7 +32,7 @@ func init() {
} }
for _, tag := range tags { for _, tag := range tags {
localizers[tag.String()] = &localizer{loc: i18n.NewLocalizer(bundle, tag.String())} localizers[tag.String()] = &localizer{loc: i18n.NewLocalizer(bundle, tag.String()), tag: tag}
} }
} }

View File

@ -1,14 +1,19 @@
package locale package locale
import "github.com/nicksnyder/go-i18n/v2/i18n" import (
"github.com/nicksnyder/go-i18n/v2/i18n"
"golang.org/x/text/language"
)
type Localizer interface { type Localizer interface {
Message(string) string Message(string) string
Template(string, interface{}) string Template(string, interface{}) string
Tag() language.Tag
} }
type localizer struct { type localizer struct {
loc *i18n.Localizer loc *i18n.Localizer
tag language.Tag
} }
func (l *localizer) Message(str string) string { func (l *localizer) Message(str string) string {
@ -21,3 +26,7 @@ func (l *localizer) Template(str string, tpl interface{}) string {
TemplateData: tpl, TemplateData: tpl,
}) })
} }
func (l *localizer) Tag() language.Tag {
return l.tag
}