Sha256: 9be1d84ef187f2ba726b4902e95b1d5fc2e4ae9c475e43a822888894e8914160

Contents?: true

Size: 1.61 KB

Versions: 2

Compression:

Stored size: 1.61 KB

Contents

<%- package "model" -%>

<%- source_file.types.each do |type| -%>
<%-   if !type.fields.empty? -%>
<%-
        type.field_type_packages.each do |pkg|
          import(PACKAGE_FOR_IMPORT[pkg] || pkg)
        end
-%>
type <%= type.name %> struct {
<%-     if type.goon -%>
	<%= type.id_definition %>
<%-       if type.parent -%>
<%-         import "google.golang.org/appengine/datastore" -%>
	ParentKey *datastore.Key `datastore:"-" goon:"parent" json:"-"`
<%-       end -%>
<%-     end -%>
<%-     type.fields.each do |field| -%>
	<%= field.definition %>
<%-     end -%>
}
<%-   elsif type.base -%>
type <%= type.name %> <%= type.base %>

<%-     if type.enum_items -%>
const (
<%-       type.enum_items.each do |item| -%>
  <%= item.camelize %> <%= type.name %> = <%= item.inspect %>
<%-       end -%>
)
<%-     end -%>
<%-   end -%>

<%- end -%>

<%- source_file.types.select(&:store?).each do |model| -%>
func (m *<%= model.name %>) PrepareToCreate() error {
<%- if model.fields.any?{|f| f.name == "CreatedAt"} -%>
	if m.CreatedAt.IsZero() {
		m.CreatedAt = time.Now()
	}
<%- end -%>
<%- if model.fields.any?{|f| f.name == "UpdatedAt"} -%>
	if m.UpdatedAt.IsZero() {
		m.UpdatedAt = time.Now()
	}
<%- end -%>
	return nil
}

func (m *<%= model.name %>) PrepareToUpdate() error {
<%- if model.fields.any?{|f| f.name == "UpdatedAt"} -%>
	m.UpdatedAt = time.Now()
<%- end -%>
	return nil
}

<%-   if model.parent -%>
<%-     import "context" -%>
func (m *<%= model.name %>) Parent(ctx context.Context) (*<%= model.parent %>, error) {
  parentStore := &<%= model.parent %>Store{}
	return parentStore.ByKey(ctx, m.ParentKey)
}
<%-   end -%>

<%- end -%>

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
goa_model_gen-0.6.0 lib/goa_model_gen/templates/model.go.erb
goa_model_gen-0.5.0 lib/goa_model_gen/templates/model.go.erb