Skip to content

Conversation

@raphael
Copy link
Member

@raphael raphael commented Nov 8, 2025

What

  • Fix mains plugin to pass one trailing nil per Files() endpoint when calling the generated HTTP server constructor, avoiding "not enough arguments" compile errors when FILES() DSL is used.
  • Treat services with only Files() endpoints as having HTTP transport so the mains emits the HTTP server wiring.

Why

  • The generated server constructor requires an http.FileSystem argument for each Files() endpoint. The previous mains template always passed a fixed pair of nil arguments (errhandler + formatter), which is insufficient when Files() is present (see Mains Plugin does not work with FILES() DSL #223).

How

  • Count file servers per service from the example http.go via httpcodegen.ServiceData.FileServers and fallback to the design (expr.HTTPServiceExpr.FileServers) when needed.
  • Expose a per-service FileServerNils []int to the mains template and append one nil argument per file server.
  • Consider services with len(FileServers) > 0 as HasHTTP when building mains template data.

Backwards compatibility

  • No change for services without Files() endpoints.

Tests

  • Added TestMainsAddsFileServerNils to assert a service with 3 Files() endpoints results in a New(...) call that ends with 5 consecutive , nil arguments (2 standard + 3 file servers).

Fixes #223

This fixes issue #206 where the testing plugin was generating invalid Go
syntax for method return types. The problem occurred when the result type
was an array or slice - the template was incorrectly placing the pointer
operator before the package qualifier and array brackets.

For example, a method returning []*AccessControl would generate:
  func GetAccessControl(...) (*bff.[]*AccessControl, error)

This is syntactically invalid. The correct syntax should be:
  func GetAccessControl(...) ([]*bff.AccessControl, error)

The fix:
- Added PkgResultRef field to clientMethodData to store the properly
  package-qualified result type reference
- Use Goa's GoFullTypeRef method to generate the package-qualified type
  reference, which correctly handles arrays, maps, primitives, and user
  types
- Updated the client_methods template to use PkgResultRef instead of
  manually constructing the type reference

This leverages Goa's existing codegen infrastructure which properly
handles all type cases including:
- Pointer types: *Result -> *pkg.Result
- Array/slice types: []*Result -> []*pkg.Result
- Map types: map[K]*Result -> map[K]*pkg.Result
- Nested types: []map[K]*Result -> []map[K]*pkg.Result

Fixes #206
@raphael raphael merged commit 8f8fe96 into v3 Nov 8, 2025
5 checks passed
@raphael raphael deleted the mains-files-nils branch November 8, 2025 23:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mains Plugin does not work with FILES() DSL

2 participants