Skip to content

Commit

Permalink
Merge pull request #27 from green-ecolution/feature/fix-linter-annota…
Browse files Browse the repository at this point in the history
…tions

chore: fix linter annotation
  • Loading branch information
choffmann authored Jul 30, 2024
2 parents 6156fd4 + 2600d60 commit b06ce82
Show file tree
Hide file tree
Showing 26 changed files with 86 additions and 86 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ linters:
- gosimple
- govet
- ineffassign
- lll
# - lll
- misspell
- nakedret
- noctx
Expand Down
2 changes: 1 addition & 1 deletion config/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type MQTTConfig struct {
}

type Config struct {
Url *url.URL `env:"APP_URL,expand" envDefault:"localhost:$PORT"`
URL *url.URL `env:"APP_URL,expand" envDefault:"localhost:$PORT"`
Port int `env:"PORT" envDefault:"8000"`
Development bool `env:"DEVELOPMENT" envDefault:"false"`
MQTT MQTTConfig `envPrefix:"MQTT_"`
Expand Down
2 changes: 1 addition & 1 deletion internal/entities/info/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type Server struct {
OS string
Arch string
Hostname string
Url *url.URL
URL *url.URL
IP net.IP
Port int
Interface string
Expand Down
2 changes: 1 addition & 1 deletion internal/entities/sensor/mqtt.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type MqttRxMetadata struct {
FrequencyOffset string
Location MqttLocation
UplinkToken string
RecievedAt *time.Time
ReceivedAt *time.Time
}

type MqttUplinkSettingsLora struct {
Expand Down
6 changes: 3 additions & 3 deletions internal/mapper/basic_types_mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ func TimeToTime(t time.Time) time.Time {
return t
}

func UrlToUrl(u *url.URL) *url.URL {
func URLToURL(u *url.URL) *url.URL {
return u
}

Expand All @@ -23,7 +23,7 @@ func StringToTime(s string) time.Time {
return t
}

func StringToUrl(s string) *url.URL {
func StringToURL(s string) *url.URL {
u, _ := url.Parse(s)
return u
}
Expand All @@ -46,7 +46,7 @@ func TimeToString(t time.Time) string {
return t.Format(time.RFC3339)
}

func NetUrlToString(u *url.URL) string {
func NetURLToString(u *url.URL) string {
return u.String()
}

Expand Down
4 changes: 2 additions & 2 deletions internal/mapper/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
)

// goverter:converter
// goverter:extend TimeToTime UrlToUrl TimeDurationToTimeDuration StringToTime StringToUrl StringToNetIP
// goverter:extend StringToDuration TimeToString NetUrlToString NetIPToString TimeDurationToString
// goverter:extend TimeToTime URLToURL TimeDurationToTimeDuration StringToTime StringToURL StringToNetIP
// goverter:extend StringToDuration TimeToString NetURLToString NetIPToString TimeDurationToString
type InfoMapper interface {
ToEntity(src *domain.App) *repo.AppEntity
FromEntity(src *repo.AppEntity) *domain.App
Expand Down
4 changes: 2 additions & 2 deletions internal/server/http/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (

func (s *Server) healthCheck() func(c *fiber.Ctx) error {
return healthcheck.New(healthcheck.Config{
LivenessProbe: func(c *fiber.Ctx) bool {
LivenessProbe: func(_ *fiber.Ctx) bool {
return true
},
LivenessEndpoint: "/health",
ReadinessProbe: func(c *fiber.Ctx) bool {
ReadinessProbe: func(_ *fiber.Ctx) bool {
return s.services.AllServicesReady()
},
ReadinessEndpoint: "/ready",
Expand Down
4 changes: 2 additions & 2 deletions internal/server/http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type HTTPError struct {
Code int `json:"code"`
Path string `json:"path"`
Method string `json:"method"`
} //@Name HTTPError
} // @Name HTTPError

type Server struct {
cfg *config.Config
Expand Down Expand Up @@ -44,7 +44,7 @@ func (s *Server) Run(ctx context.Context) error {
}
}()

return app.Listen(fmt.Sprintf(":%d", s.cfg.Port))
return app.Listen(fmt.Sprintf(":%d", s.cfg.Port))
}

func errorHandler(c *fiber.Ctx, err error) error {
Expand Down
4 changes: 2 additions & 2 deletions internal/server/mqtt/mqtt.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ func (m *Mqtt) RunSubscriber(ctx context.Context) {
opts.SetUsername(m.cfg.MQTT.Username)
opts.SetPassword(m.cfg.MQTT.Password)

opts.OnConnect = func(client MQTT.Client) {
opts.OnConnect = func(_ MQTT.Client) {
log.Println("Connected to MQTT Broker")
m.svc.MqttService.SetConnected(true)
}
opts.OnConnectionLost = func(client MQTT.Client, err error) {
opts.OnConnectionLost = func(_ MQTT.Client, err error) {
log.Printf("Connection lost to MQTT Broker: %v\n", err)
}

Expand Down
2 changes: 1 addition & 1 deletion internal/service/domain/info/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func NewInfoService(infoRepository storage.InfoRepository) *InfoService {
func (s *InfoService) GetAppInfo(ctx context.Context) (*info.App, error) {
appInfo, err := s.infoRepository.GetAppInfo(ctx)
if err != nil {
if errors.Is(err, storage.ErrIpNotFound) {
if errors.Is(err, storage.ErrIPNotFound) {
return nil, service.NewError(service.InternalError, err.Error())
}
if errors.Is(err, storage.ErrIFacesNotFound) {
Expand Down
7 changes: 3 additions & 4 deletions internal/service/domain/info/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ func TestNewInfoService(t *testing.T) {
}

func TestGetAppInfo(t *testing.T) {

t.Run("should error if GetAppInfo return error", func(t *testing.T) {
// given
repo := storageMock.NewMockInfoRepository(t)
svc := NewInfoService(repo)
tests := map[error]service.ErrorCode{
storage.ErrIpNotFound: service.InternalError,
storage.ErrIPNotFound: service.InternalError,
storage.ErrIFacesNotFound: service.InternalError,
storage.ErrIFacesAddressNotFound: service.InternalError,
storage.ErrHostnameNotFound: service.InternalError,
Expand Down Expand Up @@ -75,7 +74,7 @@ func TestGetAppInfo(t *testing.T) {
OS: "linux",
Arch: "amd64",
Hostname: "localhost",
Url: &url.URL{
URL: &url.URL{
Scheme: "http",
Host: "localhost:8080",
},
Expand Down Expand Up @@ -103,7 +102,7 @@ func TestGetAppInfo(t *testing.T) {
OS: "linux",
Arch: "amd64",
Hostname: "localhost",
Url: &url.URL{
URL: &url.URL{
Scheme: "http",
Host: "localhost:8080",
},
Expand Down
2 changes: 1 addition & 1 deletion internal/service/domain/sensor/mqtt.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func NewMqttService(sensorRepository storage.SensorRepository) *MqttService {
return &MqttService{sensorRepo: sensorRepository, mapper: &generated.MqttMapperImpl{}}
}

func (s *MqttService) HandleMessage(client MQTT.Client, msg MQTT.Message) {
func (s *MqttService) HandleMessage(_ MQTT.Client, msg MQTT.Message) {
jsonStr := string(msg.Payload())
log.Printf("Received message: %s\n", jsonStr)

Expand Down
2 changes: 1 addition & 1 deletion internal/service/domain/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/green-ecolution/green-ecolution-backend/internal/storage"
)

func NewService(cfg *config.Config, repositories *storage.Repository) *service.Services {
func NewService(_ *config.Config, repositories *storage.Repository) *service.Services {
return &service.Services{
InfoService: info.NewInfoService(repositories.Info),
MqttService: sensor.NewMqttService(repositories.Sensor),
Expand Down
24 changes: 14 additions & 10 deletions internal/service/domain/tree/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ type TreeService struct {
sensorMapper mapper.MqttMapper
}

func NewTreeService(treeRepo storage.TreeRepository, sensorRepo storage.SensorRepository) *TreeService {
func NewTreeService(repoTree storage.TreeRepository, repoSensor storage.SensorRepository) *TreeService {
return &TreeService{
treeRepo: treeRepo,
sensorRepo: sensorRepo,
treeRepo: repoTree,
sensorRepo: repoSensor,
treeMapper: &generated.TreeMapperImpl{},
sensorMapper: &generated.MqttMapperImpl{},
}
Expand Down Expand Up @@ -85,16 +85,16 @@ func (s *TreeService) GetAllTreesResponse(ctx context.Context, withSensorData bo

if withSensorData {
wg.Add(len(treeEntities))
for i, entity := range treeEntities {
go func(i int, entity *treeRepo.TreeEntity, treeID string) {
for i := range treeEntities {
go func(treeID string) {
defer wg.Done()
data, err := s.fetchSensorData(ctx, treeID)
if err != nil {
log.Printf("Error fetching sensor data for tree %s: %v", treeID, err)
return
}
sensorData[treeID] = data
}(i, entity, treeData[i].ID)
}(treeData[i].ID)
}
wg.Wait()
}
Expand All @@ -109,8 +109,8 @@ func (s *TreeService) GetAllTreesResponse(ctx context.Context, withSensorData bo
return response, nil
}

func (s *TreeService) InsertTree(ctx context.Context, data tree.Tree) error {
entity := s.treeMapper.ToEntity(&data)
func (s *TreeService) InsertTree(ctx context.Context, data *tree.Tree) error {
entity := s.treeMapper.ToEntity(data)
err := s.treeRepo.Insert(ctx, entity)
if err != nil {
return handleError(err)
Expand Down Expand Up @@ -188,9 +188,13 @@ func (s *TreeService) GetTreePredictionResponse(ctx context.Context, id string,
}

func getHealth(humidity int) tree.PredictedHealth {
if humidity < 40 {
const (
ThresholdBad = 40
ThresholdModerate = 70
)
if humidity < ThresholdBad {
return tree.HealthBad
} else if humidity < 70 {
} else if humidity < ThresholdModerate {
return tree.HealthModerate
}

Expand Down
8 changes: 4 additions & 4 deletions internal/service/entities/info/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ type AppInfoResponse struct {
GoVersion string `json:"goVersion"`
Git GitResponse `json:"git"`
Server ServerResponse `json:"server"`
} //@Name AppInfo
} // @Name AppInfo

type GitResponse struct {
Branch string `json:"branch"`
Commit string `json:"commit"`
Repository string `json:"repository"`
} //@Name GitInfo
} // @Name GitInfo

type ServerResponse struct {
OS string `json:"os"`
Arch string `json:"arch"`
Hostname string `json:"hostname"`
Url string `json:"url"`
URL string `json:"url"`
IP string `json:"ip"`
Port int `json:"port"`
Interface string `json:"interface"`
Uptime string `json:"uptime"`
} //@Name ServerInfo
} // @Name ServerInfo
Loading

0 comments on commit b06ce82

Please sign in to comment.