Compare commits
1 Commits
fix/golang
...
fix/docker
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f821d66670 |
@@ -10,8 +10,7 @@ RUN go mod download
|
|||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Run all checks — build fails if branch is not green
|
# Run all checks — build fails if branch is not green
|
||||||
# golangci-lint v2.1.6
|
RUN CGO_ENABLED=0 go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.1.6
|
||||||
RUN CGO_ENABLED=0 go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@eabc2638a66daf5bb6c6fb052a32fa3ef7b6600d
|
|
||||||
RUN make check
|
RUN make check
|
||||||
|
|
||||||
ARG VERSION=dev
|
ARG VERSION=dev
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ func (c *Client) PollMessages(
|
|||||||
|
|
||||||
req.Header.Set("Authorization", "Bearer "+c.Token)
|
req.Header.Set("Authorization", "Bearer "+c.Token)
|
||||||
|
|
||||||
resp, err := client.Do(req) //nolint:gosec,nolintlint // URL from user config
|
resp, err := client.Do(req) //nolint:gosec // URL from user config
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -269,7 +269,7 @@ func (c *Client) do(
|
|||||||
req.Header.Set("Authorization", "Bearer "+c.Token)
|
req.Header.Set("Authorization", "Bearer "+c.Token)
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := c.HTTPClient.Do(req) //nolint:gosec,nolintlint // URL from user config
|
resp, err := c.HTTPClient.Do(req) //nolint:gosec // URL from user config
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("http: %w", err)
|
return nil, fmt.Errorf("http: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ type UI struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewUI creates the tview-based IRC-like UI.
|
// NewUI creates the tview-based IRC-like UI.
|
||||||
|
|
||||||
func NewUI() *UI {
|
func NewUI() *UI {
|
||||||
ui := &UI{
|
ui := &UI{
|
||||||
app: tview.NewApplication(),
|
app: tview.NewApplication(),
|
||||||
@@ -49,21 +50,25 @@ func NewUI() *UI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run starts the UI event loop (blocks).
|
// Run starts the UI event loop (blocks).
|
||||||
|
|
||||||
func (ui *UI) Run() error {
|
func (ui *UI) Run() error {
|
||||||
return ui.app.Run()
|
return ui.app.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop stops the UI.
|
// Stop stops the UI.
|
||||||
|
|
||||||
func (ui *UI) Stop() {
|
func (ui *UI) Stop() {
|
||||||
ui.app.Stop()
|
ui.app.Stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
// OnInput sets the callback for user input.
|
// OnInput sets the callback for user input.
|
||||||
|
|
||||||
func (ui *UI) OnInput(fn func(string)) {
|
func (ui *UI) OnInput(fn func(string)) {
|
||||||
ui.onInput = fn
|
ui.onInput = fn
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddLine adds a line to the specified buffer.
|
// AddLine adds a line to the specified buffer.
|
||||||
|
|
||||||
func (ui *UI) AddLine(bufferName string, line string) {
|
func (ui *UI) AddLine(bufferName string, line string) {
|
||||||
ui.app.QueueUpdateDraw(func() {
|
ui.app.QueueUpdateDraw(func() {
|
||||||
buf := ui.getOrCreateBuffer(bufferName)
|
buf := ui.getOrCreateBuffer(bufferName)
|
||||||
@@ -84,6 +89,7 @@ func (ui *UI) AddLine(bufferName string, line string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddStatus adds a line to the status buffer (buffer 0).
|
// AddStatus adds a line to the status buffer (buffer 0).
|
||||||
|
|
||||||
func (ui *UI) AddStatus(line string) {
|
func (ui *UI) AddStatus(line string) {
|
||||||
ts := time.Now().Format("15:04")
|
ts := time.Now().Format("15:04")
|
||||||
|
|
||||||
@@ -94,6 +100,7 @@ func (ui *UI) AddStatus(line string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SwitchBuffer switches to the buffer at index n.
|
// SwitchBuffer switches to the buffer at index n.
|
||||||
|
|
||||||
func (ui *UI) SwitchBuffer(n int) {
|
func (ui *UI) SwitchBuffer(n int) {
|
||||||
ui.app.QueueUpdateDraw(func() {
|
ui.app.QueueUpdateDraw(func() {
|
||||||
if n < 0 || n >= len(ui.buffers) {
|
if n < 0 || n >= len(ui.buffers) {
|
||||||
@@ -117,6 +124,7 @@ func (ui *UI) SwitchBuffer(n int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SwitchToBuffer switches to the named buffer, creating it
|
// SwitchToBuffer switches to the named buffer, creating it
|
||||||
|
|
||||||
func (ui *UI) SwitchToBuffer(name string) {
|
func (ui *UI) SwitchToBuffer(name string) {
|
||||||
ui.app.QueueUpdateDraw(func() {
|
ui.app.QueueUpdateDraw(func() {
|
||||||
buf := ui.getOrCreateBuffer(name)
|
buf := ui.getOrCreateBuffer(name)
|
||||||
@@ -143,6 +151,7 @@ func (ui *UI) SwitchToBuffer(name string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetStatus updates the status bar text.
|
// SetStatus updates the status bar text.
|
||||||
|
|
||||||
func (ui *UI) SetStatus(
|
func (ui *UI) SetStatus(
|
||||||
nick, target, connStatus string,
|
nick, target, connStatus string,
|
||||||
) {
|
) {
|
||||||
@@ -152,11 +161,13 @@ func (ui *UI) SetStatus(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// BufferCount returns the number of buffers.
|
// BufferCount returns the number of buffers.
|
||||||
|
|
||||||
func (ui *UI) BufferCount() int {
|
func (ui *UI) BufferCount() int {
|
||||||
return len(ui.buffers)
|
return len(ui.buffers)
|
||||||
}
|
}
|
||||||
|
|
||||||
// BufferIndex returns the index of a named buffer, or -1.
|
// BufferIndex returns the index of a named buffer, or -1.
|
||||||
|
|
||||||
func (ui *UI) BufferIndex(name string) int {
|
func (ui *UI) BufferIndex(name string) int {
|
||||||
for i, buf := range ui.buffers {
|
for i, buf := range ui.buffers {
|
||||||
if buf.Name == name {
|
if buf.Name == name {
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ func NewTest(dsn string) (*Database, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Item 9: Enable foreign keys
|
// Item 9: Enable foreign keys
|
||||||
_, err = d.Exec("PRAGMA foreign_keys = ON") //nolint:noctx,nolintlint // no context in sql.Open path
|
_, err = d.Exec("PRAGMA foreign_keys = ON") //nolint:noctx // no context in sql.Open path
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = d.Close()
|
_ = d.Close()
|
||||||
|
|
||||||
@@ -612,7 +612,7 @@ func (s *Database) loadMigrations() ([]migration, error) {
|
|||||||
return nil, fmt.Errorf("read schema dir: %w", err)
|
return nil, fmt.Errorf("read schema dir: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
migrations := make([]migration, 0, len(entries))
|
var migrations []migration
|
||||||
|
|
||||||
for _, entry := range entries {
|
for _, entry := range entries {
|
||||||
if entry.IsDir() ||
|
if entry.IsDir() ||
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package db_test
|
package db_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -40,7 +41,7 @@ func TestCreateUser(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
d := setupTestDB(t)
|
d := setupTestDB(t)
|
||||||
ctx := t.Context()
|
ctx := context.Background()
|
||||||
|
|
||||||
id, token, err := d.CreateUser(ctx, nickAlice)
|
id, token, err := d.CreateUser(ctx, nickAlice)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -60,7 +61,7 @@ func TestGetUserByToken(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
d := setupTestDB(t)
|
d := setupTestDB(t)
|
||||||
ctx := t.Context()
|
ctx := context.Background()
|
||||||
|
|
||||||
_, token, _ := d.CreateUser(ctx, nickAlice)
|
_, token, _ := d.CreateUser(ctx, nickAlice)
|
||||||
|
|
||||||
@@ -81,7 +82,7 @@ func TestGetUserByNick(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
d := setupTestDB(t)
|
d := setupTestDB(t)
|
||||||
ctx := t.Context()
|
ctx := context.Background()
|
||||||
|
|
||||||
origID, _, _ := d.CreateUser(ctx, nickAlice)
|
origID, _, _ := d.CreateUser(ctx, nickAlice)
|
||||||
|
|
||||||
@@ -99,7 +100,7 @@ func TestGetOrCreateChannel(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
d := setupTestDB(t)
|
d := setupTestDB(t)
|
||||||
ctx := t.Context()
|
ctx := context.Background()
|
||||||
|
|
||||||
id1, err := d.GetOrCreateChannel(ctx, "#general")
|
id1, err := d.GetOrCreateChannel(ctx, "#general")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -125,7 +126,7 @@ func TestJoinAndListChannels(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
d := setupTestDB(t)
|
d := setupTestDB(t)
|
||||||
ctx := t.Context()
|
ctx := context.Background()
|
||||||
|
|
||||||
uid, _, _ := d.CreateUser(ctx, nickAlice)
|
uid, _, _ := d.CreateUser(ctx, nickAlice)
|
||||||
ch1, _ := d.GetOrCreateChannel(ctx, "#alpha")
|
ch1, _ := d.GetOrCreateChannel(ctx, "#alpha")
|
||||||
@@ -148,7 +149,7 @@ func TestListChannelsEmpty(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
d := setupTestDB(t)
|
d := setupTestDB(t)
|
||||||
ctx := t.Context()
|
ctx := context.Background()
|
||||||
|
|
||||||
uid, _, _ := d.CreateUser(ctx, nickAlice)
|
uid, _, _ := d.CreateUser(ctx, nickAlice)
|
||||||
|
|
||||||
@@ -166,7 +167,7 @@ func TestPartChannel(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
d := setupTestDB(t)
|
d := setupTestDB(t)
|
||||||
ctx := t.Context()
|
ctx := context.Background()
|
||||||
|
|
||||||
uid, _, _ := d.CreateUser(ctx, nickAlice)
|
uid, _, _ := d.CreateUser(ctx, nickAlice)
|
||||||
chID, _ := d.GetOrCreateChannel(ctx, "#general")
|
chID, _ := d.GetOrCreateChannel(ctx, "#general")
|
||||||
@@ -188,7 +189,7 @@ func TestSendAndGetMessages(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
d := setupTestDB(t)
|
d := setupTestDB(t)
|
||||||
ctx := t.Context()
|
ctx := context.Background()
|
||||||
|
|
||||||
uid, _, _ := d.CreateUser(ctx, nickAlice)
|
uid, _, _ := d.CreateUser(ctx, nickAlice)
|
||||||
chID, _ := d.GetOrCreateChannel(ctx, "#general")
|
chID, _ := d.GetOrCreateChannel(ctx, "#general")
|
||||||
@@ -220,7 +221,7 @@ func TestChannelMembers(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
d := setupTestDB(t)
|
d := setupTestDB(t)
|
||||||
ctx := t.Context()
|
ctx := context.Background()
|
||||||
|
|
||||||
uid1, _, _ := d.CreateUser(ctx, nickAlice)
|
uid1, _, _ := d.CreateUser(ctx, nickAlice)
|
||||||
uid2, _, _ := d.CreateUser(ctx, nickBob)
|
uid2, _, _ := d.CreateUser(ctx, nickBob)
|
||||||
@@ -245,7 +246,7 @@ func TestChannelMembersEmpty(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
d := setupTestDB(t)
|
d := setupTestDB(t)
|
||||||
ctx := t.Context()
|
ctx := context.Background()
|
||||||
|
|
||||||
chID, _ := d.GetOrCreateChannel(ctx, "#empty")
|
chID, _ := d.GetOrCreateChannel(ctx, "#empty")
|
||||||
|
|
||||||
@@ -263,7 +264,7 @@ func TestSendDM(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
d := setupTestDB(t)
|
d := setupTestDB(t)
|
||||||
ctx := t.Context()
|
ctx := context.Background()
|
||||||
|
|
||||||
uid1, _, _ := d.CreateUser(ctx, nickAlice)
|
uid1, _, _ := d.CreateUser(ctx, nickAlice)
|
||||||
uid2, _, _ := d.CreateUser(ctx, nickBob)
|
uid2, _, _ := d.CreateUser(ctx, nickBob)
|
||||||
@@ -295,7 +296,7 @@ func TestPollMessages(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
d := setupTestDB(t)
|
d := setupTestDB(t)
|
||||||
ctx := t.Context()
|
ctx := context.Background()
|
||||||
|
|
||||||
uid1, _, _ := d.CreateUser(ctx, nickAlice)
|
uid1, _, _ := d.CreateUser(ctx, nickAlice)
|
||||||
uid2, _, _ := d.CreateUser(ctx, nickBob)
|
uid2, _, _ := d.CreateUser(ctx, nickBob)
|
||||||
@@ -323,7 +324,7 @@ func TestChangeNick(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
d := setupTestDB(t)
|
d := setupTestDB(t)
|
||||||
ctx := t.Context()
|
ctx := context.Background()
|
||||||
|
|
||||||
_, token, _ := d.CreateUser(ctx, nickAlice)
|
_, token, _ := d.CreateUser(ctx, nickAlice)
|
||||||
|
|
||||||
@@ -346,7 +347,7 @@ func TestSetTopic(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
d := setupTestDB(t)
|
d := setupTestDB(t)
|
||||||
ctx := t.Context()
|
ctx := context.Background()
|
||||||
|
|
||||||
uid, _, _ := d.CreateUser(ctx, nickAlice)
|
uid, _, _ := d.CreateUser(ctx, nickAlice)
|
||||||
_, _ = d.GetOrCreateChannel(ctx, "#general")
|
_, _ = d.GetOrCreateChannel(ctx, "#general")
|
||||||
@@ -378,7 +379,7 @@ func TestGetMessagesBefore(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
d := setupTestDB(t)
|
d := setupTestDB(t)
|
||||||
ctx := t.Context()
|
ctx := context.Background()
|
||||||
|
|
||||||
uid, _, _ := d.CreateUser(ctx, nickAlice)
|
uid, _, _ := d.CreateUser(ctx, nickAlice)
|
||||||
chID, _ := d.GetOrCreateChannel(ctx, "#general")
|
chID, _ := d.GetOrCreateChannel(ctx, "#general")
|
||||||
@@ -408,7 +409,7 @@ func TestListAllChannels(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
d := setupTestDB(t)
|
d := setupTestDB(t)
|
||||||
ctx := t.Context()
|
ctx := context.Background()
|
||||||
|
|
||||||
_, _ = d.GetOrCreateChannel(ctx, "#alpha")
|
_, _ = d.GetOrCreateChannel(ctx, "#alpha")
|
||||||
_, _ = d.GetOrCreateChannel(ctx, "#beta")
|
_, _ = d.GetOrCreateChannel(ctx, "#beta")
|
||||||
|
|||||||
@@ -224,7 +224,7 @@ func (s *Handlers) HandleChannelMembers() http.HandlerFunc {
|
|||||||
|
|
||||||
var chID int64
|
var chID int64
|
||||||
|
|
||||||
err := s.params.Database.GetDB().QueryRowContext( //nolint:gosec,nolintlint // parameterized query
|
err := s.params.Database.GetDB().QueryRowContext( //nolint:gosec // parameterized query
|
||||||
r.Context(),
|
r.Context(),
|
||||||
"SELECT id FROM channels WHERE name = ?",
|
"SELECT id FROM channels WHERE name = ?",
|
||||||
name,
|
name,
|
||||||
@@ -401,7 +401,7 @@ func (s *Handlers) sendChannelMsg(
|
|||||||
) {
|
) {
|
||||||
var chID int64
|
var chID int64
|
||||||
|
|
||||||
err := s.params.Database.GetDB().QueryRowContext( //nolint:gosec,nolintlint // parameterized query
|
err := s.params.Database.GetDB().QueryRowContext( //nolint:gosec // parameterized query
|
||||||
r.Context(),
|
r.Context(),
|
||||||
"SELECT id FROM channels WHERE name = ?",
|
"SELECT id FROM channels WHERE name = ?",
|
||||||
channel,
|
channel,
|
||||||
@@ -535,7 +535,7 @@ func (s *Handlers) handlePart(
|
|||||||
|
|
||||||
var chID int64
|
var chID int64
|
||||||
|
|
||||||
err := s.params.Database.GetDB().QueryRowContext( //nolint:gosec,nolintlint // parameterized query
|
err := s.params.Database.GetDB().QueryRowContext( //nolint:gosec // parameterized query
|
||||||
r.Context(),
|
r.Context(),
|
||||||
"SELECT id FROM channels WHERE name = ?",
|
"SELECT id FROM channels WHERE name = ?",
|
||||||
channel,
|
channel,
|
||||||
@@ -717,7 +717,7 @@ func (s *Handlers) getChannelHistory(
|
|||||||
) {
|
) {
|
||||||
var chID int64
|
var chID int64
|
||||||
|
|
||||||
err := s.params.Database.GetDB().QueryRowContext( //nolint:gosec,nolintlint // parameterized query
|
err := s.params.Database.GetDB().QueryRowContext( //nolint:gosec // parameterized query
|
||||||
r.Context(),
|
r.Context(),
|
||||||
"SELECT id FROM channels WHERE name = ?",
|
"SELECT id FROM channels WHERE name = ?",
|
||||||
target,
|
target,
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ func (b *Base) GetDB() *sql.DB {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetUserLookup returns the DB as a UserLookup if it implements the interface.
|
// GetUserLookup returns the DB as a UserLookup if it implements the interface.
|
||||||
func (b *Base) GetUserLookup() UserLookup { //nolint:ireturn,nolintlint // returns interface by design
|
func (b *Base) GetUserLookup() UserLookup { //nolint:ireturn
|
||||||
if ul, ok := b.db.(UserLookup); ok {
|
if ul, ok := b.db.(UserLookup); ok {
|
||||||
return ul
|
return ul
|
||||||
}
|
}
|
||||||
@@ -56,7 +56,7 @@ func (b *Base) GetUserLookup() UserLookup { //nolint:ireturn,nolintlint // retur
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetChannelLookup returns the DB as a ChannelLookup if it implements the interface.
|
// GetChannelLookup returns the DB as a ChannelLookup if it implements the interface.
|
||||||
func (b *Base) GetChannelLookup() ChannelLookup { //nolint:ireturn,nolintlint // returns interface by design
|
func (b *Base) GetChannelLookup() ChannelLookup { //nolint:ireturn
|
||||||
if cl, ok := b.db.(ChannelLookup); ok {
|
if cl, ok := b.db.(ChannelLookup); ok {
|
||||||
return cl
|
return cl
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user