mirror of
https://github.com/WiiLink24/wfc-server.git
synced 2026-12-05 07:01:53 -06:00
22 lines
596 B
Go
22 lines
596 B
Go
package common
|
|
|
|
import (
|
|
"reflect"
|
|
)
|
|
|
|
// MaybeUnused is a helper function to mark variables as used to avoid compiler warnings.
|
|
func MaybeUnused(v ...interface{}) struct{} {
|
|
return struct{}{}
|
|
}
|
|
|
|
// ReverseMap takes a map and returns a new map with the keys and values reversed.
|
|
func ReverseMap(m interface{}) interface{} {
|
|
inputType := reflect.TypeOf(m)
|
|
inputValue := reflect.ValueOf(m)
|
|
result := reflect.MakeMap(reflect.MapOf(inputType.Elem(), inputType.Key()))
|
|
for _, key := range inputValue.MapKeys() {
|
|
result.SetMapIndex(inputValue.MapIndex(key), key)
|
|
}
|
|
return result.Interface()
|
|
}
|