[Golang][client] ineffectual assignment in client.go / client.mustache
Created by: grokify
Description
client.go
and client.mustache
has an ineffectual assignment that triggers a Go Report Card ineffassign error.
Specifically, the following assignment is never used:
if err != nil {
expires = now
}
because it is immediately followed by:
expires = now.Add(lifetime)
client.mustache
:
client.go
(Petstore sample):
openapi-generator version
3.0.3
OpenAPI declaration file content or url
Command line used for generation
$ bin/go-petstore.sh
Steps to reproduce
Generate client.
Error is seen in Go Report Card which uses ineffassign
.
An example is here:
https://goreportcard.com/report/github.com/grokify/go-stackexchange#ineffassign
Related issues/PRs
https://github.com/OpenAPITools/openapi-generator/pull/466
Suggest a fix/enhancement
If an error is encountered, lifetime
should not be valid so we can use the following:
lifetime, err := time.ParseDuration(maxAge + "s")
if err != nil {
expires = now
} else {
expires = now.Add(lifetime)
}
Technically, the following can be used as well since an error will result in a lifetime
duration of 0s
but it requires a bit more to understand, and it's better to not rely on a value not mean to be used. This is essentially what is happening now without the extra if.
lifetime, _ := time.ParseDuration(maxAge + "s")
expires = now.Add(lifetime)