From 44228cd9a27461accfff610a061b587ba40f94af Mon Sep 17 00:00:00 2001 From: Kay Date: Sat, 16 Dec 2023 17:03:34 +0000 Subject: [PATCH] chore: using erros properly --- core/server/server.go | 8 +++----- utils/errors/errors.go | 4 ++++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/core/server/server.go b/core/server/server.go index 8fd8e74..6e5c7dc 100644 --- a/core/server/server.go +++ b/core/server/server.go @@ -1,7 +1,6 @@ package server import ( - "errors" "fmt" "net" "os" @@ -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 @@ -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)) diff --git a/utils/errors/errors.go b/utils/errors/errors.go index 39e7c92..03c31f2 100644 --- a/utils/errors/errors.go +++ b/utils/errors/errors.go @@ -3,7 +3,11 @@ package errors import "errors" var ( + // config 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 + ErrAuth = errors.New("authentication error") )