mirror of
https://github.com/WiiLink24/wfc-server.git
synced 2026-05-06 22:43:27 -05:00
27 lines
710 B
Go
27 lines
710 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{}{}
|
|
}
|
|
|
|
// ShouldNotError panics if the error is not nil.
|
|
func ShouldNotError(err error) {
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// 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()
|
|
}
|