Files
wfc-server/common/misc.go
2026-12-02 16:51:23 -05:00

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()
}