Go For Laravel Developers
ASecurityWrite Go for Laravel and PHP developers, review existing Go for PHP habits, and explain Go errors in PHP terms, in Laravel for Go or any other Go project. Use when writing Go for a PHP developer, reviewing Go for PHP habits (truthy checks, default arguments, copied arrays, null and ??, throw/try-catch, associative arrays, strlen and substr, (int) casts, enums, inheritance, __toString, Collection chains, use() closures, static state, Composer and PSR-4), or explaining a compiler, go vet, nil m...
- 3 stars
- 0 votes
- 0 copies
- 0 views
- Added December 3, 2026
Works with
Security analysis
100/100Pro scans all 18 files and shows the line behind each finding
npx -y skills add airshell/laravel-php-to-rust-go --skill go-for-laravel-developers --agent claude-codeAre you the author of Go For Laravel Developers?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/airshell-go-for-laravel-developers)---
name: go-for-laravel-developers
description: "Write Go for Laravel and PHP developers, review existing Go for PHP habits, and explain Go errors in PHP terms, in Laravel for Go or any other Go project. Use when writing Go for a PHP developer, reviewing Go for PHP habits (truthy checks, default arguments, copied arrays, null and ??, throw/try-catch, associative arrays, strlen and substr, (int) casts, enums, inheritance, __toString, Collection chains, use() closures, static state, Composer and PSR-4), or explaining a compiler, go vet, nil map, nil error, slice aliasing, data race or goroutine error in PHP terms. Maps each PHP behaviour to Go and shows what the PHP habit does there: a compile error, a panic, a wrong value or a race. Every Go code block compiles with Go 1.27 and every PHP block runs with assertions on PHP 8.4; behaviour claims were checked by tests. For porting Laravel framework code use laravel-php-to-go; for auditing a Laravel for Go app use laravel-go-audit."
license: MIT
metadata:
author: airshell
version: "1.0.0"
goVersion: "1.27 (tested 1.27.3)"
phpVersion: "8.3+ (tested 8.4)"
---
# Go for Laravel Developers
Write Go for Laravel and PHP developers, review existing Go for PHP habits, and explain Go in terms of the PHP they already know. Contains 29 rules across 9 categories. Every Go code block compiles with Go 1.27 (standard library only) and is a file of a test lab; every PHP block runs with assertions on PHP 8.4; Laravel Collection behaviour was checked on `illuminate/collections` 13.45. Quotes come from the Go specification, the Go memory model and the standard library's documentation, and each "Tested" note records what a test asserted.
**Version 1.0.0 (December 2026).** This skill is about the language. For the framework (routes, models, queues, views) in Laravel for Go, use `laravel-php-to-go` (porting), `laravel-go-best-practices` (writing new code) and `laravel-go-audit` (auditing). Some examples use recent features (`sync.WaitGroup.Go` from Go 1.25, `errors.AsType` from Go 1.26, methods with their own type parameters from Go 1.27); the rules say so.
## When to Apply
- Writing Go for a PHP or Laravel developer, in Laravel for Go or any other Go project: follow the rules so the code does not repeat the PHP habits they describe
- Reviewing Go for PHP habits: ignored errors, `strconv.Atoi` results dropped, `len()` on user text, maps iterated into output, slices returned after `append` or sorted in place, package-level maps written by handlers, goroutines nobody waits for, typed nil errors. Name the rule for each finding
- Explaining a compiler, `go vet` or runtime error (unused variable, non-boolean condition, assignment to entry in nil map, concurrent map writes, a data race) to someone who knows PHP
## How to Use It
- **Writing**: before writing code that PHP handles differently (null checks, arrays, strings, numbers, errors, collections, concurrency), read the relevant rules in the Quick Map below and follow their Correct examples
- **Reviewing**: run `go vet ./...`, `gofmt -l .` and `go test -race ./...`, then read the code for the habits in the Quick Map; a match is a place to read, not a finding
- **Explaining**: find the PHP habit in the Quick Map and answer from its rule. When the compiler or `go vet` rejects code, start with `mind-compiler-and-vet`: the error often marks a bug PHP would only have shown at runtime
Each rule shows the PHP behaviour (run on PHP 8.4), what changes in Go with quotes from the official docs, Go written with the PHP habit and what it does, and the idiomatic version.
## Quick Map
| PHP | Go | Rule |
|---|---|---|
| Errors at runtime, PHPStan | Compile errors and `go vet` | `mind-compiler-and-vet` |
| Fresh state per request (PHP-FPM) | A long-running process; package variables are shared | `mind-long-running-process` |
| `if ($x)`, default arguments | `bool` conditions only; options structs | `mind-syntax-habits` |
| `$b = $a` copies arrays, shares objects | Structs copy; pointers share | `val-structs-copy-and-pointers` |
| Arrays copied on write | Slices share a backing array; `append` may or may not copy | `val-slices-share-backing-arrays` |
| `use ($x)` copies the value | Closures share the variable; one per iteration since Go 1.22 | `val-closures-and-loop-variables` |
| `null`, `??`, `isset` | Zero values, `nil`, the `ok` idiom, pointers for "missing" | `types-nil-and-zero-values` |
| Associative and list arrays | Structs, maps and slices | `types-php-arrays-to-slices-maps-structs` |
| Arrays keep insertion order | Map iteration order is not specified | `types-maps-are-unordered` |
| `strlen`, `substr`, `mb_*` | Bytes; `utf8.RuneCountInString`, ranging runes | `types-strings-bytes-runes` |
| `(int) "abc"` is `0`, int overflow becomes float | `strconv.Atoi` errors; integers wrap; conversions cut | `types-numbers-and-conversions` |
| PHP 8.1 enums, `match` | Typed constants with `iota`; `switch` is not exhaustive | `types-enums-with-constants` |
| `throw`, `try`/`catch` | Returned `error` values, checked at each call | `err-exceptions-to-errors` |
| `instanceof`, `getPrevious()` | `%w`, `errors.Is`, `errors.As` | `err-wrapping-is-and-as` |
| Uncaught exception ends one request | `panic` ends the program unless recovered in the same goroutine | `err-panic-and-recover` |
| `return null` for "no error" | A nil pointer in an `error` is not `nil` | `err-nil-interface-is-not-nil` |
| `implements`, large interfaces | Implicit, small interfaces declared where used | `iface-implicit-small-interfaces` |
| `extends`, overriding methods | Embedding; no virtual dispatch | `iface-embedding-not-inheritance` |
| `@template` docblocks, `mixed` | Type parameters and constraints | `iface-generics` |
| `__toString`, `JsonSerializable`, `__get` | `fmt.Stringer`, `json.Marshaler`, struct tags; no magic | `iface-magic-methods-to-interfaces` |
| `collect()->map()->filter()` | Loops, `slices` and `maps` | `coll-collection-to-loops-and-slices` |
| `sortBy`, `groupBy`, `unique` | `slices.SortStableFunc`, maps of slices, sort then `slices.Compact` | `coll-sort-group-unique` |
| One request at a time per process | Goroutines that must be waited for, errors collected | `conc-goroutines-wait-and-errors` |
| No shared memory between requests | Mutexes, atomics, channels; `-race` | `conc-shared-state-and-races` |
| `set_time_limit`, request timeouts | `context.Context` cancellation and deadlines | `conc-context-cancellation` |
| Composer, `composer.json`, `composer.lock` | Go modules, `go.mod`, `go.sum`, `/v2` import paths | `mod-composer-to-go-modules` |
| Namespaces, PSR-4, `private` | Packages are directories; capital letters export; `internal/` | `mod-namespaces-to-packages` |
| PHPStan, Pint | `go vet`, `gofmt` | `tool-vet-fmt-lint` |
| PHPUnit, Pest | `go test`, table tests, `t.Run`, `t.Cleanup`, `-race` | `tool-tests` |
## Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|----------|----------|--------|--------|
| 1 | Mindset | CRITICAL | `mind-` |
| 2 | Values and Pointers | CRITICAL | `val-` |
| 3 | Types | CRITICAL | `types-` |
| 4 | Errors | CRITICAL | `err-` |
| 5 | Interfaces and Generics | HIGH | `iface-` |
| 6 | Collections | HIGH | `coll-` |
| 7 | Concurrency | HIGH | `conc-` |
| 8 | Modules and Packages | MEDIUM | `mod-` |
| 9 | Tooling | MEDIUM | `tool-` |
## Quick Reference
### 1. Mindset (CRITICAL)
- `mind-compiler-and-vet` - Unused variables and imports do not compile; `go vet` catches format mistakes PHP would print
- `mind-long-running-process` - Package-level state is shared by every request; a variable written by handlers races
- `mind-syntax-habits` - No truthiness, `:=` shadowing, no default arguments
### 2. Values and Pointers (CRITICAL)
- `val-structs-copy-and-pointers` - Assignment and value receivers copy the struct
- `val-slices-share-backing-arrays` - Sorting or appending to a slice can change the caller's data
- `val-closures-and-loop-variables` - Closures share variables; the `go` line in `go.mod` decides loop-variable behaviour
### 3. Types (CRITICAL)
- `types-nil-and-zero-values` - Writing to a nil map panics; `""` and missing look the same without a pointer
- `types-php-arrays-to-slices-maps-structs` - Structs for records; JSON numbers in `map[string]any` are `float64`
- `types-maps-are-unordered` - Sort the keys before output that needs an order
- `types-strings-bytes-runes` - `len` counts bytes; index and slice by rune for text
- `types-numbers-and-conversions` - Integer division truncates, overflow wraps, `strconv.Atoi` rejects what `(int)` accepts
- `types-enums-with-constants` - Typed constants; `go vet` does not report a missing `switch` case
### 4. Errors (CRITICAL)
- `err-exceptions-to-errors` - Check every returned error; ignored errors compile
- `err-wrapping-is-and-as` - `==` fails after wrapping; use `errors.Is` and `errors.As`
- `err-panic-and-recover` - A panic not recovered in its own goroutine ends the whole program
- `err-nil-interface-is-not-nil` - A nil `*MyError` returned as `error` is not `nil`
### 5. Interfaces and Generics (HIGH)
- `iface-implicit-small-interfaces` - Accept small interfaces, return structs
- `iface-embedding-not-inheritance` - An embedded type's method never calls the outer type's "override"
- `iface-generics` - Type parameters instead of `any` and type assertions
- `iface-magic-methods-to-interfaces` - `String()`, `MarshalJSON`, tags; unexported fields are skipped by `encoding/json`
### 6. Collections (HIGH)
- `coll-collection-to-loops-and-slices` - Loops and `slices`; `slices.DeleteFunc` changes the caller's slice
- `coll-sort-group-unique` - `slices.SortFunc` is not guaranteed stable; groups come back unordered
### 7. Concurrency (HIGH)
- `conc-goroutines-wait-and-errors` - Wait with `sync.WaitGroup` and collect errors
- `conc-shared-state-and-races` - Concurrent map writes are fatal; run tests with `-race`
- `conc-context-cancellation` - Take `ctx` first and stop when it is done
### 8. Modules and Packages (MEDIUM)
- `mod-composer-to-go-modules` - `go.mod` and `go.sum`; v2+ modules need `/v2` in the import path
- `mod-namespaces-to-packages` - Directories are packages; capital letters export; `internal/` and import cycles are build errors
### 9. Tooling (MEDIUM)
- `tool-vet-fmt-lint` - `go vet` and `gofmt -l` (which exits 0); third-party linters are optional
- `tool-tests` - Table tests with `t.Run`; `t.Cleanup` for parallel subtests; `-count=1` skips the cache
## How to Use the Rules
Read individual rule files for the PHP behaviour, the differences, and the incorrect and correct Go:
```
rules/types-nil-and-zero-values.md
rules/val-slices-share-backing-arrays.md
rules/err-exceptions-to-errors.md
```
Each rule contains:
- The PHP behaviour, as a script that runs with assertions on PHP 8.4
- What changes, with quotes from the Go specification, memory model or standard library docs, and what the tests asserted
- Incorrect Go that follows the PHP habit
- Correct Go
- References
## Full Compiled Document
For the complete guide with all rules expanded: `AGENTS.md`
Files in this skill
- README.md
- SKILL.md
- rules/_sections.md
- rules/_template.md
- rules/coll-collection-to-loops-and-slices.md
- rules/coll-sort-group-unique.md
- rules/conc-context-cancellation.md
- rules/conc-goroutines-wait-and-errors.md
- rules/conc-shared-state-and-races.md
- rules/err-exceptions-to-errors.md
- rules/err-nil-interface-is-not-nil.md
- rules/err-panic-and-recover.md
- rules/err-wrapping-is-and-as.md
- rules/iface-embedding-not-inheritance.md
- rules/iface-generics.md
- rules/iface-implicit-small-interfaces.md
- rules/iface-magic-methods-to-interfaces.md
- rules/mind-compiler-and-vet.md
Attribution
Related skills
View all in development →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.