utils.go 1.04 KB
Newer Older
chenweijian's avatar
chenweijian committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
package common

import (
	"git.hilo.cn/hilo-common/resource/config"
	"strings"
)

// 去除slice中的重复元素
func UniqueSliceUInt64(sliceIn []uint64) []uint64 {
	sliceOut := make([]uint64, 0, len(sliceIn))
	m := make(map[uint64]struct{}, len(sliceIn))
	for _, i := range sliceIn {
		if _, ok := m[i]; !ok {
			m[i] = struct{}{}
			sliceOut = append(sliceOut, i)
		}
	}
	return sliceOut
}

// 补全url,区分处理oss和aws两种情况
func MakeFullUrl(url string) string {
	if strings.HasPrefix(url, config.GetConfigOss().OSS_CDN) || strings.HasPrefix(url, config.GetConfigAws().AWS_CDN) {
		return url
	} else if strings.HasPrefix(url, "nextvideo/") {
		return config.GetConfigOss().OSS_CDN + url
	} else if strings.HasPrefix(url, config.GetConfigAws().AWS_DIR) {
		return config.GetConfigAws().AWS_CDN + url
	} else {
		return url
	}
}
chenweijian's avatar
chenweijian committed
33 34 35 36

func PageNext(total int64, pageIndex, pageSize int) (int, bool) {
	var nextIdx int
	var hasNext bool
chenweijian's avatar
chenweijian committed
37
	if total >= int64(pageIndex+pageSize) {
chenweijian's avatar
chenweijian committed
38
		hasNext = true
chenweijian's avatar
chenweijian committed
39
		nextIdx = pageIndex + pageSize
chenweijian's avatar
chenweijian committed
40 41 42
	}
	return nextIdx, hasNext
}