Skip to content

Commit

Permalink
fix for comments
Browse files Browse the repository at this point in the history
Signed-off-by: Ziqi Zhao <zhaoziqi9146@gmail.com>
  • Loading branch information
fatsheep9146 committed Oct 12, 2022
1 parent 9026c8a commit 65e974a
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/attribute/attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,25 @@
// See the License for the specific language governing permissions and
// limitations under the License.

/*
Package attribute provide several helper functions for some commonly used
logic of processing attributes.
*/
package attribute // import "go.opentelemetry.io/otel/internal/attribute"

import (
"reflect"
)

// SliceValue convert a slice into an array with same elements as slice.
func SliceValue[T bool | int64 | float64 | string](v []T) any {
var zero T
cp := reflect.New(reflect.ArrayOf(len(v), reflect.TypeOf(zero)))
copy(cp.Elem().Slice(0, len(v)).Interface().([]T), v)
return cp.Elem().Interface()
}

// AsSlice convert an array into a slice into with same elements as array.
func AsSlice[T bool | int64 | float64 | string](v any) []T {
rv := reflect.ValueOf(v)
if rv.Type().Kind() != reflect.Array {
Expand Down

0 comments on commit 65e974a

Please sign in to comment.