Help us shape the future of Go! Take the 2026 Go Developer Survey

analyzer

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContentIsUnmodified

func ContentIsUnmodified(onDisk []byte) bool

ContentIsUnmodified reports whether an on-disk write-once file still matches the content that last produced it.

Algorithm:

  1. Find the marker. No marker → not ours → modified (preserve).
  2. Strip the marker line from the body.
  3. SHA-256 the remaining bytes and compare against the stored hash.

Returning true means "safe to overwrite with a new template". Returning false means "user edited this file — leave it alone" (unless --force).

func ExcludeFlowPipelines added in v0.2.0

func ExcludeFlowPipelines(report *Report, names []string)

ExcludeFlowPipelines removes named NFlow pipelines and their route-derived action contracts from an analysis report. This is useful when runtime flags conditionally mount a development pipeline that is not part of the default production API surface.

func ReadNFlowSource

func ReadNFlowSource(path string) (string, error)

ReadNFlowSource is an exported helper used by the SDK generation command's integration tests to exercise the exact Flow preprocessing path.

func RenderEnhancedReport

func RenderEnhancedReport(report *Report, actionFilter string) string

func RenderSummaryTable

func RenderSummaryTable(report *Report, actionFilter string) string

func StampContent

func StampContent(content []byte, path string) []byte

StampContent returns content with a nexssp:hash marker appended. The marker carries the SHA-256 of content itself, so ContentIsUnmodified can later verify the file hasn't been touched since we wrote it.

The path determines the comment style (markdown vs everything else).

Types

type ActionContract

type ActionContract struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	ReqTypeName string `json:"req_type"`
	ResTypeName string `json:"res_type"`
	// FlowSchemaDriven marks an NFlow route whose HTTP boundary is declared
	// with request/response-schema modifiers. Missing modifiers remain absent
	// instead of being inferred from the called Go action.
	FlowSchemaDriven bool               `json:"flow_schema_driven,omitempty"`
	ReqSchemaName    string             `json:"request_schema,omitempty"`
	ResSchemaName    string             `json:"response_schema,omitempty"`
	ReqType          TypeRef            `json:"req_type_ref,omitempty"`
	ResType          TypeRef            `json:"res_type_ref,omitempty"`
	Method           string             `json:"method"`
	Path             string             `json:"path"`
	RouteSource      string             `json:"route_source,omitempty"`
	TypeSource       string             `json:"type_source,omitempty"`
	Transports       []TransportBinding `json:"transports,omitempty"`
	Tags             []string           `json:"tags"`
	Scope            string             `json:"scope"`
	Idempotent       bool               `json:"idempotent"`
	Timeout          time.Duration      `json:"timeout"`
	RetryMax         int                `json:"retry_max"`
	CacheTTL         time.Duration      `json:"cache_ttl,omitempty"`
	RateLimit        string             `json:"rate_limit,omitempty"`
	ConcurrencyLimit int32              `json:"concurrency_limit,omitempty"`
	Permissions      []string           `json:"permissions"`
	Roles            []string           `json:"roles"`
	Features         []string           `json:"features"`
	ReqFields        []FieldContract    `json:"req_fields"`
	ResFields        []FieldContract    `json:"res_fields"`
	SourceFile       string             `json:"source_file"`
	SourceLine       int                `json:"source_line"`
	Streaming        bool               `json:"streaming,omitempty"`
	Raw              bool               `json:"raw,omitempty"`

	// Multipart is true when at least one request field is declared with a
	// `form:"..."` tag on a []byte — the client method is emitted as
	// multipart/form-data instead of application/json.
	Multipart bool `json:"multipart,omitempty"`

	// BlobResponse is true when the action's declared response type is
	// `[]byte`. The generated client returns a Blob.
	BlobResponse bool `json:"blob_response,omitempty"`

	BudgetMicros    int64         `json:"budget_micros,omitempty"`
	RequiresAuth    bool          `json:"requires_auth,omitempty"`
	RateLimitBurst  int           `json:"rate_limit_burst,omitempty"`
	BreakerFailures int           `json:"breaker_failures,omitempty"`
	BreakerCooldown time.Duration `json:"breaker_cooldown,omitempty"`
	HITLPrompt      string        `json:"hitl_prompt,omitempty"`
	HITLOptions     []string      `json:"hitl_options,omitempty"`
	HITLTriggers    []string      `json:"hitl_triggers,omitempty"`
	SuccessStatus   int           `json:"success_status,omitempty"`

	BackoffStrategy   string        `json:"backoff_strategy,omitempty"`
	BackoffBase       time.Duration `json:"backoff_base,omitempty"`
	BackoffMax        time.Duration `json:"backoff_max,omitempty"`
	RetryPredicate    string        `json:"retry_predicate,omitempty"`
	Priority          string        `json:"priority,omitempty"`
	CacheKey          string        `json:"cache_key,omitempty"`
	Audit             bool          `json:"audit,omitempty"`
	IdempotencyHeader string        `json:"idempotency_header,omitempty"`
	Deprecated        bool          `json:"deprecated,omitempty"`
	DeprecatedSince   string        `json:"deprecated_since,omitempty"`
	DeprecatedUse     string        `json:"deprecated_use,omitempty"`
}

