One explicit PATCH input in Laravel Go
Scope
Replace one flat package-backed input data object with an app-owned PATCH boundary. Preserve omitted/null/string distinctions, rules, authorization and response shape. Exclude inferred rules, nested data, casts, lazy properties/includes, dynamic creation, collection wrapping and TypeScript generation. Retain callers needing excluded features. Keep the upstream MIT notice for adapted source.
At the time of writing, the Package Port catalog classified Go's typed request validation and JSON structs as built-in alternatives, without TypeScript generation. Check get-recipe's current port catalog and the actual framework before implementing additional machinery. This guidance has not been exercised in your app; verify it with the checks below.
Source behaviour
src/Concerns/BaseData.php builds the package pipeline for authorization, mapping, injection, validation, defaults and casting. src/DataPipes/ValidatePropertiesDataPipe.php respects the creation strategy; config/data.php defaults to validating requests, not every array passed to creation. Moving a class into a struct does not reproduce its rules or guards.
src/DataPipes/DefaultValuesDataPipe.php checks key presence, then defaults, optional values and nullable fallback. In src/Resolvers/TransformedDataResolver.php, Optional values are omitted while null survives; output names may be mapped. The creation/transformation tests cover optional values. A single Go *string decoded without presence tracking cannot distinguish an absent PATCH field from explicit null.
Implementation
- Inventory the selected class's defaults, normalization, rules, casts, field mapping, authorization, creation/transform methods and all transport/job callers. Capture source-backed fixtures. Select one flat nullable string field; don't silently replace business behavior supplied by an excluded feature.
- Keep the framework's existing size-limited request decoder and error contract. Preserve object shape and key presence before typed binding. Validate the decoder's UTF-8, malformed-body and duplicate-key policy; do not equate standard-library decoder behavior with the framework's. JSON null must not become an empty map or an all-zero struct.
- Use an explicit presence bit plus nullable value, or an app-owned tagged type. Omitted means no operation, null clears, and string assigns. The example deliberately rejects unknown fields and non-string scalars instead of preserving every package cast/default mode. It does not trim or convert empty strings to null; apply the original normalization and field/length rules at the same boundary. Run those rules for direct/job calls too.
- Authorize trusted actor/tenant/resource and editable fields separately. Apply only present allowlisted fields to the authorized record; never mass-bind the input map. Retain the app's expected-version/stale-write policy. Use
db.Transactionand its callback's context for related atomic writes where the existing operation needs it; propagate errors and keep goroutines outside the transaction lifetime. - Build an explicit response projection with deliberate omitted/null semantics. Do not expose internal fields through exported structs or unrestricted includes. Keep the existing error statuses/envelope, post-commit delivery and scoped cache invalidation. No global DTO registry or new storage is needed. After-commit failure does not undo committed data.
Complete pure classifier for an already decoded non-nil JSON object using map[string]any. The caller must first reject non-object JSON/decoder failures. It returns (present, value, error); domain rules, normalization and authorization remain outside it:
import "fmt"
func namePatch(fields map[string]any) (bool, *string, error) {
if fields == nil {
return false, nil, fmt.Errorf("object required")
}
for key := range fields {
if key != "display_name" {
return false, nil, fmt.Errorf("unknown field")
}
}
value, present := fields["display_name"]
if !present || value == nil {
return present, nil, nil
}
text, ok := value.(string)
if !ok {
return false, nil, fmt.Errorf("display_name must be string or null")
}
return true, &text, nil
}
Acceptance checklist
- Starting from
"Ada",{}preserves the stored name, null clears it, and"0"assigns a string. Empty and" Åda "are unchanged by this classifier and follow the endpoint's declared normalization. Reject numbers, booleans, arrays, objects and unknownis_admininput. - Exercise malformed/top-level array/null/oversized JSON through the real request decoder, including duplicate-key policy and renamed fields. Preserve validation error keys/status and explicit response projections.
- Direct, HTTP and queued callers enforce identical required rules/authorization. Denied or cross-tenant input changes neither records nor scoped caches.
- Omitted fields never overwrite stored values. Exercise existing stale-write checks, rollback and post-commit failure without blindly replaying a committed operation. Output omits private data.
- Compare package-backed default/optional/null/transformation fixtures. Retain excluded features and search all package consumers before removal.
Run gofmt, go vet ./..., go test ./..., go test -race ./... and app request/job/resource/database integration tests. Record versions/results and deliberate differences with the change.
Sources
- MIT reference source:
src/Concerns/BaseData.php,src/DataPipes/DefaultValuesDataPipe.php,src/DataPipes/ValidatePropertiesDataPipe.php,src/Resolvers/TransformedDataResolver.php,config/data.php,tests/CreationTest.php, andtests/TransformationTest.php. PreserveLICENSE.md. - Framework source checked:
web/request.goanddb/tx.go. Reconcile metadata with the app's module revision and test its actual input APIs. - Port options: check
get-recipe's current port catalog (sourced from Package Port) at implementation time.