kis-flow/id/kis_id.go
2024-03-26 14:54:50 +08:00

35 lines
632 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package id
import (
"github.com/aceld/kis-flow/common"
"github.com/google/uuid"
"strings"
)
// KisID 获取一个中随机实例ID
// 格式为 "prefix1-[prefix2-][prefix3-]ID"
// 如flow-1234567890
// 如func-1234567890
// 如: conn-1234567890
// 如: func-1-1234567890
func KisID(prefix ...string) (kisId string) {
idStr := strings.Replace(uuid.New().String(), "-", "", -1)
kisId = formatKisID(idStr, prefix...)
return
}
func formatKisID(idStr string, prefix ...string) string {
var kisId string
for _, fix := range prefix {
kisId += fix
kisId += common.KisIdJoinChar
}
kisId += idStr
return kisId
}