copygen

package
v0.0.0-...-429302c Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2022 License: GPL-3.0, MIT-0 Imports: 2 Imported by: 0

README

Example: Manual

The manual example uses manual mapping to match three models.

./domain/domain.go

// Package domain contains business logic models.
package domain

// Account represents a user account.
type Account struct {
	ID     int
	UserID string
	Name   string
	Other  string // The other field is not used.
}

./models/model.go

// Package models contains data storage models (i.e database).
package models

// Account represents the data model for account.
type Account struct {
	ID       int
	Name     string
    Email    string
	Password string
}

YML

# Define where the code will be generated.
generated:
  setup: ./setup.go
  output: ../copygen.go

# Templates and custom options aren't used for this example.

Go

The automatcher will match fields from models.Account to domain.Account and the UserID string field to a domain.Account.UserID that has a definition of a string.

// Copygen defines the functions that will be generated.
type Copygen interface {
	Basic(A *models.Account, UserID string) *domain.Account
}

Use pointers to avoid allocations.

Output

copygen -yml path/to/yml

// Code generated by github.com/reedom/copygen
// DO NOT EDIT.

// Package copygen contains the setup information for copygen generated code.
package copygen

import (
	"github.com/reedom/copygen/examples/basic/domain"
	"github.com/reedom/copygen/examples/basic/models"
)

// Basic copies a *models.Account, string to a *domain.Account.
func Basic(tA *domain.Account, fA *models.Account, fs string) {
	// *domain.Account fields
	tA.ID = fA.ID
	tA.UserID = fs
	tA.Name = fA.Name
}

Documentation

Overview

Package copygen contains the setup information for copygen generated code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Basic

func Basic(tA *domain.Account, fA *models.Account, fs string)

Basic copies a *models.Account, string to a *domain.Account.

Types

This section is empty.

Directories

Path Synopsis
Package domain contains business logic models.
Package domain contains business logic models.
Package models contains data storage models (i.e database).
Package models contains data storage models (i.e database).
Package copygen contains the setup information for copygen generated code.
Package copygen contains the setup information for copygen generated code.

Jump to

Keyboard shortcuts

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