create <route>
nexler create <route>
Scaffolds a route inside an existing app — a leading / is what tells Nexler this is a route rather than a resource keyword like app/store/service. Generates a handler, service, store, and model file grouped under module[/submodule]. If the route already exists, this instead adds only the newly-requested methods (or missing layers) to it rather than erroring.
| Flag | Default | Description |
|---|---|---|
| -module | required | Top-level group this route belongs to, e.g. purchase. |
| -submodule | "" | Nested group, e.g. verify. |
| -file | package name | Base file name for the generated handler/service/store/model files. Naming a file that doesn't exist yet in an already-scaffolded package creates a genuine second handler+model file pair for this invocation's method(s), instead of appending to the original file. |
| -name | package name | Overrides the identifier base for handler function names, Request/Response types, and OperationIDs (not the file/package location, which stays -module/-submodule-derived). Needed when adding a second, distinct route to an already-scaffolded package whose identifiers would otherwise collide with the first route's. |
| -service | "" | Reuse an existing service package as module[/submodule]; "none" skips generating a service entirely (stop at handler + model). |
| -store | "" | Reuse an existing store package the same way; "none" skips it. |
| -dir | "." | Path to the app directory (must contain go.mod). |
| -protected | false | Require auth (wraps in middleware.RequireAuth, registers in routes/protected instead of routes/public). On a later invocation, applies only to the newly-added method(s). |
| -methods | GET | Comma-separated HTTP methods: GET, POST, PUT, PATCH, DELETE. OPTIONS is automatic and always 200 OK. |
| -body | json | Request body shape for non-GET methods: json, form, or multipart. |
| -response | json | json (response.JSON, {"data": …} envelope), html (response.HTML, renders an editable template), or raw (response.JSONRaw, no envelope). |
| -layout | shared | Only for -response html: shared reuses templates/html/shared/layout.html; module gives this route its own layout copy. |
| -own-register | false | Combined with a not-yet-existing -file and a required -name, scaffolds an independent second resource in the package instead of folding into its existing Register — see below. |
| -callable | false | Marks the new method(s) as tasks another service (e.g. a workflow engine) may run on a caller's behalf: their openapi.Register call gets Callable: true, which core.SyncTasks copies into core_tasks. Like -protected, it only applies to the method(s) this invocation adds. Not prompted for. |
A route's URL can carry named path parameters — /admin/user/{id}/profile, or a trailing {name...} catch-all (Go 1.22+ ServeMux wildcards). Every generated handler decodes them via request.DecodePath, matched to your Request struct by the same json tag convention as query/body fields, and they're documented as OpenAPI path parameters automatically. A literal ? or # in the route is rejected — use a path parameter instead.
Handler function names, Request/Response types, and OperationIDs are derived from -module/-submodule + HTTP verb, never the URL path — so adding a second, distinct route under the same -module/-submodule as an existing one (different path, overlapping verb) fails fast with an error naming the colliding identifier(s), instead of silently generating duplicate/broken code. Pass -name to disambiguate.
-own-register goes a step further than a plain second -file: instead of that new file's method(s) still being wired into the package's one existing Register function (Go only allows one func Register per package), it becomes its own fully independent resource — its own Register<name> function, own middleware/openapi imports, own service/store/model files — wired into the aggregator with an additional call alongside the package's existing one, e.g. adminproviders.Register(mux) then adminproviders.RegisterSms(mux), both from one shared import. Useful when two resources genuinely belong in the same package (shared permission scope, shared helpers) but each needs its own full CRUD route set. A later nexler create <route> targeting that same -file again (e.g. adding a method) correctly finds and extends its own Register<name>, without -own-register needing to be repeated. Off by default — every existing -file/-name combination keeps behaving exactly as before.
nexler create /purchase/verify -module purchase -submodule verify -methods GET,POST -body json -protected nexler create /home -module home -response html nexler create /purchase/new -module purchase -submodule verify -methods POST -name New nexler create /admin/providers/sms -module admin -submodule providers -file sms -name Sms -own-register -protected