service

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetectSchemaDir

func DetectSchemaDir(dir string) string

DetectSchemaDir resolves the sphere schema directory relative to dir when it exists, so generators can match service names against real ent schema types. Empty is returned outside a project (or when no known schema directory is found), in which case the generators fall back to inflection-based naming.

func GenServiceGolang

func GenServiceGolang(name, pkg, mod, schemaDir string) (string, error)

GenServiceGolang generates a service implementation skeleton for the entity named by `name`. When schemaDir points at an existing sphere schema directory, the name is matched against the real schema types first (see NormalizeEntity); otherwise inflection is used.

func GenServiceProto

func GenServiceProto(name, pkg, schemaDir string) (string, error)

GenServiceProto generates a CRUD service proto for the entity named by `name`. When schemaDir points at an existing sphere schema directory, the name is matched against the real schema types first (see NormalizeEntity); otherwise inflection is used.

func ResolveSchemaEntity

func ResolveSchemaEntity(name, schemaDir string) (string, bool)

ResolveSchemaEntity maps a CLI-supplied service name to the canonical ent schema type name present in schemaDir. The name is matched case- and separator-insensitively against both the raw name and its singular form. It returns ok=false when no schema type matches.

func SchemaEntityTypes

func SchemaEntityTypes(schemaDir string) []string

SchemaEntityTypes scans a sphere project's schema directory and returns the sorted list of ent schema type names declared there (types embedding ent.Schema). It returns an empty slice when the directory does not exist or cannot be parsed, so callers outside a project degrade gracefully.

Types

type Entity

type Entity struct {
	// TypeName is the PascalCase entity/type name (e.g. KeyValueStore).
	TypeName string
	// FileName is the lower-cased name used for ent sub-package imports
	// (e.g. keyvaluestore).
	FileName string
	// FieldName is the snake_case proto/JSON field name of the entity
	// (e.g. key_value_store).
	FieldName string
	// Route is the kebab-case route segment (e.g. key-value-store).
	Route string
	// Plural is the inflected plural of TypeName (e.g. KeyValueStores).
	Plural string
	// PluralField is the snake_case plural field name used in list responses
	// (e.g. key_value_stores).
	PluralField string
}

Entity is the canonicalised entity identity shared by the proto and Go generators. All names are derived from a single PascalCase TypeName so the output stays consistent regardless of the separator style of the --name flag.

func NormalizeEntity

func NormalizeEntity(name, schemaDir string) (Entity, bool)

NormalizeEntity resolves a CLI-supplied service name to an Entity.

When schemaDir names an existing sphere schema directory, the name is matched case- and separator-insensitively against the real ent schema types there (also trying the singular form), so "--name keyvaluestore" resolves to the KeyValueStore schema instead of producing the un-compilable "Keyvaluestore". The second return value reports whether such a schema-backed match happened.

When no schema match is possible (outside a project, or the name does not correspond to a schema), the name is PascalCased through inflection. Separator-rich inputs (snake_case, kebab-case) split reliably; a single undivided lowercase word is treated as one word (so "keyvaluestore" would produce "Keyvaluestore" — pass the schema-separated form, or run inside the project, to disambiguate).

Jump to

Keyboard shortcuts

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