2022-09-12 22:47:27 +00:00
|
|
|
{{/* The line below tells Intellij/GoLand to enable the autocompletion based on the *gen.Graph type. */}}
|
|
|
|
{{/* gotype: entgo.io/ent/entc/gen.Graph */}}
|
|
|
|
|
|
|
|
{{ define "has_id" }}
|
|
|
|
|
|
|
|
{{/* Add the base header for the generated file */}}
|
|
|
|
{{ $pkg := base $.Config.Package }}
|
|
|
|
{{ template "header" $ }}
|
|
|
|
import "github.com/google/uuid"
|
|
|
|
{{/* Loop over all nodes and implement the "HasID" interface */}}
|
|
|
|
{{ range $n := $.Nodes }}
|
2022-12-10 05:57:57 +00:00
|
|
|
{{ if not $n.ID }}
|
|
|
|
{{/* If the node doesn't have an ID field, we skip it. */}}
|
|
|
|
{{ continue }}
|
|
|
|
{{ end }}
|
|
|
|
{{/* The "HasID" interface is implemented by the "ID" method. */}}
|
2022-09-12 22:47:27 +00:00
|
|
|
{{ $receiver := $n.Receiver }}
|
2022-12-10 05:57:57 +00:00
|
|
|
func ({{ $receiver }} *{{ $n.Name }}) GetID() {{ $n.ID.Type }} {
|
2022-09-12 22:47:27 +00:00
|
|
|
return {{ $receiver }}.ID
|
|
|
|
}
|
|
|
|
{{ end }}
|
|
|
|
|
|
|
|
{{ end }}
|