style: restructure cli and registry packages #43
Reference in New Issue
Block a user
Delete Branch "style/move-cli"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description
The
internal/clipackage had grown to contain both CLI utilities (source/destination I/O) and registry-level abstractions (repr, conversion, engine, marshaler).This PR separates concerns by moving registry types into
internal/registryand keeping only CLI I/O types ininternal/cli.It also simplifies several core abstractions and aligns naming conventions.
Source,Destinationfrominternal/configtointernal/cli.Repr,Conversion,Engine,Process,Codecfrominternal/clitointernal/registry.codec.Codec[T, U]tocodec.Codec[T](string-based marshaling only).codec.Conversion[T, U]as a function type alias.engine.Engine[T]from an interface to a function type.Engine.Load()+Process.Set()into a singleEngine.Load(Repr)call.Saccharine2Lambdafrom a struct to standalone conversion functions.MustAddMarshaler,MustAddEngine,MustAddConversions) with generic free functions (RegisterCodec,RegisterEngine,RegisterConversion).internal/configpackage (Config,GetLogger,ParseFromArgs).pkg/emitterpackage.Id()toID()per Go conventions.checkPublicInterfacelint rule.reduce_one.gotoreduce_once.go.Decisions
Engine[T]is now a function type (func(T) (Process[T], error)) rather than an interface, since the only method wasLoad.Codec[T, U]was split intoCodec[T](string marshaling) andConversion[T, U](type-to-type conversion function), which better reflects how they are actually used.RegisterCodec,RegisterEngine,RegisterConversion) instead of methods onRegistry, enabling type inference at the call site.Benefits
config,emitter) reduces maintenance burden.ID, codecs,reduce_once) are more idiomatic.Checklist
<type>/<description>).