MCPcopy Index your code
hub / github.com/coder/coder / convertDiffType

Function convertDiffType

enterprise/audit/diff.go:96–171  ·  view source on GitHub ↗

convertDiffType converts external struct types to primitive types. nolint:forcetypeassert

(left, right any)

Source from the content-addressed store, hash-verified

94//
95//nolint:forcetypeassert
96func convertDiffType(left, right any) (newLeft, newRight any, changed bool) {
97 switch typedLeft := left.(type) {
98 case uuid.UUID:
99 typedRight := right.(uuid.UUID)
100
101 // Automatically coerce Nil UUIDs to empty strings.
102 outLeft := typedLeft.String()
103 if typedLeft == uuid.Nil {
104 outLeft = ""
105 }
106
107 outRight := typedRight.String()
108 if typedRight == uuid.Nil {
109 outRight = ""
110 }
111
112 return outLeft, outRight, true
113
114 case uuid.NullUUID:
115 leftStr, _ := typedLeft.MarshalText()
116 rightStr, _ := right.(uuid.NullUUID).MarshalText()
117 return string(leftStr), string(rightStr), true
118
119 case sql.NullString:
120 leftStr := typedLeft.String
121 if !typedLeft.Valid {
122 leftStr = "null"
123 }
124
125 rightStr := right.(sql.NullString).String
126 if !right.(sql.NullString).Valid {
127 rightStr = "null"
128 }
129
130 return leftStr, rightStr, true
131
132 case sql.NullInt64:
133 var leftInt64Ptr *int64
134 var rightInt64Ptr *int64
135 if !typedLeft.Valid {
136 leftInt64Ptr = nil
137 } else {
138 leftInt64Ptr = ptr.Ref(typedLeft.Int64)
139 }
140
141 rightInt64Ptr = ptr.Ref(right.(sql.NullInt64).Int64)
142 if !right.(sql.NullInt64).Valid {
143 rightInt64Ptr = nil
144 }
145
146 return leftInt64Ptr, rightInt64Ptr, true
147 case database.NullNotificationMethod:
148 vl, vr := string(typedLeft.NotificationMethod), ""
149 if val, ok := right.(database.NullNotificationMethod); ok {
150 vr = string(val.NotificationMethod)
151 }
152
153 return vl, vr, true

Callers 1

diffValuesFunction · 0.85

Calls 3

RefFunction · 0.92
MarshalTextMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected