func parseXLStat(xlMetaBuf []byte) (statInfo, error) { // obtain stat info. stat := statInfo{} // fetching modTime. modTime, err := time.Parse(time.RFC3339, gjson.GetBytes(xlMetaBuf, "stat.modTime").String()) if err != nil { return statInfo{}, err } stat.ModTime = modTime // obtain Stat.Size . stat.Size = gjson.GetBytes(xlMetaBuf, "stat.size").Int() return stat, nil }
func parseXLErasureInfo(xlMetaBuf []byte) erasureInfo { erasure := erasureInfo{} erasureResult := gjson.GetBytes(xlMetaBuf, "erasure") // parse the xlV1Meta.Erasure.Distribution. disResult := erasureResult.Get("distribution").Array() distribution := make([]int, len(disResult)) for i, dis := range disResult { distribution[i] = int(dis.Int()) } erasure.Distribution = distribution erasure.Algorithm = erasureResult.Get("algorithm").String() erasure.DataBlocks = int(erasureResult.Get("data").Int()) erasure.ParityBlocks = int(erasureResult.Get("parity").Int()) erasure.BlockSize = erasureResult.Get("blockSize").Int() erasure.Index = int(erasureResult.Get("index").Int()) // Pare xlMetaV1.Erasure.Checksum array. checkSumsResult := erasureResult.Get("checksum").Array() checkSums := make([]checkSumInfo, len(checkSumsResult)) for i, checkSumResult := range checkSumsResult { checkSum := checkSumInfo{} checkSum.Name = checkSumResult.Get("name").String() checkSum.Algorithm = checkSumResult.Get("algorithm").String() checkSum.Hash = checkSumResult.Get("hash").String() checkSums[i] = checkSum } erasure.Checksum = checkSums return erasure }
func Audios(count, offset uint, token string) ([]track.Track, error) { requestsCount := float64(count) / float64(tracksLimit) requestsCount = math.Ceil(requestsCount) var limit uint var tracks []track.Track params := url.Values{} for i := uint(0); i < uint(requestsCount); i++ { if count < tracksLimit { limit = count } else { limit = tracksLimit } count -= limit params.Set("count", strconv.Itoa(int(limit))) params.Set("offset", strconv.Itoa(int((i*tracksLimit)+offset))) params.Set("access_token", token) params.Set("v", "5.60") jsonAudios, err := getTracks(params) if err == ErrNotFound { break } if err != nil { return nil, err } trackResults := gjson.GetBytes(jsonAudios, "response.items").Array() tracks = append(tracks, convRS2TS(trackResults)...) } return tracks, nil }
func parseXLMetaMap(xlMetaBuf []byte) map[string]string { // Get xlMetaV1.Meta map. metaMapResult := gjson.GetBytes(xlMetaBuf, "meta").Map() metaMap := make(map[string]string) for key, valResult := range metaMapResult { metaMap[key] = valResult.String() } return metaMap }
func parseXLParts(xlMetaBuf []byte) []objectPartInfo { // Parse the XL Parts. partsResult := gjson.GetBytes(xlMetaBuf, "parts").Array() partInfo := make([]objectPartInfo, len(partsResult)) for i, p := range partsResult { info := objectPartInfo{} info.Number = int(p.Get("number").Int()) info.Name = p.Get("name").String() info.ETag = p.Get("etag").String() info.Size = p.Get("size").Int() partInfo[i] = info } return partInfo }
func Search(limit, offset uint, query, token string) ([]track.Track, error) { params := url.Values{} params.Set("q", query) params.Set("count", strconv.Itoa(int(limit))) params.Set("offset", strconv.Itoa(int(offset))) params.Set("access_token", token) params.Set("v", "5.60") jsonFound, err := search(params) if err != nil { return nil, err } trackResults := gjson.GetBytes(jsonFound, "response.items").Array() return convRS2TS(trackResults), nil }
func WallAudios(id, token string) ([]track.Track, error) { params := url.Values{} params.Set("posts", id) params.Set("access_token", token) params.Set("v", "5.60") jsonWallAudios, err := wallAudios(params) if err != nil { return nil, err } var trackResults []gjson.Result attachmentsResults := gjson.GetBytes(jsonWallAudios, `response.#.attachments`) for _, r := range attachmentsResults.Array()[0].Array() { // it's so ugly! if r.Get("type").String() == "audio" { trackResults = append(trackResults, r.Get("audio")) } } return convRS2TS(trackResults), nil }
func parseXLRelease(xlMetaBuf []byte) string { return gjson.GetBytes(xlMetaBuf, "minio.release").String() }
func parseXLFormat(xlMetaBuf []byte) string { return gjson.GetBytes(xlMetaBuf, "format").String() }
func parseXLVersion(xlMetaBuf []byte) string { return gjson.GetBytes(xlMetaBuf, "version").String() }