github.com/thetreep/go-swagger@v0.0.0-20240223100711-35af64f14f01/generator/templates/serializers/marshalbinaryserializer.gotmpl (about) 1 {{ define "marshalBinarySerializer" }} 2 // MarshalBinary interface implementation 3 func ({{.ReceiverName}} *{{ pascalize .Name }}) MarshalBinary() ([]byte, error) { 4 if {{ .ReceiverName }} == nil { 5 return nil, nil 6 } 7 return swag.WriteJSON({{ .ReceiverName }}) 8 } 9 10 // UnmarshalBinary interface implementation 11 func ({{.ReceiverName}} *{{ pascalize .Name }}) UnmarshalBinary(b []byte) error { 12 var res {{ pascalize .Name }} 13 if err := swag.ReadJSON(b, &res); err != nil { 14 return err 15 } 16 *{{ .ReceiverName }} = res 17 return nil 18 } 19 {{- end }}