modules

package
v0.26.1 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Sources embed.FS

Sources embeds module.go and all module subdirectory source files needed to reconstruct the modules package tree in an external module cache. Test files are excluded.

Functions

func CleanRuntime

func CleanRuntime(src string) string

CleanRuntime strips //go:build directives, the package declaration, and import blocks from Go source so it can be emitted into a generated program.

func CollectGoDeps

func CollectGoDeps(moduleNames []string) []string

CollectGoDeps returns all GoDeps from the named modules (deduped, sorted).

func CollectGoReplace added in v0.15.0

func CollectGoReplace(moduleNames []string) []string

CollectGoReplace returns all GoReplace directives from the named modules (deduped).

func IsModule

func IsModule(name string) bool

IsModule returns true if name is a registered module.

func LookupFunc

func LookupFunc(module, funcName string) (string, bool)

LookupFunc resolves a module function to its Go runtime wrapper name.

func Names

func Names() []string

Names returns sorted names of all registered modules.

func Register

func Register(m *Module)

Register adds a module to the global registry.

Types

type ArgType

type ArgType int

ArgType represents the expected type of a function argument.

const (
	String ArgType = iota
	Int
	Float
	Bool
	Any
)

type FuncDef

type FuncDef struct {
	// Name is the rugo function name (e.g. "exec").
	Name string
	// Args lists the expected typed arguments. The wrapper will convert
	// interface{} args to these types before calling the implementation.
	Args []ArgType
	// ArgNames provides display names for arguments in documentation.
	// When empty, generic names (arg0, arg1, ...) are used.
	ArgNames []string
	// Variadic, when true, passes remaining args beyond Args as ...interface{}.
	// The implementation function should accept extra ...interface{} as its last parameter.
	Variadic bool
	// Doc is the documentation string shown by `rugo doc`.
	Doc string
}

FuncDef describes a function exposed by a module. The implementation function must be named <module>_<Name> in runtime.go and use typed parameters matching Args (e.g. func os_exec(command string) interface{}).

type Module

type Module struct {
	// Name is the rugo import name (e.g. "os", "http", "conv").
	Name string
	// Type is the Go struct type name used as the method receiver (e.g. "OS", "HTTP").
	Type string
	// Funcs describes the functions this module exposes.
	Funcs []FuncDef
	// GoImports lists additional Go imports this module needs beyond the base set.
	GoImports []string
	// GoDeps lists Go module dependencies (require lines for go.mod) that the
	// generated program needs. Each entry should be "module version", e.g.
	// "github.com/gosimple/slug v1.15.0". Only needed for external modules
	// that depend on third-party Go packages.
	GoDeps []string
	// GoReplace lists replace directives for go.mod. Each entry should be
	// "module => path" or "module version => path", e.g.
	// "github.com/rubiojr/rugo => /path/to/local/rugo".
	GoReplace []string
	// Runtime is the Go source for the struct type and its methods (from embedded runtime.go).
	Runtime string
	// DispatchEntry, when set, names the module function that triggers dispatch.
	// The compiler generates a typed map (rugo_<mod>_dispatch) mapping user-defined
	// function names to their Go implementations, which the module's runtime uses
	// to route commands to handlers.
	DispatchEntry string
	// DispatchTransform maps a handler name from source (e.g. the string argument
	// in web.get("/", "handler") or cli.cmd("db:seed", "...")) to the Go function
	// name used in the dispatch map. When nil, the identity transform is used
	// (handler name == function name). Only functions whose transformed names match
	// a def function are included in the dispatch map.
	DispatchTransform func(string) string
	// DispatchMainOnly, when true, restricts the dispatch map to functions
	// defined in the main file (i.e. rugofn_* only), excluding namespaced
	// functions from required modules.
	DispatchMainOnly bool
	// Doc is the module-level documentation shown by `rugo doc`.
	Doc string
}

Module represents a Rugo stdlib module that can be imported.

func Get

func Get(name string) (*Module, bool)

Get returns a registered module by name.

func (*Module) FullRuntime

func (m *Module) FullRuntime() string

FullRuntime returns the complete runtime source: the struct type and methods from Runtime plus auto-generated wrappers that handle interface{} conversion.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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