gocommon/convert/convert.go

21 lines
507 B
Go
Raw Permalink Normal View History

2022-11-26 20:45:32 +00:00
package convert
// ToPointer will convert any type of data to his pointer.
func ToPointer[T any](v T) *T {
return &v
}
// Stringer is a interface that any "enum" style struct need to follow.
type Stringer interface {
String() string
}
// StringerSliceToStringSlice will take a slice of stringer and convert it to a slice of string.
func StringerSliceToStringSlice[E Stringer](v []E) []string {
output := make([]string, len(v))
for i, data := range v {
output[i] = data.String()
}
return output
}