github.com/enbility/spine-go@v0.7.0/model/custom.go (about) 1 package model 2 3 import ( 4 "fmt" 5 6 "github.com/enbility/spine-go/util" 7 ) 8 9 // provides a helper method to create hash values of custom structs for usage with collection updates 10 type UpdateHelper interface { 11 String() string 12 } 13 14 type ErrorType struct { 15 ErrorNumber ErrorNumberType 16 Description *DescriptionType 17 } 18 19 func NewErrorType(errorNumber ErrorNumberType, description string) *ErrorType { 20 return &ErrorType{ 21 ErrorNumber: errorNumber, 22 Description: util.Ptr(DescriptionType(description)), 23 } 24 } 25 26 func NewErrorTypeFromNumber(errorNumber ErrorNumberType) *ErrorType { 27 return &ErrorType{ 28 ErrorNumber: errorNumber, 29 } 30 } 31 32 func NewErrorTypeFromString(description string) *ErrorType { 33 return NewErrorType(ErrorNumberTypeGeneralError, description) 34 } 35 36 func NewErrorTypeFromResult(result *ResultDataType) *ErrorType { 37 if result.ErrorNumber == nil || *result.ErrorNumber == ErrorNumberTypeNoError { 38 return nil 39 } 40 41 return &ErrorType{ 42 ErrorNumber: *result.ErrorNumber, 43 Description: result.Description, 44 } 45 } 46 47 func (e *ErrorType) String() string { 48 if e.Description != nil && len(*e.Description) > 0 { 49 return fmt.Sprintf("Error %d: %s", e.ErrorNumber, *e.Description) 50 } 51 return fmt.Sprintf("Error %d", e.ErrorNumber) 52 }