Review frozen and platform-specific APIs
Review frozen and platform-specific APIs
Frozen packages may still be maintained but are not accepting new features; net/rpc is one example. The syscall package varies across operating systems and new code should usually prefer portable os, io and net APIs or appropriate x/sys packages for low-level operations. Frozen is not the same as removed or guaranteed secure.
package main
import ( "errors" "fmt" "os" "syscall")
func main() { err := &os.PathError{Op: "open", Path: "fixture", Err: syscall.ENOENT} fmt.Println(errors.Is(err, os.ErrNotExist)) fmt.Println(errors.Is(err, os.ErrPermission))}Use errors.Is with portable sentinel errors instead of comparing OS-specific numeric errno values. The synthetic PathError shows how wrapping preserves error classification. Actual error availability and behavior vary across platforms; check target-specific documentation and tests.
Expected output:
truefalseInspect a frozen package without network access
package main
import ( "fmt" "net/rpc")
type Args struct{ N int }type Doubler struct{}
func (Doubler) Double(a Args, out *int) error { *out = a.N * 2; return nil }func main() { s := rpc.NewServer() fmt.Println(s.RegisterName("Doubler", Doubler{}) == nil)}net/rpc exposes registered exported methods with specific signatures and is frozen. Registration tests the shape, not communication, authentication or security. Avoid exposing this toy service. For OS-specific code use files such as worker_linux.go and worker_windows.go or //go:build constraints, with matching public interfaces. Cross-build and test on each target; external x/sys packages require a pinned module dependency.
Expected output:
trueTry it locally
Create a wrapped permission error and classify it with errors.Is. Print true for permission and false for not-exist.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Specialized library 07: Review frozen and platform-specific APIs
Check the lesson objective before moving on.
What does frozen mean for net/rpc?
How should portable missing-file handling be written?