You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
569 B
28 lines
569 B
4 months ago
|
package useronline
|
||
|
|
||
|
import (
|
||
|
"errors"
|
||
|
"strconv"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
|
func ParseUserOnlineStatus(payload string) (string, []int32, error) {
|
||
|
arr := strings.Split(payload, ":")
|
||
|
if len(arr) == 0 {
|
||
|
return "", nil, errors.New("invalid data")
|
||
|
}
|
||
|
userID := arr[len(arr)-1]
|
||
|
if userID == "" {
|
||
|
return "", nil, errors.New("userID is empty")
|
||
|
}
|
||
|
platformIDs := make([]int32, len(arr)-1)
|
||
|
for i := range platformIDs {
|
||
|
platformID, err := strconv.Atoi(arr[i])
|
||
|
if err != nil {
|
||
|
return "", nil, err
|
||
|
}
|
||
|
platformIDs[i] = int32(platformID)
|
||
|
}
|
||
|
return userID, platformIDs, nil
|
||
|
}
|