Skip to content

Commit

Permalink
Fix Go linter issues, add Latte linter to the CI
Browse files Browse the repository at this point in the history
  • Loading branch information
rootpd committed May 31, 2022
1 parent 62793f9 commit 10b6d42
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 19 deletions.
19 changes: 14 additions & 5 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ syntax:7.4:

sniffer:
stage: test
image: remp/php-ci:7.4.15
image: remp/php-ci:7.4.29
tags:
- docker
script:
Expand All @@ -25,26 +25,35 @@ sniffer:

phpstan:
stage: test
image: remp/php-ci:7.4.15
image: remp/php-ci:7.4.29
tags:
- docker
script:
- make composer-install
- make phpstan

latte_lint:
stage: test
image: remp/php-ci:7.4.29
tags:
- docker
script:
- make composer-install
- make latte-lint

tests:
stage: test
image: remp/php-ci:7.4.15
image: remp/php-ci:7.4.29
tags:
- docker
script:
- make composer-install
- make copy-env
- make phpunit
services:
- name: mysql:5.7.21
- name: mysql:8.0.29
alias: mysql
- name: redis:3.2
- name: redis:6.2
alias: redis
variables:
MYSQL_DATABASE: remp_test
Expand Down
2 changes: 1 addition & 1 deletion Beam/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ lint: lint-lib
@cd $(SUB_SEGMENTS) && make lint

vet-lib:
@go vet $$(go list ./... | grep -vE '(/vendor|/cmd)')
@go vet $$(go list go/... | grep -vE '(/vendor|/cmd)')

vet: vet-lib
@cd $(SUB_TRACKER) && make vet
Expand Down
4 changes: 2 additions & 2 deletions Beam/go/cmd/tracker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ install: gen

lint:
set -e; \
for package in $$(go list ./... | grep -vE '(/app|/design|/swagger|/client|/tool|/test)'); \
for package in $$(go list ./... | grep -vE '(/app|/design|/swagger|/client|/tool|/test|/data)'); \
do golint -set_exit_status=true $$package; done

vet:
go vet $$(go list ./... | grep -vE '(/app|/design|/swagger|/client|/tool|/test)')
go vet $$(go list ./... | grep -vE '(/app|/design|/swagger|/client|/tool|/test|/data)')
6 changes: 3 additions & 3 deletions Beam/go/cmd/tracker/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ type Config struct {

InternalHosts string `envconfig:"internal_hosts" required:"false"`

TimespentLimit int `envconfig:"timespent_limit" required:"false" default:0`
TimespentLimit int `envconfig:"timespent_limit" required:"false" default:"0"`

BrokerImpl string `envconfig:"broker_impl" required:"false" default:"kafka"`

PubSubProjectId string `envconfig:"pubsub_project_id" required:"false"`
PubSubTopicId string `envconfig:"pubsub_topic_id" required:"false"`
PubSubProjectID string `envconfig:"pubsub_project_id" required:"false"`
PubSubTopicID string `envconfig:"pubsub_topic_id" required:"false"`
}
5 changes: 5 additions & 0 deletions Beam/go/cmd/tracker/controller/event_producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ import (
"time"
)

// EventProducer provides a method to produce and publish the tracked events as messages.
//
// The messages are published to the configured message queue implementation.
type EventProducer interface {
// Produce generates a message and passes it to the message queue broker.
Produce(ctx context.Context, table string, time time.Time, data map[string]any) error

// Close closes any channels or connections that are opened by the producer.
Close() error
}
2 changes: 2 additions & 0 deletions Beam/go/cmd/tracker/controller/kafka_event_producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func NewKafkaEventProducer(brokerAddrs []string, saslConfig *SaslConfig) (*Kafka
}, nil
}

// Produce generates a message in the influx-data format and passes it to the configured Kafka instance.
func (kep KafkaEventProducer) Produce(ctx context.Context, table string, time time.Time, data map[string]any) error {
p, err := influxClient.NewPoint(table, nil, data, time)
if err != nil {
Expand All @@ -64,6 +65,7 @@ func (kep KafkaEventProducer) Produce(ctx context.Context, table string, time ti
return nil
}

// Close closes the connection to the Kafka event producer.
func (kep KafkaEventProducer) Close() error {
return kep.EventProducer.Close()
}
12 changes: 7 additions & 5 deletions Beam/go/cmd/tracker/controller/pubsub_event_producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,26 @@ import (
"github.com/pkg/errors"
)

// Implementation of EventProducer
// PubSubEventProducer is a Cloud PubSub implementation of EventProducer interface.
type PubSubEventProducer struct {
client pubsub.Client
topic pubsub.Topic
}

// NewPubSubEventProducer creates new PubSubEventProducer
func NewPubSubEventProducer(ctx context.Context, projectId string, topicId string) (*PubSubEventProducer, error) {
client, err := pubsub.NewClient(ctx, projectId)
func NewPubSubEventProducer(ctx context.Context, projectID string, topicID string) (*PubSubEventProducer, error) {
client, err := pubsub.NewClient(ctx, projectID)
if err != nil {
return nil, err
}

topic := client.Topic(topicId)
topic := client.Topic(topicID)
ok, err := topic.Exists(ctx)
if err != nil {
return nil, err
}
if !ok {
return nil, errors.Errorf("PubSub: topic %q doesn't exist.", topicId)
return nil, errors.Errorf("PubSub: topic %q doesn't exist.", topicID)
}

return &PubSubEventProducer{
Expand All @@ -38,6 +38,7 @@ func NewPubSubEventProducer(ctx context.Context, projectId string, topicId strin
}, nil
}

// Produce generates a message and passes it to the configured Cloud Pub/Sub interface.
func (psep PubSubEventProducer) Produce(ctx context.Context, table string, time time.Time, data map[string]any) error {
p, err := influxClient.NewPoint(table, nil, data, time)
if err != nil {
Expand All @@ -58,6 +59,7 @@ func (psep PubSubEventProducer) Produce(ctx context.Context, table string, time
return nil
}

// Close closes the connection with the Cloud Pub/Sub client.
func (psep PubSubEventProducer) Close() error {
return psep.client.Close()
}
4 changes: 2 additions & 2 deletions Beam/go/cmd/tracker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ func newProducer(ctx context.Context, config *Config, service *goa.Service) (con
return producer, nil

case "pubsub":
service.LogInfo("connecting to pubsub", "projectID", config.PubSubProjectId, "topicID", config.PubSubTopicId)
producer, err := controller.NewPubSubEventProducer(ctx, config.PubSubProjectId, config.PubSubTopicId)
service.LogInfo("connecting to pubsub", "projectID", config.PubSubProjectID, "topicID", config.PubSubTopicID)
producer, err := controller.NewPubSubEventProducer(ctx, config.PubSubProjectID, config.PubSubTopicID)
if err != nil {
return nil, err
}
Expand Down
5 changes: 4 additions & 1 deletion Mailer/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@ syntax:
find ${PHP_FOLDERS} -name "*.php" -print0 | xargs -0 -n1 -P8 php -l

phpstan:
php vendor/bin/phpstan analyse --configuration=.phpstan.neon --level=1 --memory-limit=1G app tests extensions
php vendor/bin/phpstan analyse --level=1 --memory-limit=1G app tests extensions

latte-lint:
php vendor/bin/latte-lint app extensions
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ phpstan:
lint:
cd $(SUB_BEAM) && make lint

latte-lint:
cd $(SUB_MAILER) && make latte-lint

vet:
cd $(SUB_BEAM) && make vet

Expand Down

0 comments on commit 10b6d42

Please sign in to comment.