copygen

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2021 License: MIT Imports: 2 Imported by: 0

README

Example: Automatch

The automatch examples uses the automatcher to match three models with varying level of depth:

// 0
type Account // domain
    // 1
    ID      int
    Name    string
    Email   string
            // 2
    User    domain.DomainUser
                UserID   int
                Username string    
// 0
type User    // models
    // 1
    UserID    int
    Username  string
              // 2
    UserData  models.UserData
                  Options map[string]interface{}
                  // 3
                  Data    models.Data
                        ID      int
// 0            
type Account // models
    // 1
    ID       int
    Name     string
    Password string
    Email    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

Specify a depth-level of two for the subfields of domain.Account. Specify a depth-level of 1 for the models.User field. Keep in mind that not specifying a depth-level for models.Account would result in the same outcome, as Copygen uses a maximum depth by default.

// Copygen defines the functions that will be generated.
type Copygen interface {
	// depth domain.Account 2
	// depth models.User 1
	ModelsToDomain(models.Account, models.User) *domain.Account
}

Output

copygen -yml path/to/yml

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

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

import (
	"github.com/switchupcb/copygen/examples/automatch/domain"
	"github.com/switchupcb/copygen/examples/automatch/models"
)

// ModelsToDomain copies a Account, User to a Account.
func ModelsToDomain(tA *domain.Account, fA models.Account, fU models.User) {
	// Account fields
	tA.User.Username = fU.Username
	tA.User.UserID = fU.UserID
	tA.Email = fA.Email
	tA.Name = fA.Name
	tA.ID = fA.ID

}

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 ModelsToDomain

func ModelsToDomain(tA *domain.Account, fA models.Account, fU models.User)

ModelsToDomain copies a Account, User to a 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