scan

package
v0.0.0-...-58acc5f Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package scan はGoテンプレートをスキャンしてスキーマを推論します。

このパッケージは text/template のASTを解析し、テンプレート内のフィールド参照を追跡して スキーマ木を構築します。推論される型は以下の通り:

  • 葉のフィールド: string
  • range で使用されるフィールド: []struct{...}
  • index で使用されるフィールド: map[string]string

スキャン結果は internal/typing パッケージで型解決されます。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Field

type Field struct {
	Name     string
	Kind     Kind
	Elem     *Field            // Slice/Map の要素
	Children map[string]*Field // Struct の子
}

Field は推論スキーマ木のノードです。

type Kind

type Kind int

Kind は推論されたフィールド種別を表します。

const (
	KindString Kind = iota
	KindStruct
	KindSlice
	KindMap
)

type Schema

type Schema struct {
	Fields map[string]*Field
}

Schema はトップレベル(Params直下)のフィールド集合です。

func ScanTemplate

func ScanTemplate(src string) (Schema, error)

ScanTemplate は Go テンプレートを AST 解析して、.(ドット)スコープを追跡して フィールド参照からスキーマ木を推論します。 既定では葉はすべて string として扱い、 range は []struct{} (子フィールドがあれば) または []string (なければ), index は map[string]string を推論します。