Fixes+Chores: avoid de-referencing nil ptrs + lint

- Avoid referencing conditions we know are false/true

 - Avoid using name of imported package as variable

 - Avoid broken (see list item 1) if else statement in `ipservice.go` by refactoring to switch statement

 - When assigning a pointer value to a variable along with an error, check that error before referencing that pointer. Thus avoiding de-referencing a nil and causing a panic.
  *** This item is the most important ***

 - Standard gofmt package sorting + linting; This includes fixing comment starts for go doc

 - Explicit non-handling of unhandled errors where appropriate (assigning errs to _ to reduce linter screaming)

 - Export ErrExpired in `netcache` package so that we can properly reference it using `errors.Is` instead of using `strings.Contains` against an `error.Error()` value
This commit is contained in:
kayos@tcp.direct
2022-12-06 20:11:20 -08:00
parent 0d9b47f212
commit e878e4820a
17 changed files with 219 additions and 188 deletions

View File

@@ -21,7 +21,7 @@ type CValue struct {
Expiration time.Time `json:"expiration"`
}
var errExpired = fmt.Errorf("expired")
var ErrExpired = fmt.Errorf("expired")
// Set - sets a value to a key in db
func Set(k string, newValue *CValue) error {
@@ -45,7 +45,7 @@ func Get(k string) (*CValue, error) {
return nil, err
}
if time.Now().After(entry.Expiration) {
return nil, errExpired
return nil, ErrExpired
}
return &entry, nil