From 7830fe284ceaf5f2170419798a3941e68518f995 Mon Sep 17 00:00:00 2001 From: Jannis Mattheis Date: Tue, 11 Jun 2024 22:14:33 +0200 Subject: [PATCH] update examples --- example/default/generated/generated.go | 4 +--- example/house/generated/generated.go | 18 ++++++------------ .../generated/generated.go | 4 +--- .../wrap-errors-using/generated/generated.go | 12 ++++-------- example/wrap-errors-using/generated/minimal.go | 12 ++++-------- 5 files changed, 16 insertions(+), 34 deletions(-) diff --git a/example/default/generated/generated.go b/example/default/generated/generated.go index 6eefb158..2f85d940 100644 --- a/example/default/generated/generated.go +++ b/example/default/generated/generated.go @@ -12,12 +12,10 @@ func (c *ConverterImpl) Convert(source *default1.Input) *default1.Output { if source != nil { var exampleOutput default1.Output exampleOutput.Age = (*source).Age - var pString *string if (*source).Name != nil { xstring := *(*source).Name - pString = &xstring + exampleOutput.Name = &xstring } - exampleOutput.Name = pString pExampleOutput = &exampleOutput } return pExampleOutput diff --git a/example/house/generated/generated.go b/example/house/generated/generated.go index 74881345..586ba8e3 100644 --- a/example/house/generated/generated.go +++ b/example/house/generated/generated.go @@ -12,27 +12,23 @@ func (c *ConverterImpl) ConvertApartment(source house.DBApartment) house.APIApar houseAPIApartment.Position = source.Position houseAPIApartment.Owner = c.ConvertPerson(source.Owner) houseAPIApartment.OwnerName = source.Owner.Name - var houseAPIPersonList []house.APIPerson if source.CoResident != nil { - houseAPIPersonList = make([]house.APIPerson, len(source.CoResident)) + houseAPIApartment.CoResident = make([]house.APIPerson, len(source.CoResident)) for i := 0; i < len(source.CoResident); i++ { - houseAPIPersonList[i] = c.ConvertPerson(source.CoResident[i]) + houseAPIApartment.CoResident[i] = c.ConvertPerson(source.CoResident[i]) } } - houseAPIApartment.CoResident = houseAPIPersonList return houseAPIApartment } func (c *ConverterImpl) ConvertHouse(source house.DBHouse) house.APIHouse { var houseAPIHouse house.APIHouse houseAPIHouse.Address = source.Address - var mapHouseAPIRoomNRHouseAPIApartment map[house.APIRoomNR]house.APIApartment if source.Apartments != nil { - mapHouseAPIRoomNRHouseAPIApartment = make(map[house.APIRoomNR]house.APIApartment, len(source.Apartments)) + houseAPIHouse.Apartments = make(map[house.APIRoomNR]house.APIApartment, len(source.Apartments)) for key, value := range source.Apartments { - mapHouseAPIRoomNRHouseAPIApartment[house.APIRoomNR(key)] = c.ConvertApartment(value) + houseAPIHouse.Apartments[house.APIRoomNR(key)] = c.ConvertApartment(value) } } - houseAPIHouse.Apartments = mapHouseAPIRoomNRHouseAPIApartment return houseAPIHouse } func (c *ConverterImpl) ConvertPerson(source house.DBPerson) house.APIPerson { @@ -41,13 +37,11 @@ func (c *ConverterImpl) ConvertPerson(source house.DBPerson) house.APIPerson { houseAPIPerson.MiddleName = house.SQLStringToPString(source.MiddleName) pString := source.Name houseAPIPerson.FirstName = &pString - var houseAPIPersonList []house.APIPerson if source.Friends != nil { - houseAPIPersonList = make([]house.APIPerson, len(source.Friends)) + houseAPIPerson.Friends = make([]house.APIPerson, len(source.Friends)) for i := 0; i < len(source.Friends); i++ { - houseAPIPersonList[i] = c.ConvertPerson(source.Friends[i]) + houseAPIPerson.Friends[i] = c.ConvertPerson(source.Friends[i]) } } - houseAPIPerson.Friends = houseAPIPersonList return houseAPIPerson } diff --git a/example/use-zero-value-on-pointer-inconsistency/generated/generated.go b/example/use-zero-value-on-pointer-inconsistency/generated/generated.go index fdc37e50..bc07343e 100644 --- a/example/use-zero-value-on-pointer-inconsistency/generated/generated.go +++ b/example/use-zero-value-on-pointer-inconsistency/generated/generated.go @@ -9,11 +9,9 @@ type ConverterImpl struct{} func (c *ConverterImpl) Convert(source usezerovalueonpointerinconsistency.Input) usezerovalueonpointerinconsistency.Output { var exampleOutput usezerovalueonpointerinconsistency.Output - var xstring string if source.Name != nil { - xstring = *source.Name + exampleOutput.Name = *source.Name } - exampleOutput.Name = xstring exampleOutput.Age = source.Age return exampleOutput } diff --git a/example/wrap-errors-using/generated/generated.go b/example/wrap-errors-using/generated/generated.go index f956b2e1..e70f42ea 100644 --- a/example/wrap-errors-using/generated/generated.go +++ b/example/wrap-errors-using/generated/generated.go @@ -27,34 +27,30 @@ func (c *ConverterImpl) Convert(source map[int]example.Input) (map[int]example.O } func (c *ConverterImpl) exampleInputToExampleOutput(source example.Input) (example.Output, error) { var exampleOutput example.Output - var exampleOutputList []example.Output if source.Friends != nil { - exampleOutputList = make([]example.Output, len(source.Friends)) + exampleOutput.Friends = make([]example.Output, len(source.Friends)) for i := 0; i < len(source.Friends); i++ { exampleOutput2, err := c.exampleInputToExampleOutput(source.Friends[i]) if err != nil { return exampleOutput, patherr.Wrap(err, patherr.Field("Friends"), patherr.Index(i)) } - exampleOutputList[i] = exampleOutput2 + exampleOutput.Friends[i] = exampleOutput2 } } - exampleOutput.Friends = exampleOutputList xint, err := strconv.Atoi(source.Age) if err != nil { return exampleOutput, patherr.Wrap(err, patherr.Field("Age")) } exampleOutput.Age = xint - var mapStringInt map[string]int if source.Attributes != nil { - mapStringInt = make(map[string]int, len(source.Attributes)) + exampleOutput.Attributes = make(map[string]int, len(source.Attributes)) for key, value := range source.Attributes { xint2, err := strconv.Atoi(value) if err != nil { return exampleOutput, patherr.Wrap(err, patherr.Field("Attributes"), patherr.Key(key)) } - mapStringInt[key] = xint2 + exampleOutput.Attributes[key] = xint2 } } - exampleOutput.Attributes = mapStringInt return exampleOutput, nil } diff --git a/example/wrap-errors-using/generated/minimal.go b/example/wrap-errors-using/generated/minimal.go index dee8bb05..7ec7bcc2 100644 --- a/example/wrap-errors-using/generated/minimal.go +++ b/example/wrap-errors-using/generated/minimal.go @@ -27,34 +27,30 @@ func (c *MinimalImpl) Convert(source map[int]example.Input) (map[int]example.Out } func (c *MinimalImpl) exampleInputToExampleOutput(source example.Input) (example.Output, error) { var exampleOutput example.Output - var exampleOutputList []example.Output if source.Friends != nil { - exampleOutputList = make([]example.Output, len(source.Friends)) + exampleOutput.Friends = make([]example.Output, len(source.Friends)) for i := 0; i < len(source.Friends); i++ { exampleOutput2, err := c.exampleInputToExampleOutput(source.Friends[i]) if err != nil { return exampleOutput, patherr.Wrap(err, patherr.Field("Friends"), patherr.Index(i)) } - exampleOutputList[i] = exampleOutput2 + exampleOutput.Friends[i] = exampleOutput2 } } - exampleOutput.Friends = exampleOutputList xint, err := strconv.Atoi(source.Age) if err != nil { return exampleOutput, patherr.Wrap(err, patherr.Field("Age")) } exampleOutput.Age = xint - var mapStringInt map[string]int if source.Attributes != nil { - mapStringInt = make(map[string]int, len(source.Attributes)) + exampleOutput.Attributes = make(map[string]int, len(source.Attributes)) for key, value := range source.Attributes { xint2, err := strconv.Atoi(value) if err != nil { return exampleOutput, patherr.Wrap(err, patherr.Field("Attributes"), patherr.Key(key)) } - mapStringInt[key] = xint2 + exampleOutput.Attributes[key] = xint2 } } - exampleOutput.Attributes = mapStringInt return exampleOutput, nil }