codegen

package
v0.22.1 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(w io.Writer, pkgName string, svc *ServiceInfo) error

Generate writes the .gen.go file for the service to w.

func GenerateFile

func GenerateFile(outputPath string, pkgName string, svc *ServiceInfo) error

GenerateFile writes the .gen.go file to the specified path. outputPath is the full path for the output .gen.go file.

func GenerateSchema

func GenerateSchema(typ types.Type, comments map[string]string) map[string]any

GenerateSchema produces a JSON Schema map[string]any from a go/types Type. It handles: string, int/uint variants, float variants, bool, slices, maps, structs, pointers, any. For structs: reads json tags for field names and omitempty, reads doc comments from the AST for field descriptions, reads //tool:enum annotations for enum values.

func SnakeCase

func SnakeCase(s string) string

SnakeCase converts PascalCase to snake_case. Examples: "GetWeather" -> "get_weather", "ID" -> "id", "UserID" -> "user_id".

Types

type MethodInfo

type MethodInfo struct {
	GoName        string            // Go method name (e.g., "GetWeather")
	ToolName      string            // tool name: //tool:name value, or snake_case(GoName)
	Desc          string            // from //tool:desc annotation
	ReqType       types.Type        // the request parameter type (2nd param, after ctx)
	RespType      types.Type        // the first return type
	FieldComments map[string]string // key: "TypeName.FieldName" -> combined doc comment + //tool: annotations
}

MethodInfo holds metadata for a single tool method.

type ServiceInfo

type ServiceInfo struct {
	Name    string // from //tool:service annotation
	PkgPath string // full package import path
	Methods []MethodInfo
}

ServiceInfo holds the parsed service metadata.

func ParseService

func ParseService(filename string) (*ServiceInfo, error)

ParseService parses a Go source file and extracts the first //tool:service annotated interface. Returns ServiceInfo with all tool methods and their parameter/return types resolved via go/types.

Jump to

Keyboard shortcuts

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