dto

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package dto — table-driven generic-based DTO transfers for kaname (parity with services/vpc/internal/dto/base.go).

Layout:

  • dto/base.go (this file): generic Interface, RegTransfer / FindTransfer, FromTo helper, Transfer entry-point with type-set generic constraint (Transferrable).
  • dto/toproto/*.go: implementations of Interface[domain.X, *iamv1.X] + init()-time registration in the registry.

Usage (caller-site):

var dst *iamv1.Account
if err := dto.Transfer(dto.FromTo(d, &dst)); err != nil { ... }
return anypb.New(dst)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegTransfer

func RegTransfer[F any, T any](impl Interface[F, T])

RegTransfer регистрирует трансфер F → T под ключом reflect.TypeFor[tag[F,T]].

func Transfer

func Transfer[V Transferrable](dto V) error

Transfer запускает Perform() на dto. Единственная публичная entry-point.

Types

type DTO

type DTO[F any, T any] struct {
	// contains filtered or unexported fields
}

DTO — pair-объект, который собирает FromTo(): хранит src + указатель на dst и реализует Perform() через registry-lookup.

func FromTo

func FromTo[F any, T any](src F, dst *T) *DTO[F, T]

FromTo — конструктор DTO. Применяется в caller-site.

func (*DTO[F, T]) Perform

func (d *DTO[F, T]) Perform() error

Perform выполняет лукап Interface[F,T] и пишет результат в *dto.dst.

type Fn

type Fn[F any, T any] func(F) (T, error)

Fn — adapter: обычная Go-функция как Interface.

func (Fn[F, T]) Transfer

func (f Fn[F, T]) Transfer(src F) (T, error)

type Interface

type Interface[F any, T any] interface {
	Transfer(F) (T, error)
}

Interface — generic transfer-функтор F → T.

func Fn2Face

func Fn2Face[F any, T any](fn func(F) (T, error)) Interface[F, T]

Fn2Face оборачивает функцию в Interface — синтаксический helper для init().

type Transferrable

Transferrable — closed type-set generic constraint for Transfer(). Accepts only those `*DTO[F,T]` pairs that are **explicitly** registered in the type-set below. New pairs are added here as new domain↔proto mappings are introduced.

Directories

Path Synopsis
Package toproto — DTO transfer implementations domain/repo → proto for kaname.
Package toproto — DTO transfer implementations domain/repo → proto for kaname.

Jump to

Keyboard shortcuts

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