From d6702a49fa79a78bd0a309878418ca93531c3fe7 Mon Sep 17 00:00:00 2001 From: Jannik C <12862103+masseelch@users.noreply.github.com> Date: Thu, 5 Nov 2020 17:29:56 +0100 Subject: [PATCH] entc/gen: allow users to override the stringer implementation using templates * Update ent.tmpl Fixed a small typo * allow customization of stringer implementation * remove "model/stringer" from ExtendPatterns --- entc/gen/internal/bindata.go | 4 +- entc/gen/template/ent.tmpl | 79 ++++++++++--------- entc/integration/template/ent/pet.go | 16 +--- .../template/ent/template/stringer.tmpl | 43 ++++++++++ 4 files changed, 89 insertions(+), 53 deletions(-) create mode 100644 entc/integration/template/ent/template/stringer.tmpl diff --git a/entc/gen/internal/bindata.go b/entc/gen/internal/bindata.go index 75cad13c5..7cf0344a5 100644 --- a/entc/gen/internal/bindata.go +++ b/entc/gen/internal/bindata.go @@ -910,7 +910,7 @@ func templateDialectSqlUpdateTmpl() (*asset, error) { return a, nil } -var _templateEntTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xa4\x58\x5f\x6f\xe3\xb8\x11\x7f\xb6\x3e\xc5\x9c\xe0\xbd\xb3\x0d\x87\xda\xde\x5b\xb7\x4d\x81\xdc\x26\xdb\x06\x58\xe4\xda\x26\x8b\x3e\x2c\x16\x77\xb4\x34\xb2\xd8\xc8\xa4\x97\xa4\x9c\x04\x82\xbe\xfb\x61\x48\x51\xa6\x6c\x27\x97\xbd\x7b\xb2\x45\xce\xdf\xdf\x0c\x87\x33\x6c\xdb\x6c\x91\xbc\x57\xdb\x27\x2d\xd6\x95\x85\x1f\xdf\xfe\xe5\xaf\x67\x5b\x8d\x06\xa5\x85\x0f\x3c\xc7\x95\x52\xf7\x70\x2d\x73\x06\x17\x75\x0d\x8e\xc8\x00\xed\xeb\x1d\x16\x2c\xb9\xab\x84\x01\xa3\x1a\x9d\x23\xe4\xaa\x40\x10\x06\x6a\x91\xa3\x34\x58\x40\x23\x0b\xd4\x60\x2b\x84\x8b\x2d\xcf\x2b\x84\x1f\xd9\xdb\xb0\x0b\xa5\x6a\x64\x91\x08\xe9\xf6\x3f\x5e\xbf\xbf\xba\xb9\xbd\x82\x52\xd4\x08\xfd\x9a\x56\xca\x42\x21\x34\xe6\x56\xe9\x27\x50\x25\xd8\x48\x99\xd5\x88\x2c\x59\x64\x5d\x97\x24\x6d\x0b\x05\x96\x42\x22\xa4\x1b\x55\x60\x9d\x42\xbf\x3a\xdd\xde\xaf\xe1\xdd\x39\xac\xb8\x41\x98\xb2\xf7\x4a\x96\x62\xcd\xfe\xcd\xf3\x7b\xbe\x46\x22\x6a\x5b\xb0\xb8\xd9\xd6\xdc\x22\xa4\x15\xf2\x02\x75\x0a\xd3\xc0\xbe\xdf\x12\x9b\xad\xd2\x36\x6c\xf9\x2f\x98\x25\x93\xb6\x3d\x03\xcd\xe5\x1a\x61\xba\xe5\xb6\x22\x5d\x53\x76\x2b\x56\xb5\x90\xeb\x6b\x47\x65\x88\x63\x32\x49\x9d\x35\x44\xd2\x75\xa9\xe7\x43\x59\xd0\xde\x3c\x49\xb2\x0c\x68\x9b\xdd\xf0\x0d\x59\x45\x18\x12\x00\xce\x17\x40\x69\x85\x7d\x82\x52\x79\x24\x47\x84\x26\xaf\x70\xc3\x59\x62\x9f\xb6\x87\x3b\x56\x37\xb9\x85\x36\x99\xe4\xce\x69\x18\xb9\xe3\x24\x67\x6a\x23\xac\xe5\x6b\xd3\xbb\x35\xc9\x32\xb8\xbe\xf4\x38\x23\xa9\x65\xc9\xe4\xfa\xd2\x8b\xbd\xbe\x64\x77\xa4\xa3\xeb\xe8\xfb\x41\xd8\x0a\xa6\xec\x42\x4a\x65\xb9\x15\x4a\x1a\xf6\x41\x60\x5d\x18\x76\xeb\xd4\xde\xf1\x35\x13\xe4\xdc\xaf\x6d\x0b\xac\xff\xc5\xda\x60\xff\xd7\xc9\x1b\x48\xc3\xbe\x87\x23\x86\xb4\xf4\x78\x7a\xd9\x1e\x47\xda\x9d\x5a\xee\xa2\x3a\x2d\x47\x42\x06\xc3\xc8\x27\xcf\xf9\x92\x85\x11\x87\x90\x05\x3e\xf6\x7c\xd3\x32\x60\x48\x86\x92\xa6\x73\xe7\xc2\x60\x61\x64\xea\xa4\x0f\x5c\xb0\xc3\xa9\x20\x8c\x2a\x45\x06\x13\x8c\x3b\x5e\x37\x18\x30\x4d\x3d\x71\x2f\x3f\x85\x92\xe8\x99\xf3\xea\x84\x90\xb6\x05\x51\x3a\x7a\x51\xd7\x7c\x55\x13\xcf\x22\x36\x63\x5a\xc6\x41\x11\x25\x48\x65\x9d\x1c\x94\x46\x58\xb1\x1b\xe0\xb6\x7b\x90\x7d\x10\x7e\x37\x19\x0e\xe2\x11\xff\xef\x83\x7f\x55\xac\xd1\x0c\x28\xf8\xaf\xbd\xdb\x1a\x6b\x0f\x7b\x86\x6e\x87\xb2\x57\xd9\x0a\x35\x48\x55\xa0\x09\x47\x7c\xad\xf9\xb6\x62\x5e\xc4\x5d\x40\xcb\x00\xd7\x08\x2b\x14\x72\x0d\x5b\xb5\x6d\xc8\xca\x02\x56\x4f\x47\xe9\xff\x9f\x06\xf5\x13\x3c\x54\x28\x01\xf9\x1a\xf5\x59\xad\x78\x41\x5c\x54\x25\x90\xd2\x77\xe2\xed\x8a\x99\x86\x95\x43\x00\xc8\xd0\xf8\x34\x04\xbf\xcf\xc2\x47\xb6\x80\x8b\xa2\x10\xe4\x16\xaf\x7d\xec\x0c\x58\x05\xbc\x18\xac\x33\x56\x69\xaa\x2c\x85\x16\x3b\xd4\x0c\x5c\x79\xea\x73\x76\xb3\xad\x29\x29\xb7\x5a\x48\x5b\x42\x5a\x08\x5e\x63\x6e\xb3\x37\x26\xf3\xfa\xbd\xc0\x94\xea\x47\x2f\x25\xf0\x8a\x12\x2a\x6e\xee\x82\xbd\x5e\xd4\x70\x1a\x1e\xed\x78\x83\x9d\x8c\xda\x2b\x8c\x6f\x4c\x6c\xf2\x11\x3e\x9e\x27\xe3\x83\x94\x1e\x28\x57\x2a\x8f\xd3\xe2\xa0\xa6\xfd\xb9\x04\x39\xaa\x6f\x5e\xdc\xbe\xc8\x45\x45\x03\x09\x65\x36\x3a\x9f\xf8\xca\xf3\xe9\x69\x43\x09\x25\xc3\xc2\xe1\x3c\x92\x10\x1d\x38\x64\x9f\xa4\xf8\xda\x10\xcf\xe7\x2f\xc3\xc1\x59\x78\x36\x3a\xa0\x83\xc4\xa1\x42\xe1\x51\xf5\x63\x27\xaa\x60\xf8\x9f\x65\x40\x99\x8d\x05\x09\x8b\x41\x14\xb2\x54\x7a\xe3\x70\x74\x00\x6a\xa4\x1b\xc7\x9d\x80\x12\xb8\x63\x74\xc8\x3d\x70\xd3\x4b\x80\x99\x23\xfb\xda\xa0\xb1\x58\xcc\x09\xe6\xf1\xd1\x51\x14\x00\x3a\x3a\xb1\xc6\xcf\x6d\x0b\x35\x4a\x67\xe4\x97\x95\x52\x75\x08\x7a\x0f\xb9\x58\x8e\x60\x7f\x06\xf5\x9f\xf5\x95\x26\xe5\xb6\xd1\xd2\x44\x78\x1f\x20\xdb\x47\x44\x03\x97\x80\x5a\x2b\x4d\xce\xb8\x1b\xa9\x58\xa3\x13\x4e\xee\x10\xf2\xbd\x4b\x87\x3e\xf4\x75\x33\x0a\xcb\x92\xc4\xf5\xd4\xab\xc6\x0e\x02\x5c\x0b\x32\x80\xce\x92\x49\xd9\xc8\x1c\x66\x27\x52\x6d\xfe\xbc\x47\xb3\x39\xcc\xfe\x48\x36\x2c\xbd\x77\x73\x4a\xdf\x89\x28\x01\x59\x04\x39\x21\x3e\x15\x04\xb7\xdb\x0e\x65\x20\x96\x4e\xcb\x9e\xef\x24\x8c\xe7\xe7\x20\x45\xed\xb9\x87\xfa\x4a\x10\x1e\x64\x79\x94\x1b\x87\x40\x2e\x07\xde\x23\xd0\x98\xdf\xf2\xc1\x24\x45\x4b\xf8\xfe\x46\xd9\x0f\xb4\x77\x45\x6e\xb5\x35\x5f\x61\xfd\x0e\x22\xbf\xf7\x6d\x17\xfb\x48\x9b\xde\x83\x2e\xb8\x37\x5c\xaa\x41\xea\x69\xc7\x96\xa4\x2d\xf1\x7c\x87\xea\x3f\x3a\x3f\xbc\x7e\x72\xf5\x9d\xbf\x71\x07\x67\xd3\x2e\x99\x74\x49\xa4\x2c\xfa\xeb\xda\x45\x57\x40\x4f\xd6\xe8\x02\xa9\xbb\xcd\x94\xc4\x83\x0a\xdd\xb6\x47\x15\x78\xe8\x1f\xa7\x1a\x73\xa4\x9b\xc0\x77\x23\xff\x0d\x5f\xfd\x76\x5c\xb0\xe2\x0b\xd5\x5d\xed\x94\x89\xe1\xba\x80\xd4\x5d\x75\xe9\x31\x1a\xc3\x61\x73\xf4\x5d\x07\x5f\x1b\xd4\x02\xcd\x33\xe5\x2c\x2e\x74\x61\x63\x48\xfb\x91\xc1\x5d\x07\x8b\x98\x6a\x1e\x6b\x99\xcd\x21\x4e\x68\x67\xdc\x50\xe3\xf6\x71\x99\x7d\x1f\x4b\x78\x5f\x0b\x94\xb6\xf5\xed\xa8\x4f\x8c\x48\x1b\xf3\xeb\xdd\x9c\xc5\x7a\x0e\x88\xe6\x3e\x7c\x43\xc8\xb2\x0c\x3e\x6d\x0b\x02\x3e\x54\x15\x0e\xab\x46\xd4\x34\x75\x50\x3d\x6c\x68\x93\xaa\x9a\x1b\x1c\xc6\x4e\x67\x19\xdc\x28\x8b\x60\x2b\x6e\x97\xf0\xa4\x1a\x90\x88\x05\x5d\x89\x39\xaf\xeb\x31\xf1\x27\xf9\xa0\xf9\x76\x36\x87\x15\x96\x4a\xa3\xa3\x18\xc4\x6e\xd0\x56\xaa\x58\xfa\x2a\x75\xa0\x26\xe9\xab\x95\x37\x0f\x0b\x28\xb5\xda\x00\x07\xab\xb9\x34\x3c\xa7\xc2\xbd\x04\x2e\x0b\x17\x94\x68\xd1\x31\xe5\x6a\x43\x3d\x19\x16\x54\xbd\xb4\xaa\x6b\xaa\x5e\x3c\xbf\x67\xc9\xab\xe2\xe5\x91\x09\xa1\x62\xfe\xf3\x67\x89\x51\xa0\xfe\x54\x9c\x06\x81\xc7\x51\xea\x43\xe3\x50\x83\xc6\xfd\x98\x30\x54\xd0\x2c\x43\x98\xff\x1e\x2e\xc0\x4b\x8b\x1a\x84\x27\xcc\x6b\x65\xb0\x58\x92\x58\xa3\x3c\x3f\x45\x49\xe2\xa3\x1d\x52\xfe\x41\xd4\x35\xac\x10\xf0\x11\xf3\x86\x60\xb3\x95\x56\xcd\xba\x72\x9a\x7d\x47\x06\x0f\x95\xc8\x2b\xc8\x35\x72\x4f\x30\x42\xfd\xb5\xc0\x86\x6c\x18\xad\x13\x9e\xf6\x71\x09\xea\x9e\x8e\xed\x69\xd4\x58\xdf\x17\xce\x16\xf6\xf1\xd2\xfd\x9d\x27\x54\xc2\xbf\x53\xf7\xee\xdc\x6c\xb9\x14\xf9\x2c\x0d\x83\x6b\xd7\xbd\x3b\x9a\x0b\xa9\x02\x8f\x70\xe2\x61\x42\x4c\xdd\xe9\x98\xbc\xa8\x19\xce\xc1\x3e\xb2\x42\xef\x86\xd8\x1f\x90\xf7\xa1\xbb\xb5\xda\x75\x11\x9b\x6d\x8d\x1b\x94\xd6\x47\xaf\xdc\x58\xe6\x77\x50\xbf\x12\x2b\x4f\x3e\x9b\x53\xab\x46\x12\xdb\x64\xb2\xe3\x7a\x38\xa4\x7e\xd5\xb0\x9f\xfc\x77\x32\xe9\x37\xd8\xff\xb4\xb0\xd8\x33\xa7\xb1\xc8\x19\xb9\x79\x8a\xca\x19\xe7\x0b\xf7\x2c\x15\xc5\xf9\x9b\x5d\xba\x3c\x0a\xc3\xf5\xe5\x7c\x3e\x6a\x16\xa9\x73\x79\x66\xca\xf4\xb3\x57\x3c\x4b\xd1\xdd\x74\xd2\xc0\x25\x8c\x06\xbb\xf3\xbf\x9b\xc0\xf5\x0f\x32\xd7\x5f\x6f\x7e\xf2\x0a\xb7\xdd\xd4\x94\xf1\x34\xf0\xc6\xb0\x37\xd4\xfb\x0f\xc6\x1e\x8d\x83\x71\x17\x30\x1a\x09\x43\x1f\xb0\x0b\x79\x67\x4a\xe8\xba\xbf\xc1\x0e\xbe\x1b\xb5\x00\xaf\xb2\xdc\x99\xbb\xd7\x44\xa5\x69\x5a\xb2\x6b\x73\x27\x36\x08\xb3\x7e\xbe\xfc\x17\x37\xff\x54\x54\xf9\xe7\x41\xfd\x69\xe9\x3b\xf6\xc1\xb5\xa7\x33\x2b\x36\xc8\x2e\x6e\x6e\xaf\xdf\xcf\x23\xf9\x0e\x91\x58\x49\x9f\x75\xdf\xaa\x66\xb1\x3b\x14\xfa\x22\xf9\x28\x51\x5c\x96\x2c\x76\x23\xb3\x86\x3e\x24\xea\x4d\x22\xa9\xdf\x82\xe3\xb7\xc2\x78\x4a\xf6\x10\xd2\x67\xd1\xfc\x83\x60\xbe\xa8\xec\x40\xf2\x4b\x3c\xc7\x80\xee\xa5\x44\x62\x64\x9c\xc5\xc3\xd7\xe1\x9c\x1a\xfe\x8f\x14\xfd\xf4\x64\x71\xf6\xc3\xfc\x87\xf9\x50\xb6\xc2\x76\xa8\x2f\x49\xdf\x70\x99\x5a\xe4\xae\x9f\xda\xd6\x8d\xe6\xf5\xf8\x26\xde\x13\xf8\x5a\xca\x61\xcb\xb5\x71\xc7\xc8\x2f\xab\xf2\xa0\x49\x18\xe6\xce\x81\xed\xf3\x97\x51\x85\x73\x5a\xdd\x4c\x87\x8f\x96\x6c\x9f\x42\x7a\x4b\xb4\xe9\x9e\xc7\xd7\xe4\x17\xe6\xff\xbe\xb7\xdc\x70\xf9\x74\x3c\xfe\x9f\x9e\xef\xa3\x26\xe8\x74\x1d\x8e\x8d\x9e\x83\xbf\x04\x66\x79\xb9\xee\xff\xba\xa9\x83\x5a\xa4\x5f\x04\x19\xe5\xab\xe1\x91\x8c\x7e\xf8\x8d\xd6\x3e\xff\x22\xbe\xf4\x57\x0a\x9c\x43\x5e\xae\xe9\xce\x19\x99\xd3\xb6\xd9\x02\x2e\xf6\xaf\x07\xa4\x64\x8d\x12\x75\xe8\xc4\x10\x2c\x5f\x87\x46\x34\x9e\xe3\xcf\xfc\x73\x98\x7f\x81\x38\x7c\xd2\x8d\x9e\x67\xa2\x97\xbe\xd1\x03\x9f\x93\xf5\xfc\x60\xdd\x3f\x3f\xfe\xdf\x28\xf9\x2e\x75\x8f\x0e\xe9\xaf\x27\x1e\xf5\x4e\x3a\xe0\x1e\xc7\xc8\xfc\xde\x52\x32\xe4\x39\x43\xf7\x0f\x69\xb1\xa1\x77\x7c\xed\x67\x69\x6f\x4d\x74\xfd\xd8\x30\x38\xf7\x43\x24\x2d\xc3\xdb\x3e\x86\xfb\xb7\x3e\x4b\xed\x40\x7a\x96\x0e\x8b\xaf\x32\xde\x75\x4a\x39\x97\xd4\x17\xa9\x1d\x6a\x2d\x8a\x02\x25\x4d\x7a\x4a\xbb\xb7\x79\xff\x02\xc4\x4f\x3d\x0d\xb9\x86\x8d\xe7\x95\x7b\x43\x60\xa7\x9d\x3d\xf1\x28\x44\xf6\xa0\x2c\xba\x2e\xf9\x2d\x00\x00\xff\xff\xe6\x0a\xfa\x6c\x5b\x18\x00\x00") +var _templateEntTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xa4\x59\x5f\x6f\xdc\xb8\x11\x7f\x5e\x7d\x8a\x39\x61\x73\xb7\x6b\xac\xb9\xe9\xbd\x35\xad\x0b\xe4\x12\xa7\x35\x10\xf8\xda\xda\x41\x1f\x82\xe0\x8e\x2b\x8d\x24\xd6\x5a\x72\x43\x52\x6b\x1b\x82\xbe\xfb\x61\x48\x49\x4b\xfd\xb1\xcf\xb9\x7b\xf2\x8a\xe4\xfc\xfb\xcd\xf0\xc7\x21\x5d\xd7\xdb\xb3\xe8\x9d\x3a\x3c\x6a\x91\x17\x16\x7e\x7c\xfd\x97\xbf\x9e\x1f\x34\x1a\x94\x16\x3e\xf0\x04\x77\x4a\xdd\xc1\x95\x4c\x18\xbc\x2d\x4b\x70\x8b\x0c\xd0\xbc\x3e\x62\xca\xa2\xdb\x42\x18\x30\xaa\xd2\x09\x42\xa2\x52\x04\x61\xa0\x14\x09\x4a\x83\x29\x54\x32\x45\x0d\xb6\x40\x78\x7b\xe0\x49\x81\xf0\x23\x7b\xdd\xcd\x42\xa6\x2a\x99\x46\x42\xba\xf9\x8f\x57\xef\x2e\xaf\x6f\x2e\x21\x13\x25\x42\x3b\xa6\x95\xb2\x90\x0a\x8d\x89\x55\xfa\x11\x54\x06\x36\x30\x66\x35\x22\x8b\xce\xb6\x4d\x13\x45\x75\x0d\x29\x66\x42\x22\xc4\x7b\x95\x62\x19\x43\x3b\xba\x3c\xdc\xe5\xf0\xe6\x02\x76\xdc\x20\x2c\xd9\x3b\x25\x33\x91\xb3\x7f\xf3\xe4\x8e\xe7\x48\x8b\xea\x1a\x2c\xee\x0f\x25\xb7\x08\x71\x81\x3c\x45\x1d\xc3\xb2\x13\x3f\x4d\x89\xfd\x41\x69\xdb\x4d\xf9\x2f\x58\x45\x8b\xba\x3e\x07\xcd\x65\x8e\xb0\x3c\x70\x5b\x90\xad\x25\xbb\x11\xbb\x52\xc8\xfc\xca\xad\x32\x24\xb1\x58\xc4\xce\x1b\x5a\xd2\x34\xb1\x97\x43\x99\xd2\xdc\x3a\x8a\xb6\x5b\xa0\x69\x76\xcd\xf7\xe4\x15\x61\x48\x00\xb8\x58\x00\xa5\x15\xf6\x11\x32\xe5\x91\x1c\x2c\x34\x49\x81\x7b\xce\x22\xfb\x78\x18\xcf\x58\x5d\x25\x16\xea\x68\x91\xb8\xa0\x61\x10\x8e\xd3\xbc\x55\x7b\x61\x2d\xcf\x4d\x1b\xd6\x62\xbb\x85\xab\xf7\x1e\x67\x24\xb3\x2c\x5a\x5c\xbd\xf7\x6a\xaf\xde\xb3\x5b\xb2\xd1\x34\xf4\x7d\x2f\x6c\x01\x4b\xf6\x56\x4a\x65\xb9\x15\x4a\x1a\xf6\x41\x60\x99\x1a\x76\xe3\xcc\xde\xf2\x9c\x09\x0a\xee\xd7\xba\x06\xd6\xfe\xc5\xd2\x60\xfb\xd3\xe9\xeb\x97\x76\xf3\x1e\x8e\x10\xd2\xcc\xe3\xe9\x75\x7b\x1c\x69\x76\x69\xb9\xcb\xea\x32\x1b\x28\xe9\x1d\xa3\x98\xbc\xe4\x73\x1e\x06\x12\x42\xa6\xf8\xd0\xca\x2d\xb3\x0e\x43\x72\x94\x2c\x5d\xb8\x10\x7a\x0f\x03\x57\x17\x6d\xe2\x3a\x3f\x9c\x09\xc2\xa8\x50\xe4\x30\xc1\x78\xe4\x65\x85\x1d\xa6\xb1\x5f\xdc\xea\x8f\x21\xa3\xf5\xcc\x45\x35\xa3\xa4\xae\x41\x64\x6e\xbd\x28\x4b\xbe\x2b\x49\xe6\x2c\x74\x63\x99\x85\x49\x11\x19\x48\x65\x9d\x1e\x94\x46\x58\x71\xec\xe1\xb6\x27\x90\x7d\x12\x7e\xb7\x18\x46\xf9\x08\x7f\xb7\xc9\xbf\x4c\x73\x34\x3d\x0a\xfe\xeb\x14\xb6\xc6\xd2\xc3\xbe\x45\x37\x43\xd5\xab\x6c\x81\x1a\xa4\x4a\xd1\x74\x5b\x3c\xd7\xfc\x50\x30\xaf\xe2\xb6\x43\xcb\x00\xd7\x08\x3b\x14\x32\x87\x83\x3a\x54\xe4\x65\x0a\xbb\xc7\x49\xf9\xff\xa7\x42\xfd\x08\xf7\x05\x4a\x40\x9e\xa3\x3e\x2f\x15\x4f\x49\x8a\x58\x02\xa9\x7c\x17\xde\xaf\x50\xa8\x1f\x19\x03\x40\x8e\x86\xbb\xa1\x8b\xfb\xbc\xfb\xd8\x9e\xc1\xdb\x34\x15\x14\x16\x2f\x7d\xee\x0c\x58\x05\x3c\xed\xbd\x33\x56\x69\x62\x96\x54\x8b\x23\x6a\x06\x8e\x9e\xda\x9a\xdd\x1f\x4a\x2a\xca\x83\x16\xd2\x66\x10\xa7\x82\x97\x98\xd8\xed\x2b\xb3\xf5\xf6\xbd\xc2\x98\xf8\xa3\xd5\xd2\xc9\x8a\x0c\x0a\x6e\x6e\x3b\x7f\xbd\xaa\x7e\x37\x3c\xd8\xe1\x04\x9b\xcd\xda\x0b\x9c\xaf\x4c\xe8\xf2\x04\x1f\x2f\xb3\xe5\xbd\x96\x16\x28\x47\x95\xd3\xb2\x18\x71\xda\x9f\x2b\x90\x09\xbf\x79\x75\x27\x92\x0b\x48\x03\x09\x65\x36\xd8\x9f\xf8\xc2\xfd\xe9\xd7\x76\x14\x4a\x8e\x75\x9b\x73\xa2\x21\xd8\x70\xc8\x3e\x49\xf1\xb5\x22\x99\xcf\x5f\xfa\x8d\x73\xe6\xc5\x68\x83\xf6\x1a\x7b\x86\xc2\x09\xfb\xb1\x19\x16\xec\x7e\x6f\xb7\x40\x95\x8d\x29\x29\x0b\x41\x14\x32\x53\x7a\xef\x70\x74\x00\x6a\xa4\x13\xc7\xed\x80\x0c\xb8\x13\x74\xc8\xdd\x73\xd3\x6a\x80\x95\x5b\xf6\xb5\x42\x63\x31\x5d\x13\xcc\xc3\xad\xa3\x28\x01\xb4\x75\x42\x8b\x9f\xeb\x1a\x4a\x94\xce\xc9\x2f\x3b\xa5\xca\x2e\xe9\x2d\xe4\x62\x33\x80\xfd\x09\xd4\x7f\xd6\x97\x9a\x8c\xdb\x4a\x4b\x13\xe0\x3d\x42\xb6\xcd\x88\x06\x2e\x01\xb5\x56\x9a\x82\x71\x27\x52\x9a\xa3\x53\x4e\xe1\x10\xf2\x6d\x48\xe3\x18\x5a\xde\x0c\xd2\xb2\x21\x75\xed\xea\x5d\x65\x7b\x05\xae\x05\xe9\x41\x67\xd1\x22\xab\x64\x02\xab\x99\x52\x5b\x3f\x1d\xd1\x6a\x0d\xab\x3f\x52\x0d\x1b\x1f\xdd\x9a\xca\x77\x21\x32\x40\x16\x40\x4e\x88\x2f\x05\xc1\xed\xa6\x3b\x1a\x08\xb5\xd3\xb0\x97\x9b\x85\xf1\xe2\x02\xa4\x28\xbd\x74\xcf\xaf\x04\xe1\xa8\xca\x83\xda\x18\x03\xb9\xe9\x65\x27\xa0\x31\x3f\xe5\x93\x49\x86\x36\xf0\xfd\xb5\xb2\x1f\x68\xee\x92\xc2\xaa\x4b\xbe\xc3\xf2\x0d\x04\x71\x9f\xda\x2e\xf6\x91\x26\x7d\x04\x4d\x17\x5e\x7f\xa8\x76\x5a\xe7\x03\xdb\x90\xb5\xc8\xcb\x8d\xcd\x7f\x74\x71\x78\xfb\x14\xea\x1b\x7f\xe2\xf6\xc1\xc6\x4d\xb4\x68\xa2\xc0\x58\xf0\xd3\xb5\x8b\x8e\x40\x67\x39\x3a\x45\xea\x6e\xb7\x4a\xe2\x88\xa1\xeb\x7a\xc2\xc0\x7d\xff\xb8\xd4\x98\x20\x9d\x04\xbe\x1b\xf9\x6f\xf7\xd5\x4e\x87\x84\x15\x1e\xa8\xee\x68\xa7\x4a\xec\x8e\x0b\x88\xdd\x51\x17\x4f\xd1\xe8\x37\x9b\x5b\xdf\x34\xf0\xb5\x42\x2d\xd0\x3c\x41\x67\x21\xd1\x75\x13\x7d\xd9\x0f\x1c\x6e\x1a\x38\x0b\x57\xad\x43\x2b\xab\x35\x84\x05\xed\x9c\xeb\x39\xee\x94\x97\xd5\xf7\xa1\x86\x77\xa5\x40\x69\x6b\xdf\x8e\xfa\xc2\x08\xac\x31\x3f\xde\xac\x59\x68\x67\xb4\x68\xed\xd3\xd7\xa7\x6c\xbb\x85\x4f\x87\x94\x80\xef\x58\x85\xc3\xae\x12\x25\xdd\x3a\x88\x0f\x2b\x9a\x24\x56\x73\x17\x87\x61\xd0\xdb\x2d\x5c\x2b\x8b\x60\x0b\x6e\x37\xf0\xa8\x2a\x90\x88\x29\x1d\x89\x09\x2f\xcb\xe1\xe2\x4f\xf2\x5e\xf3\xc3\x6a\x0d\x3b\xcc\x94\x46\xb7\xa2\x57\xbb\x47\x5b\xa8\x74\xe3\x59\x6a\x64\x26\x6a\xd9\xca\xbb\x87\x29\x64\x5a\xed\x81\x83\xd5\x5c\x1a\x9e\x10\x71\x6f\x80\xcb\xd4\x25\x25\x18\x74\x42\x89\xda\x53\x4f\x86\x29\xb1\x97\x56\x65\x49\xec\xc5\x93\x3b\x16\xbd\x28\x5f\x1e\x99\x2e\x55\xcc\x7f\xfe\x2c\x31\x48\xd4\x9f\xca\x53\xaf\x70\x9a\xa5\x36\x35\x0e\x35\xa8\xdc\x1f\xd3\x5d\x2a\xe8\x2e\x43\x98\xff\x1e\x2e\xc0\x33\x8b\x1a\x84\x5f\x98\x94\xca\x60\xba\x21\xb5\x46\x79\x79\xca\x92\xc4\x07\xdb\x97\xfc\xbd\x28\x4b\xd8\x21\xe0\x03\x26\x15\xc1\x66\x0b\xad\xaa\xbc\x70\x96\x7d\x47\x06\xf7\x85\x48\x0a\x48\x34\x72\xbf\x60\x80\xfa\x4b\x81\xed\xaa\x61\x30\x4e\x78\xda\x87\x0d\xa8\x3b\xda\xb6\xf3\xa8\xb1\xb6\x2f\x5c\x9d\xd9\x87\xf7\xee\xe7\x3a\x22\x0a\xff\x4e\xdd\xb9\x7d\x73\xe0\x52\x24\xab\xb8\xbb\xb8\x36\xcd\x9b\xc9\xbd\x90\x18\x78\x80\x13\xef\x6e\x88\xb1\xdb\x1d\x8b\x67\x2d\xc3\x05\xd8\x07\x96\xea\x63\x9f\xfb\xd1\xf2\x68\x7c\xf1\xf5\xbd\x9f\xb1\x5a\xc8\x7c\x70\x37\x5e\x1a\xba\xc8\x3b\x8a\x2a\x2b\xcd\xcb\x61\xd1\x9f\x16\x78\xb7\x39\x1c\xb8\x36\xee\x12\xe3\x87\x55\x36\xda\x8f\x7d\x8b\xd7\x8b\x7d\xfe\x32\x00\xd8\x59\x75\xed\x13\x3e\x58\x62\x80\x25\xc4\x37\xb4\x36\x3e\xc9\xf8\xf0\x9f\x69\xb5\x5b\x1a\xdf\x73\xf9\x38\xed\xb4\xe7\x5b\xe9\x80\x6f\xe6\xcb\x23\x74\x7a\x0d\x1e\xef\x55\x92\xe5\xed\x4f\x77\xc0\x13\x1b\xfd\x22\xc8\x29\x4f\xfa\x13\x1d\x6d\x9f\x19\x8c\x7d\xfe\x45\x7c\x69\xb3\x07\x17\x90\x64\x39\xa5\x77\xe0\x4e\x5d\x53\x57\x7f\x4a\x96\x55\x90\xa3\x44\x4d\xbf\x39\x64\x7b\x4b\x87\x85\xcb\x1b\x88\xfd\xa1\xc4\x3d\x4a\x7f\x19\x6e\xbb\xfc\xf1\xb3\x49\x90\xe6\x66\x5c\x49\xd3\x03\x8c\x4e\x1e\xaf\xff\xa4\xdd\xef\xf2\xd0\xf2\x4b\x4f\x17\xbf\x7e\xb5\x06\xef\x83\x03\xe4\xc8\x75\x4f\xe7\x7e\xd8\xb0\x9f\xfc\x77\xb4\x58\xb4\x33\xec\x7f\x5a\x58\x6c\xc5\xe3\x50\xe9\x8a\x76\xc4\xec\x32\xe7\xa0\xaf\x8e\x55\x2c\xd2\x8b\x57\xc7\x78\x33\xd9\xb2\x57\xef\xd7\xeb\xf6\x8a\x15\xb4\xb9\x33\x4f\x12\x7d\x73\x36\xbc\x79\xbb\xee\x66\xd6\xc9\x0d\x0c\xde\x01\x2e\xfe\x6e\x3a\xb1\x7f\x38\x97\x7d\x3b\xe4\x6f\xea\x4e\x8b\xbb\x40\x9a\x2c\xac\xe9\x57\x86\xbd\xa2\xcb\x62\xef\xf1\xe4\xfd\xa0\x97\x9c\x3c\x22\xf8\xde\x4d\x64\x70\xec\xa8\xca\x64\xd0\x34\x7f\x83\x23\x7c\x37\xe8\x1a\x5f\xe6\xbe\xf7\xf9\x64\x8c\xce\xb3\x65\xc6\xae\xcc\xad\xd8\x23\xac\xda\x47\x89\x7f\x71\xf3\x4f\x45\xed\xc2\xba\xf7\x60\x5e\xff\x91\x7d\x70\x97\x9a\x95\x15\x7b\x64\x6f\xaf\x6f\xae\xde\xad\x43\x0b\x0e\x98\xd0\x4c\x5b\x84\xdf\x6c\xe8\xec\x38\x51\xfb\xbc\xc0\xa0\x6c\x5c\xcd\x9c\x1d\x87\xae\xf5\x2d\x6c\xdb\xd7\x4e\x35\x7f\x13\xa2\xdf\x0c\xe8\x9c\xf6\x3e\xbf\x4f\xe3\xfa\x47\x61\x7d\xd6\xdc\x58\xf7\xb3\x52\x53\x68\x4f\x7a\x42\x45\x72\x50\xd9\xa7\xcf\xc1\xd7\xe0\x63\x60\xed\xa7\x47\x8b\xab\x1f\xd6\x3f\xac\x4f\x4d\x6a\x37\xdf\x11\xd0\xa8\xc5\x1c\x73\x2c\x11\x79\x4b\xb2\xbe\x03\x44\xb0\x3c\xef\xfa\xea\xf0\x59\xe2\xdc\xbf\xee\x3d\x41\xb5\xa7\xd7\xa6\xe0\xe1\x72\xf0\x5e\xe9\x74\x3d\xfd\x4e\xd0\xbe\xa6\xfe\xdf\x28\xf9\x26\x76\x6f\x28\xf1\xaf\x33\x6f\x94\xb3\x01\xb8\xb7\x3e\x72\xbf\xf5\x94\x1c\x79\xca\xd1\xd3\xbb\x60\xe8\xe8\x2d\xcf\xfd\xd3\x80\xf7\x26\x20\x48\xdb\xbd\x03\xb4\x77\x62\x1a\x86\xd7\xed\x39\x79\x7a\xba\xb4\xd4\xdd\xc4\xe7\x71\x3f\xf8\x22\xe7\x5d\xe3\x97\x70\x49\x6d\x9e\x3a\xa2\xd6\x22\x4d\x51\xd2\xc5\x55\x69\xf7\xaf\x06\xff\xa0\xc5\xe7\x5e\xba\x5c\xff\xc9\x93\xc2\x3d\x89\xb0\xf9\x60\x67\xde\xb8\xc8\x1f\x94\x69\xd3\x44\xbf\x05\x00\x00\xff\xff\x12\xa1\x4f\x11\x2a\x19\x00\x00") func templateEntTmplBytes() ([]byte, error) { return bindataRead( @@ -925,7 +925,7 @@ func templateEntTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/ent.tmpl", size: 6235, mode: os.FileMode(420), modTime: time.Unix(1, 0)} + info := bindataFileInfo{name: "template/ent.tmpl", size: 6442, mode: os.FileMode(420), modTime: time.Unix(1, 0)} a := &asset{bytes: bytes, info: info} return a, nil } diff --git a/entc/gen/template/ent.tmpl b/entc/gen/template/ent.tmpl index df61160fa..c591dc4c1 100644 --- a/entc/gen/template/ent.tmpl +++ b/entc/gen/template/ent.tmpl @@ -103,42 +103,7 @@ func ({{ $receiver }} *{{ $.Name }}) Unwrap() *{{ $.Name }} { return {{ $receiver }} } -// String implements the fmt.Stringer. -func ({{ $receiver }} *{{ $.Name }}) String() string { - var builder strings.Builder - builder.WriteString("{{ $.Name }}(") - builder.WriteString(fmt.Sprintf("id=%v", {{ $receiver }}.ID)) - {{- range $i, $f := $.Fields }} - {{- if $f.Sensitive }} - builder.WriteString(", {{ $f.Name }}=") - {{- else }} - {{- $sf := printf "%s.%s" $receiver $f.StructField }} - {{- if $f.Nillable }} - if v := {{ $sf }}; v != nil { - builder.WriteString(", {{ $f.Name }}=") - {{- if and $f.IsTime (not $f.HasGoType) }} - builder.WriteString(v.Format(time.ANSIC)) - {{- else if and $f.IsString (not $f.HasGoType) }} - builder.WriteString(*v) - {{- else }} - builder.WriteString(fmt.Sprintf("%v", *v)) - {{- end }} - } - {{- else }} - builder.WriteString(", {{ $f.Name }}=") - {{- if and $f.IsTime (not $f.HasGoType) }} - builder.WriteString({{ $sf }}.Format(time.ANSIC)) - {{- else if and $f.IsString (not $f.HasGoType) }} - builder.WriteString({{ $sf }}) - {{- else }} - builder.WriteString(fmt.Sprintf("%v", {{ $sf }})) - {{- end }} - {{- end }} - {{- end }} - {{- end }} - builder.WriteByte(')') - return builder.String() -} +{{ template "model/stringer" $ }} {{ $slice := plural $.Name }} // {{ $slice }} is a parsable slice of {{ $.Name }}. @@ -156,6 +121,48 @@ func ({{ $receiver }} {{ $slice }}) config(cfg config) { } {{ end }} +{{/* A template to generate a fmt.Stringer implementation. */}} +{{ define "model/stringer" }} + {{ $receiver := $.Receiver }} + + // String implements the fmt.Stringer. + func ({{ $receiver }} *{{ $.Name }}) String() string { + var builder strings.Builder + builder.WriteString("{{ $.Name }}(") + builder.WriteString(fmt.Sprintf("id=%v", {{ $receiver }}.ID)) + {{- range $i, $f := $.Fields }} + {{- if $f.Sensitive }} + builder.WriteString(", {{ $f.Name }}=") + {{- else }} + {{- $sf := printf "%s.%s" $receiver $f.StructField }} + {{- if $f.Nillable }} + if v := {{ $sf }}; v != nil { + builder.WriteString(", {{ $f.Name }}=") + {{- if and $f.IsTime (not $f.HasGoType) }} + builder.WriteString(v.Format(time.ANSIC)) + {{- else if and $f.IsString (not $f.HasGoType) }} + builder.WriteString(*v) + {{- else }} + builder.WriteString(fmt.Sprintf("%v", *v)) + {{- end }} + } + {{- else }} + builder.WriteString(", {{ $f.Name }}=") + {{- if and $f.IsTime (not $f.HasGoType) }} + builder.WriteString({{ $sf }}.Format(time.ANSIC)) + {{- else if and $f.IsString (not $f.HasGoType) }} + builder.WriteString({{ $sf }}) + {{- else }} + builder.WriteString(fmt.Sprintf("%v", {{ $sf }})) + {{- end }} + {{- end }} + {{- end }} + {{- end }} + builder.WriteByte(')') + return builder.String() + } +{{ end }} + {{/* A template for generating the tag of the Edges struct-field. */}} {{ define "model/edgetags" }}{{ with $.Annotations.Edges.StructTag }}`{{ . }}`{{ else }}`json:"edges"`{{ end }}{{ end }} diff --git a/entc/integration/template/ent/pet.go b/entc/integration/template/ent/pet.go index 5dd7a7788..163430cb1 100644 --- a/entc/integration/template/ent/pet.go +++ b/entc/integration/template/ent/pet.go @@ -8,7 +8,6 @@ package ent import ( "fmt" - "strings" "time" "github.com/facebook/ent/dialect/sql" @@ -128,20 +127,7 @@ func (pe *Pet) Unwrap() *Pet { return pe } -// String implements the fmt.Stringer. -func (pe *Pet) String() string { - var builder strings.Builder - builder.WriteString("Pet(") - builder.WriteString(fmt.Sprintf("id=%v", pe.ID)) - builder.WriteString(", age=") - builder.WriteString(fmt.Sprintf("%v", pe.Age)) - if v := pe.LicensedAt; v != nil { - builder.WriteString(", licensed_at=") - builder.WriteString(v.Format(time.ANSIC)) - } - builder.WriteByte(')') - return builder.String() -} +// custom stringer implementation (in this case none) // Pets is a parsable slice of Pet. type Pets []*Pet diff --git a/entc/integration/template/ent/template/stringer.tmpl b/entc/integration/template/ent/template/stringer.tmpl new file mode 100644 index 000000000..7cc09ecde --- /dev/null +++ b/entc/integration/template/ent/template/stringer.tmpl @@ -0,0 +1,43 @@ +{{ define "model/stringer" }} + {{- if eq $.Name "Pet" }} + // custom stringer implementation (in this case none) + {{ else }} + {{ $receiver := $.Receiver }} + // String implements the fmt.Stringer. + func ({{ $receiver }} *{{ $.Name }}) String() string { + var builder strings.Builder + builder.WriteString("{{ $.Name }}(") + builder.WriteString(fmt.Sprintf("id=%v", {{ $receiver }}.ID)) + {{- range $i, $f := $.Fields }} + {{- if $f.Sensitive }} + builder.WriteString(", {{ $f.Name }}=") + {{- else }} + {{- $sf := printf "%s.%s" $receiver $f.StructField }} + {{- if $f.Nillable }} + if v := {{ $sf }}; v != nil { + builder.WriteString(", {{ $f.Name }}=") + {{- if and $f.IsTime (not $f.HasGoType) }} + builder.WriteString(v.Format(time.ANSIC)) + {{- else if and $f.IsString (not $f.HasGoType) }} + builder.WriteString(*v) + {{- else }} + builder.WriteString(fmt.Sprintf("%v", *v)) + {{- end }} + } + {{- else }} + builder.WriteString(", {{ $f.Name }}=") + {{- if and $f.IsTime (not $f.HasGoType) }} + builder.WriteString({{ $sf }}.Format(time.ANSIC)) + {{- else if and $f.IsString (not $f.HasGoType) }} + builder.WriteString({{ $sf }}) + {{- else }} + builder.WriteString(fmt.Sprintf("%v", {{ $sf }})) + {{- end }} + {{- end }} + {{- end }} + {{- end }} + builder.WriteByte(')') + return builder.String() + } + {{- end}} +{{ end }} \ No newline at end of file