diff --git a/.golangci.yml b/.golangci.yml index 94e639e3b..6bb95ab6c 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -25,7 +25,7 @@ linters: - asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers - bidichk # Checks for dangerous unicode character sequences - bodyclose # Checks whether HTTP response body is closed successfully - # - copyloopvar # Detects places where loop variables are copied + - copyloopvar # Detects places where loop variables are copied - decorder # Check declaration order and count of types, constants, variables and functions - dogsled # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f()) - dupl # Tool for code clone detection @@ -35,7 +35,6 @@ linters: - errchkjson # Checks types passed to the json encoding functions. Reports unsupported types and optionally reports occasions, where the check for the returned error can be omitted. - errname # Checks that sentinel errors are prefixed with the `Err` and error types are suffixed with the `Error`. - errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13. - - exportloopref # checks for pointers to enclosing loop variables # - forcetypeassert # finds forced type assertions - gci # Gci control golang package import order and make it always deterministic. - gocheckcompilerdirectives # Checks that go compiler directive comments (//go:) are valid. diff --git a/bundle/client/coap/main.go b/bundle/client/coap/main.go index bb0fed732..a6407e91c 100644 --- a/bundle/client/coap/main.go +++ b/bundle/client/coap/main.go @@ -194,7 +194,7 @@ func updateResource(co *client.Conn, href string, contentFormat int) { if err != nil { updateError(err) } - resp, err := co.Post(context.Background(), href, message.MediaType(contentFormat), bytes.NewReader(b.Bytes())) + resp, err := co.Post(context.Background(), href, message.MediaType(contentFormat), bytes.NewReader(b.Bytes())) //nolint:gosec if err != nil { updateError(err) } @@ -210,7 +210,7 @@ func createResource(co *client.Conn, href string, contentFormat int) { if err != nil { createError(err) } - req, err := co.NewPostRequest(context.Background(), href, message.MediaType(contentFormat), os.Stdin) + req, err := co.NewPostRequest(context.Background(), href, message.MediaType(contentFormat), os.Stdin) //nolint:gosec if err != nil { createError(err) } diff --git a/bundle/client/grpc/main.go b/bundle/client/grpc/main.go index 11659f814..bc83d0dc4 100644 --- a/bundle/client/grpc/main.go +++ b/bundle/client/grpc/main.go @@ -108,7 +108,7 @@ func updateResource(ctx context.Context, client pbGW.GrpcGatewayClient, deviceID resp, err := client.UpdateResource(ctx, &pbGW.UpdateResourceRequest{ ResourceId: commands.NewResourceID(deviceID, href), Content: &pbGW.Content{ - ContentType: message.MediaType(contentFormat).String(), + ContentType: message.MediaType(contentFormat).String(), //nolint:gosec Data: data, }, }) @@ -133,7 +133,7 @@ func createResource(ctx context.Context, client pbGW.GrpcGatewayClient, deviceID resp, err := client.CreateResource(ctx, &pbGW.CreateResourceRequest{ ResourceId: commands.NewResourceID(deviceID, href), Content: &pbGW.Content{ - ContentType: message.MediaType(contentFormat).String(), + ContentType: message.MediaType(contentFormat).String(), //nolint:gosec Data: data, }, }) diff --git a/cloud2cloud-connector/service/deviceSubscription.go b/cloud2cloud-connector/service/deviceSubscription.go index f80f8647c..55cc07ec2 100644 --- a/cloud2cloud-connector/service/deviceSubscription.go +++ b/cloud2cloud-connector/service/deviceSubscription.go @@ -108,7 +108,7 @@ func (s *SubscriptionManager) handleResourcesPublished(ctx context.Context, d Su for _, endpoint := range link.GetEndpoints() { endpoints = append(endpoints, &commands.EndpointInformation{ Endpoint: endpoint.URI, - Priority: int64(endpoint.Priority), + Priority: endpoint.Priority, }) } href := pkgHttpUri.CanonicalHref(trimDeviceIDFromHref(link.DeviceID, link.Href)) @@ -120,7 +120,7 @@ func (s *SubscriptionManager) handleResourcesPublished(ctx context.Context, d Su Interfaces: link.Interfaces, DeviceId: link.DeviceID, Anchor: link.Anchor, - Policy: &commands.Policy{BitFlags: int32(link.Policy.BitMask)}, + Policy: &commands.Policy{BitFlags: commands.ToPolicyBitFlags(link.Policy.BitMask)}, Title: link.Title, SupportedContentTypes: link.SupportedContentTypes, EndpointInformations: endpoints, diff --git a/cloud2cloud-connector/service/publishResource.go b/cloud2cloud-connector/service/publishResource.go index 8646814fe..4b36a8089 100644 --- a/cloud2cloud-connector/service/publishResource.go +++ b/cloud2cloud-connector/service/publishResource.go @@ -14,7 +14,7 @@ func publishResource(ctx context.Context, raClient raService.ResourceAggregateCl for _, endpoint := range link.GetEndpoints() { endpoints = append(endpoints, &commands.EndpointInformation{ Endpoint: endpoint.URI, - Priority: int64(endpoint.Priority), + Priority: endpoint.Priority, }) } href := pkgHttpUri.CanonicalHref(trimDeviceIDFromHref(link.DeviceID, link.Href)) @@ -26,7 +26,7 @@ func publishResource(ctx context.Context, raClient raService.ResourceAggregateCl Interfaces: link.Interfaces, DeviceId: link.DeviceID, Anchor: link.Anchor, - Policy: &commands.Policy{BitFlags: int32(link.Policy.BitMask)}, + Policy: &commands.Policy{BitFlags: commands.ToPolicyBitFlags(link.Policy.BitMask)}, Title: link.Title, SupportedContentTypes: link.SupportedContentTypes, EndpointInformations: endpoints, diff --git a/coap-gateway/coapconv/coapconv.go b/coap-gateway/coapconv/coapconv.go index 7ff762d5c..95186a25b 100644 --- a/coap-gateway/coapconv/coapconv.go +++ b/coap-gateway/coapconv/coapconv.go @@ -89,7 +89,7 @@ func CoapCodeToStatus(code codes.Code, operation Operation) commands.Status { func MakeMediaType(coapContentFormat int32, contentType string) (message.MediaType, error) { if coapContentFormat >= 0 { - return message.MediaType(coapContentFormat), nil + return message.MediaType(coapContentFormat), nil //nolint:gosec } switch contentType { case message.TextPlain.String(): @@ -174,7 +174,7 @@ func NewContent(opts message.Options, body io.Reader) *commands.Content { data, coapContentFormat := GetContentData(opts, body) return &commands.Content{ - ContentType: getContentFormatString(coapContentFormat), + ContentType: GetContentFormatString(coapContentFormat), CoapContentFormat: coapContentFormat, Data: data, } @@ -192,10 +192,9 @@ func GetContentData(opts message.Options, body io.Reader) (data []byte, contentF return data, contentFormat } -func getContentFormatString(coapContentFormat int32) string { +func GetContentFormatString(coapContentFormat int32) string { if coapContentFormat != -1 { - mt := message.MediaType(coapContentFormat) - return mt.String() + return message.MediaType(coapContentFormat).String() //nolint:gosec } return "" } @@ -416,7 +415,7 @@ func NewNotifyResourceChangedRequestsFromBatchResourceDiscovery(deviceID, connec resourceChangedReq := &commands.NotifyResourceChangedRequest{ ResourceId: commands.NewResourceID(deviceID, r.Href()), Content: &commands.Content{ - ContentType: getContentFormatString(ct), + ContentType: GetContentFormatString(ct), CoapContentFormat: ct, Data: data, }, diff --git a/coap-gateway/coapconv/getEncoder.go b/coap-gateway/coapconv/getEncoder.go index 72d15b16e..ae8b35b5a 100644 --- a/coap-gateway/coapconv/getEncoder.go +++ b/coap-gateway/coapconv/getEncoder.go @@ -16,7 +16,7 @@ func GetAccept(opts message.Options) message.MediaType { if err != nil { return message.AppOcfCbor } - return message.MediaType(ct) + return message.MediaType(ct) //nolint:gosec } // GetEncoder returns encoder by accept diff --git a/coap-gateway/service/observation/deviceObserver.go b/coap-gateway/service/observation/deviceObserver.go index cd99da812..4dd94539a 100644 --- a/coap-gateway/service/observation/deviceObserver.go +++ b/coap-gateway/service/observation/deviceObserver.go @@ -363,7 +363,7 @@ func createDiscoveryResourceObserver(ctx context.Context, deviceID string, coapC err := resourcesObserver.addResource(ctx, &commands.Resource{ DeviceId: resourcesObserver.deviceID, Href: resources.ResourceURI, - Policy: &commands.Policy{BitFlags: int32(schema.Observable)}, + Policy: &commands.Policy{BitFlags: commands.ToPolicyBitFlags(schema.Observable)}, }, interfaces.OC_IF_B, etags) if err != nil { resourcesObserver.CleanObservedResources(ctx) diff --git a/coap-gateway/service/observation/deviceObserver_test.go b/coap-gateway/service/observation/deviceObserver_test.go index 45563cc49..9c10c91b8 100644 --- a/coap-gateway/service/observation/deviceObserver_test.go +++ b/coap-gateway/service/observation/deviceObserver_test.go @@ -321,7 +321,7 @@ func testValidateResourceLinks(ctx context.Context, t *testing.T, deviceID strin ResourceTypes: []string{device.ResourceType}, Interfaces: []string{interfaces.OC_IF_BASELINE}, Policy: &commands.Policy{ - BitFlags: int32(schema.Observable | schema.Discoverable), + BitFlags: commands.ToPolicyBitFlags(schema.Observable | schema.Discoverable), }, }, { @@ -330,7 +330,7 @@ func testValidateResourceLinks(ctx context.Context, t *testing.T, deviceID strin ResourceTypes: []string{platform.ResourceType}, Interfaces: []string{interfaces.OC_IF_BASELINE}, Policy: &commands.Policy{ - BitFlags: int32(schema.Observable | schema.Discoverable), + BitFlags: commands.ToPolicyBitFlags(schema.Observable | schema.Discoverable), }, }, } diff --git a/coap-gateway/service/resourceDirectory.go b/coap-gateway/service/resourceDirectory.go index 6deccec75..7a8d9d937 100644 --- a/coap-gateway/service/resourceDirectory.go +++ b/coap-gateway/service/resourceDirectory.go @@ -94,7 +94,7 @@ func parsePublishedResources(data io.ReadSeeker, deviceID string) (wkRd, error) return w, nil } -func PublishResourceLinks(ctx context.Context, raClient raService.ResourceAggregateClient, links schema.ResourceLinks, deviceID string, ttl int32, connectionID string, sequence uint64) ([]*commands.Resource, error) { +func PublishResourceLinks(ctx context.Context, raClient raService.ResourceAggregateClient, links schema.ResourceLinks, deviceID string, ttl int, connectionID string, sequence uint64) ([]*commands.Resource, error) { var validUntil time.Time if ttl > 0 { validUntil = time.Now().Add(time.Second * time.Duration(ttl)) @@ -118,7 +118,7 @@ func PublishResourceLinks(ctx context.Context, raClient raService.ResourceAggreg } func observeResources(ctx context.Context, client *session, w wkRd, sequenceNumber uint64) (coapCodes.Code, error) { - publishedResources, err := PublishResourceLinks(ctx, client.server.raClient, w.Links, w.DeviceID, int32(w.TimeToLive), client.RemoteAddr().String(), sequenceNumber) + publishedResources, err := PublishResourceLinks(ctx, client.server.raClient, w.Links, w.DeviceID, w.TimeToLive, client.RemoteAddr().String(), sequenceNumber) if err != nil { return coapCodes.BadRequest, fmt.Errorf("unable to publish resources for device %v: %w", w.DeviceID, err) } diff --git a/coap-gateway/service/service.go b/coap-gateway/service/service.go index 4975f0e78..2fefdcc2e 100644 --- a/coap-gateway/service/service.go +++ b/coap-gateway/service/service.go @@ -337,7 +337,7 @@ func New(ctx context.Context, config Config, fileWatcher *fsnotify.Watcher, logg ownerCache: ownerCache, subscriptionsCache: subscriptionsCache, - messagePool: pool.New(uint32(config.APIs.COAP.MessagePoolSize), 1024), + messagePool: pool.New(config.APIs.COAP.MessagePoolSize, 1024), logger: logger, tracerProvider: tracerProvider, } diff --git a/device-provisioning-service/service/cloudConfiguration.go b/device-provisioning-service/service/cloudConfiguration.go index cfd486305..466d127de 100644 --- a/device-provisioning-service/service/cloudConfiguration.go +++ b/device-provisioning-service/service/cloudConfiguration.go @@ -40,7 +40,7 @@ func (RequestHandle) ProcessCloudConfiguration(ctx context.Context, req *mux.Mes }, Gateways: coapGateways, ProviderName: cloudCfg.AuthorizationProvider, - SelectedGateway: int32(selectedGateway), + SelectedGateway: int32(selectedGateway), //nolint:gosec }, }) return msg, err diff --git a/device-provisioning-service/service/config.go b/device-provisioning-service/service/config.go index 9f4542a98..e95cf4ad1 100644 --- a/device-provisioning-service/service/config.go +++ b/device-provisioning-service/service/config.go @@ -259,9 +259,9 @@ func HTTPConfigToProto(cfg pkgHttpClient.Config) (*pb.HttpConfig, error) { } return &pb.HttpConfig{ - MaxIdleConns: uint32(cfg.MaxIdleConns), - MaxConnsPerHost: uint32(cfg.MaxConnsPerHost), - MaxIdleConnsPerHost: uint32(cfg.MaxIdleConnsPerHost), + MaxIdleConns: uint32(cfg.MaxIdleConns), //nolint:gosec + MaxConnsPerHost: uint32(cfg.MaxConnsPerHost), //nolint:gosec + MaxIdleConnsPerHost: uint32(cfg.MaxIdleConnsPerHost), //nolint:gosec IdleConnTimeout: cfg.IdleConnTimeout.Nanoseconds(), Timeout: cfg.Timeout.Nanoseconds(), Tls: tls, diff --git a/device-provisioning-service/service/service.go b/device-provisioning-service/service/service.go index e2373f97c..04cf3e6bf 100644 --- a/device-provisioning-service/service/service.go +++ b/device-provisioning-service/service/service.go @@ -176,7 +176,7 @@ func New(ctx context.Context, config Config, fileWatcher *fsnotify.Watcher, logg ctx: ctx, cancel: cancel, - messagePool: pool.New(uint32(config.APIs.COAP.MessagePoolSize), 1024), + messagePool: pool.New(config.APIs.COAP.MessagePoolSize, 1024), store: store, logger: logger, authHandler: optCfg.authHandler, diff --git a/grpc-gateway/pb/README.md b/grpc-gateway/pb/README.md index e61e136bf..50e2e0945 100644 --- a/grpc-gateway/pb/README.md +++ b/grpc-gateway/pb/README.md @@ -1262,7 +1262,7 @@ If true - show UI element, if false - hide UI element | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | | endpoint | [string](#string) | | | -| priority | [int64](#int64) | | | +| priority | [uint64](#uint64) | | | diff --git a/grpc-gateway/pb/doc.html b/grpc-gateway/pb/doc.html index 4f8ab66b5..4dd4ac4d6 100644 --- a/grpc-gateway/pb/doc.html +++ b/grpc-gateway/pb/doc.html @@ -3621,7 +3621,7 @@