You've already forked focalboard
mirror of
https://github.com/mattermost/focalboard.git
synced 2025-07-15 23:54:29 +02:00
Channels style UUID (#1369)
* server channels style uuids * webapp channels style uuids
This commit is contained in:
@ -1,28 +1,52 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
mm_model "github.com/mattermost/mattermost-server/v6/model"
|
||||
)
|
||||
|
||||
// CreateGUID returns a random GUID.
|
||||
func CreateGUID() string {
|
||||
b := make([]byte, 16)
|
||||
_, err := rand.Read(b)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
uuid := fmt.Sprintf("%x-%x-%x-%x-%x", b[0:4], b[4:6], b[6:8], b[8:10], b[10:])
|
||||
type IDType byte
|
||||
|
||||
return uuid
|
||||
const (
|
||||
IDTypeNone IDType = '7'
|
||||
IDTypeWorkspace IDType = 'w'
|
||||
IDTypeBoard IDType = 'b'
|
||||
IDTypeCard IDType = 'c'
|
||||
IDTypeView IDType = 'v'
|
||||
IDTypeSession IDType = 's'
|
||||
IDTypeUser IDType = 'u'
|
||||
IDTypeToken IDType = 'k'
|
||||
IDTypeBlock IDType = 'a'
|
||||
)
|
||||
|
||||
// NewId is a globally unique identifier. It is a [A-Z0-9] string 27
|
||||
// characters long. It is a UUID version 4 Guid that is zbased32 encoded
|
||||
// with the padding stripped off, and a one character alpha prefix indicating the
|
||||
// type of entity or a `7` if unknown type.
|
||||
func NewID(idType IDType) string {
|
||||
return string(idType) + mm_model.NewId()
|
||||
}
|
||||
|
||||
// GetMillis is a convenience method to get milliseconds since epoch.
|
||||
func GetMillis() int64 {
|
||||
return time.Now().UnixNano() / int64(time.Millisecond)
|
||||
return mm_model.GetMillis()
|
||||
}
|
||||
|
||||
// GetMillisForTime is a convenience method to get milliseconds since epoch for provided Time.
|
||||
func GetMillisForTime(thisTime time.Time) int64 {
|
||||
return mm_model.GetMillisForTime(thisTime)
|
||||
}
|
||||
|
||||
// GetTimeForMillis is a convenience method to get time.Time for milliseconds since epoch.
|
||||
func GetTimeForMillis(millis int64) time.Time {
|
||||
return mm_model.GetTimeForMillis(millis)
|
||||
}
|
||||
|
||||
// SecondsToMillis is a convenience method to convert seconds to milliseconds.
|
||||
func SecondsToMillis(seconds int64) int64 {
|
||||
return seconds * 1000
|
||||
}
|
||||
|
||||
func StructToMap(v interface{}) (m map[string]interface{}) {
|
||||
|
Reference in New Issue
Block a user