nullify

package
v0.111.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 28, 2026 License: Apache-2.0 Imports: 1 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package nullify is the canonical "I checked and found nothing" helper for enrichers writing a verdict/classification column to Postgres.

Observed live across a 2026-07-05 audit of the domain_* enrichment tables (go-url-categorizer-api/docs/audit/2026-07-05-enricher-quality-audit.md): at least six enrichers write a literal placeholder string ("unknown", "Unknown", "n/a", "none", "") into a text column instead of leaving it NULL when no real signal was found. That's not six unrelated bugs, it's the same missing call in six places — every downstream consumer (API filters, dashboards, TRL scoring) has to special-case "is this value real or a fossilized default" per column instead of trusting SQL NULL to mean "not determined."

Use StringOrNil at the boundary where an enricher's Go struct is about to be marshaled/written: replace

row.Verdict = classify(evidence) // may return "unknown"

with

row.Verdict = nullify.StringOrNil(classify(evidence))

so the column round-trips as NULL, not the string "unknown".

This package intentionally does NOT address the sibling bug where a numeric column writes a sentinel 0 for "not checked" (see domain_price_range in the audit above) — that's a struct-shape fix (use *int / sql.NullInt64 fields), not a value-transform one, and needs a per-service decision about what a genuine zero means.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsPlaceholder

func IsPlaceholder(s string) bool

IsPlaceholder reports whether s (after trimming whitespace and lowercasing) is one of the known "no real signal" placeholder strings. Enrichers can use this to gate a write ("only persist this field if it's not a placeholder") without allocating.

func StringOrNil

func StringOrNil(s string) *string

StringOrNil returns nil when s is a known placeholder (per IsPlaceholder), otherwise returns a pointer to the trimmed string. Assign the result directly to a `*string` struct field that a jsonb/text column marshals from.

Example

Store NULL, not the string "unknown", when a check found nothing.

package main

import (
	"fmt"

	"github.com/baditaflorin/go-common/nullify"
)

func main() {
	fmt.Println(nullify.StringOrNil("N/A") == nil)
	fmt.Println(*nullify.StringOrNil("  nginx "))
}
Output:
true
nginx

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL