forked from Silverfish/proton-bridge
Other: Linter fixes after bumping linter version
This commit is contained in:
@ -1,12 +1,20 @@
|
||||
package user
|
||||
|
||||
import "reflect"
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
func mapTo[From, To any](from []From) []To {
|
||||
to := make([]To, 0, len(from))
|
||||
|
||||
for _, from := range from {
|
||||
to = append(to, reflect.ValueOf(from).Convert(reflect.TypeOf(to).Elem()).Interface().(To))
|
||||
val, ok := reflect.ValueOf(from).Convert(reflect.TypeOf(to).Elem()).Interface().(To)
|
||||
if !ok {
|
||||
panic(fmt.Sprintf("cannot convert %T to %T", from, *new(To)))
|
||||
}
|
||||
|
||||
to = append(to, val)
|
||||
}
|
||||
|
||||
return to
|
||||
|
||||
Reference in New Issue
Block a user