type Analyzer

type Analyzer struct {
	// contains filtered or unexported fields
}

func New

func New() *Analyzer

func (*Analyzer) FindStruct

func (a *Analyzer) FindStruct(nameOrQualified string) (StructDefinition, bool)

func (*Analyzer) ScanFlowFiles

func (a *Analyzer) ScanFlowFiles(root string)

type DSLConfig

type DSLConfig = dsl.Config

type Diagnostic

type Diagnostic struct {
	Severity   DiagnosticSeverity `json:"severity"`
	Rule       string             `json:"rule"`
	Message    string             `json:"message"`
	Suggestion string             `json:"suggestion,omitempty"`
	File       string             `json:"file,omitempty"`
	Line       int                `json:"line,omitempty"`
	Action     string             `json:"action,omitempty"`
}

func ValidatePublicAPI added in v0.2.0

func ValidatePublicAPI(report *Report) []Diagnostic

ValidatePublicAPI reports contracts that the generated public SDK cannot type safely. It is intentionally separate from general analysis so generic OPS reports and non-SDK workflows keep their existing behavior.

type DiagnosticSeverity

type DiagnosticSeverity string
const (
	SeverityError   DiagnosticSeverity = "ERROR"
	SeverityWarning DiagnosticSeverity = "WARNING"
)

type EnumDefinition

type EnumDefinition struct {
	TypeName   string
	Package    string
	Domain     string
	Qualified  string
	SourceFile string
	Values     []EnumValue
}

EnumDefinition captures a Go string-backed enum type and its values.

Convention recognised by the analyzer:

type TaskStatus string
const (
    StatusPending TaskStatus = "PENDING"
    StatusRunning            = "RUNNING"  // inherits the type
)

Only exported type names and exported const names are captured. The captured TypeName is the Go type; ConstName is the identifier; Value is the literal string. Order of Values matches declaration order.

type EnumValue

type EnumValue struct {
	ConstName string
	Value     string
}

type FieldContract

type FieldContract struct {
	Name          string `json:"name"`
	Key           string `json:"key"`
	Type          string `json:"type"`
	Required      bool   `json:"required"`
	Nullable      bool   `json:"nullable,omitempty"`
	JSONOmitEmpty bool   `json:"-"`
	Validation    string `json:"validation,omitempty"`
	RawTags       string `json:"raw_tags,omitempty"`

	// Multipart marks a field that must be transported as a file part in
	// a multipart/form-data request. Set by the analyzer when a []byte field
	// carries a `form:"..."` tag.
	Multipart bool `json:"multipart,omitempty"`
}

type FlowHTTPRoute

type FlowHTTPRoute struct {
	Pipeline      string `json:"pipeline"`
	Method        string `json:"method"`
	Path          string `json:"path"`
	SuccessStatus int    `json:"success_status,omitempty"`
	SourceFile    string `json:"source_file,omitempty"`
	SourceLine    int    `json:"source_line,omitempty"`
}

FlowHTTPRoute describes a route declared by an .nflow @pipeline modifier. Pipeline is the compiled Flow resolver name (for example, pipeline.agents_list).

type GeneratedFile

type GeneratedFile struct {
	Path      string
	Content   []byte
	Overwrite bool
}

func GenerateTypeScriptAPISDK added in v0.2.0

