func TestConvertString(t *testing.T) { tests := []struct { input interface{} expected string prec int }{ {"abc", "abc", 0}, {3.20, "3.2", 1}, {3.20, "3.20", 2}, {3.21, "3.21", 2}, {float32(3.21), "3.21", 2}, {1, "1", 0}, {uint(1), "1", 0}, {int8(1), "1", 0}, {uint8(1), "1", 0}, {false, "false", 0}, } for _, test := range tests { actual := goutils.ConvertString(test.input, test.prec) if test.expected != actual { t.Errorf("ConvertString(%q, %q)=%s, expected:%s", test.input, test.prec, actual, test.expected) } } }
func (s *Service) GenSign(args map[string]interface{}) string { keys := make([]string, 0, len(args)) for k := range args { keys = append(keys, k) } sort.Sort(sort.StringSlice(keys)) buffer := goutils.NewBuffer() for _, k := range keys { buffer.Append(k).Append("=").Append(goutils.ConvertString(args[k])) } if s.CommonSalt != "" { buffer.Append(s.CommonSalt) } else { if from, ok := args["from"]; ok { if salt, ok := s.FromSalt[goutils.ConvertString(from)]; ok { buffer.Append(salt) } } } return goutils.Md5(buffer.String()) }