14 lines
199 B
Go
14 lines
199 B
Go
|
package generics
|
||
|
|
||
|
import "encoding/json"
|
||
|
|
||
|
func UnmarshalTo[T any](raw []byte) (*T, error) {
|
||
|
var resp T
|
||
|
err := json.Unmarshal(raw, &resp)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
return &resp, nil
|
||
|
}
|