MCPcopy Create free account
hub / github.com/dolanor/rip / updateFieldInEntity

Function updateFieldInEntity

handler.go:148–170  ·  view source on GitHub ↗

TODO: is it used? Delete?

(entity Ent, fieldName string, fieldValue any)

Source from the content-addressed store, hash-verified

146
147// TODO: is it used? Delete?
148func updateFieldInEntity[Ent any](entity Ent, fieldName string, fieldValue any) (err error) {
149 defer func() {
150 rerr := recover()
151 if rerr != nil {
152 // TODO(the): add a real full error with error source, etc
153 err = Error{
154 Source: ErrorSource{
155 Pointer: fieldName,
156 },
157 Debug: fmt.Errorf("%v: %w", rerr, err).Error(),
158 }
159 }
160 }()
161 val := reflect.ValueOf(entity)
162 // it should be a pointer type
163 val = val.Elem()
164 field := val.FieldByNameFunc(func(s string) bool {
165 return strings.ToLower(s) == strings.ToLower(fieldName)
166 })
167 field.Set(reflect.ValueOf(fieldValue))
168
169 return nil
170}
171
172func updatePathID[Ent any](urlPath, method string, f updateFunc[Ent], get getFunc[Ent], options *RouteOptions) http.HandlerFunc {
173 return func(w http.ResponseWriter, r *http.Request) {

Callers

nothing calls this directly

Calls 1

ErrorMethod · 0.45

Tested by

no test coverage detected