Skip to content
This repository has been archived by the owner on Sep 7, 2024. It is now read-only.

Commit

Permalink
chore: using erros properly
Browse files Browse the repository at this point in the history
  • Loading branch information
kehiy committed Dec 16, 2023
1 parent fdfae8e commit 44228cd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 3 additions & 5 deletions core/server/server.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package server

import (
"errors"
"fmt"
"net"
"os"
Expand All @@ -14,10 +13,9 @@ import (
parser "github.com/zurvan-lab/TimeTrace/core/TQL/parser"
"github.com/zurvan-lab/TimeTrace/core/database"
ttlogger "github.com/zurvan-lab/TimeTrace/log"
"github.com/zurvan-lab/TimeTrace/utils/errors"
)

var ErrAuth = errors.New("authentication error")

type Server struct {
ListenAddress string
Listener net.Listener
Expand Down Expand Up @@ -154,14 +152,14 @@ func (s *Server) Authenticate(conn net.Conn) (*config.User, error) {
if query.Command != "CON" {
_ = conn.Close()

return nil, ErrAuth
return nil, errors.ErrAuth
}

result := execute.Execute(query, s.db)
if result != database.DONE {
_ = conn.Close()

return nil, ErrAuth
return nil, errors.ErrAuth
}

_, _ = conn.Write([]byte(result))
Expand Down
4 changes: 4 additions & 0 deletions utils/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ package errors
import "errors"

var (
// config

Check failure on line 6 in utils/errors/errors.go

View workflow job for this annotation

GitHub Actions / lint

Comment should end in a period (godot)
ErrInavlidConfigPath = errors.New("invalid config path")
ErrInvalidUsers = errors.New("invalid user(s)")
ErrSpecificAndAllCommandSameAtTime = errors.New("can't have all cmds and specific cmd at same time")

// server

Check failure on line 11 in utils/errors/errors.go

View workflow job for this annotation

GitHub Actions / lint

Comment should end in a period (godot)
ErrAuth = errors.New("authentication error")
)

0 comments on commit 44228cd

Please sign in to comment.