route

package
v1.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 13, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package route is the leaf authority for craftgo's HTTP routes: how a method's final route is assembled (base path + @prefix + method path), the string form of a DSL path, the shape key two colliding routes share, and net/http's pattern-overlap rule. The analyzer, the routes/OpenAPI emitters, and the route-conflict detector all read these — one implementation, so the route the editor diagnoses is byte-for-byte the route the generated server mounts.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PathString

func PathString(p *ast.Path) string

func PatternsConflict

func PatternsConflict(a, b string) bool

patternsConflict reports whether two same-verb mux patterns overlap with neither strictly more specific - the exact condition net/http rejects. It models craftgo's single-segment wildcards (`{name}`): patterns of different segment counts can never overlap, and at each shared position a literal beats a wildcard. The pair conflicts when one is more specific at some segment AND the other is more specific at another (a cross-over), or when they are the same pattern (every segment ties) - i.e. neither side wins outright.

func Resolve

func Resolve(basePath string, svc *ast.ServiceDecl, m *ast.Method) string

ResolveRoute joins the OpenAPI base path, the service's @prefix, and the method's own path into the single absolute route the server registers and the OpenAPI document advertises. Empty segments are dropped, consecutive slashes collapse, the result always begins with '/', and a pathless method falls back to its kebab-cased name ("Ping" → "/ping"). @group is absent on purpose — it nests generated files on disk, never the URL.

This is THE route authority: the analyzer's path checks and every codegen emitter (routes, OpenAPI paths, route-conflict detection) call it, so the route the editor diagnoses is byte-for-byte the route the server mounts.

func ServicePrefix

func ServicePrefix(svc *ast.ServiceDecl) string

decoratorString returns the first string-literal positional arg of `@name(...)` on the service decl, or "" when absent. Used to read `@prefix` and `@group` without depending on codegen helpers.

func Shape

func Shape(route string) string

Shape strips parameter names from a resolved route string, replacing every `{name}` segment with `{}`. Mirrors PathShape but operates on the already-joined route (post-prefix, post-basePath) that resolveMethodPath produces.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL