packagemainimport"fmt"// 定义约束
typeNumberinterface{int64|float64}// SumIntsOrFloats sums the values of map m. It supports both int64 and float64
// as types for map values.
funcSumNumbers[Kcomparable,VNumber](mmap[K]V)V{varsVfor_,v:=rangem{s+=v}returns}funcmain(){// Initialize a map for the integer values
ints:=map[string]int64{"first":34,"second":12,}// Initialize a map for the float values
floats:=map[string]float64{"first":35.98,"second":26.99,}fmt.Printf("Generic Sums: %v and %v\n",SumNumbers(ints),SumNumbers(floats))}