updated deps, added golangci linter

This commit is contained in:
2022-11-20 18:11:52 +01:00
parent d10a134a34
commit 5b938f4d06
8 changed files with 231 additions and 154 deletions

View File

@@ -10,9 +10,9 @@ import (
//goland:noinspection SpellCheckingInspection
var DICT = "ABCDEFGHJKLMNOPQRSTUVWXYZabcdefhijkmnopqrstuvwxyz23456789"
var sharecodeRexEx = regexp.MustCompile("^CSGO(?:-?\\w{5}){5}$")
var sharecodeRexEx = regexp.MustCompile(`^CSGO(?:-?\w{5}){5}$`)
func DecodeSharecode(code string) (uint64, uint64, uint16, error) {
func DecodeSharecode(code string) (matchID, outcomeID uint64, tokenID uint16, err error) {
if !sharecodeRexEx.MatchString(code) {
return 0, 0, 0, fmt.Errorf("not a CSGO sharecode: %s", code)
}
@@ -28,17 +28,17 @@ func DecodeSharecode(code string) (uint64, uint64, uint16, error) {
bigInt.Add(bigInt, big.NewInt(int64(strings.Index(DICT, c))))
}
if bigInt.BitLen() > 144 {
if bigInt.BitLen() > 144 { //nolint:gomnd
return 0, 0, 0, fmt.Errorf("invalid sharecode")
}
bytes := make([]byte, 18)
bytes := make([]byte, 18) //nolint:gomnd
bigInt.FillBytes(bytes)
matchId := binary.LittleEndian.Uint64(bytes[0:8])
outcomeId := binary.LittleEndian.Uint64(bytes[8:16])
tokenId := binary.LittleEndian.Uint16(bytes[16:18])
matchID = binary.LittleEndian.Uint64(bytes[0:8])
outcomeID = binary.LittleEndian.Uint64(bytes[8:16])
tokenID = binary.LittleEndian.Uint16(bytes[16:18])
return matchId, outcomeId, tokenId, nil
return
}
func ReverseString(numbers []string) []string {