func GenerateTypeScriptAPISDK(report *Report) []GeneratedFile

GenerateTypeScriptAPISDK emits DTOs reachable from routed public actions only. It excludes unrelated structs that were exposed by package/file conventions.

func GenerateTypeScriptSDK

func GenerateTypeScriptSDK(report *Report) []GeneratedFile

GenerateTypeScriptSDK produces the full generated tree for ui/src/lib/.

Three categories of output, distinguished by GeneratedFile.Overwrite:

Overwrite: true    always regenerated
Overwrite: false   written once, then preserved (edit freely)

Ownership map (paths relative to ui/src/lib/):

_gen/api/*                 generated
_gen/stores/{entities,forms,streams,system}/*   generated
_gen/stores/index.ts       generated
_gen/index.ts              generated
_gen/stores/runtime/*      write-once
api.ts                     write-once (merge barrel)
custom/*                   write-once (extension points)

Anything outside these paths is yours — the generator never touches it.

type PackageInfo

type PackageInfo struct {
	ImportPath string
	Domain     string
	Package    string
}

type Report

type Report struct {
	ScannedFiles   int                         `json:"scanned_files"`
	Actions        []ActionContract            `json:"actions"`
	FlowHTTPRoutes []FlowHTTPRoute             `json:"flow_http_routes,omitempty"`
	FlowSchemas    map[string]StructDefinition `json:"flow_schemas,omitempty"`
	Structs        map[string]StructDefinition `json:"structs"`
	Enums          map[string]EnumDefinition   `json:"enums,omitempty"`
	Diagnostics    []Diagnostic                `json:"diagnostics"`
	Stats          ReportStats                 `json:"stats"`
}

func Analyze

func Analyze(root string) (*Report, error)

Analyze scans a single root. Kept for callers that pass exactly one path.

func AnalyzeAll

func AnalyzeAll(roots ...string) (*Report, error)

AnalyzeAll scans one or more roots. Extra roots are additive; each root's local-dependency expansion (`replace` directives in go.mod) still runs, so multi-module workspaces work out of the box.

Files visited under more than one root are parsed exactly once (path-based dedupe via seenFiles), and Flow DSL files found under any root are merged in scan order.

func (*Report) FindStruct

func (r *Report) FindStruct(nameOrQualified string) (StructDefinition, bool)

type ReportStats

type ReportStats struct {
	TotalActions    int `json:"total_actions"`
	PublicActions   int `json:"public_actions"`
	InternalActions int `json:"internal_actions"`
	SystemActions   int `json:"system_actions"`
	TotalStructs    int `json:"total_structs"`
	TotalEnums      int `json:"total_enums"`
	ErrorCount      int `json:"error_count"`
	WarningCount    int `json:"warning_count"`
}

type StoreCluster

type StoreCluster struct {
	Noun         string
	List         *ActionContract
	Get          *ActionContract
	Create       *ActionContract
	Update       *ActionContract
	Delete       *ActionContract
	EntityType   string
	EntityStruct StructDefinition
	IDField      string
}

type StructDefinition

type StructDefinition struct {
	Name       string          `json:"name"`
	Package    string          `json:"package"`
	Domain     string          `json:"domain"`
	ImportPath string          `json:"import_path,omitempty"`
	Qualified  string          `json:"qualified"`
	SourceFile string          `json:"source_file"`
	Fields     []FieldContract `json:"fields"`
	IsExposed  bool            `json:"is_exposed"`
	IsIgnored  bool            `json:"is_ignored"`
	CustomName string          `json:"custom_name,omitempty"`
	TargetFile string          `json:"target_file,omitempty"`
}

type StructKey

type StructKey struct {
	Domain  string
	Package string
	Name    string
}

type TransportBinding

type TransportBinding = dsl.TransportBinding

type TypeRef

type TypeRef struct {
	ImportPath string `json:"import_path,omitempty"`
	Domain     string `json:"domain,omitempty"`
	Package    string `json:"package,omitempty"`
	Name       string `json:"name"`
}

func (TypeRef) String

func (t TypeRef) String() string

Directories

Path Synopsis
Package dsl contains OPS's compatibility parser for older action-oriented route manifests.
Package dsl contains OPS's compatibility parser for older action-oriented route manifests.

Jump to

Keyboard shortcuts

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