37 lines
689 B
Go
37 lines
689 B
Go
|
|
package generator
|
||
|
|
|
||
|
|
import (
|
||
|
|
"fmt"
|
||
|
|
"math/rand"
|
||
|
|
"strconv"
|
||
|
|
"time"
|
||
|
|
|
||
|
|
"github.com/google/uuid"
|
||
|
|
)
|
||
|
|
|
||
|
|
func MedicalRecordNumberRand() string {
|
||
|
|
return RandStringRunes(10)
|
||
|
|
}
|
||
|
|
|
||
|
|
func RandStringRunes(n int) string {
|
||
|
|
rand.Seed(time.Now().UnixNano()) // seed the random number generator
|
||
|
|
|
||
|
|
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||
|
|
b := make([]byte, n)
|
||
|
|
for i := range b {
|
||
|
|
b[i] = letterBytes[rand.Intn(len(letterBytes))]
|
||
|
|
}
|
||
|
|
|
||
|
|
return string(b)
|
||
|
|
}
|
||
|
|
|
||
|
|
// format -> <uuid>-<time unix>
|
||
|
|
func GenerateFileName() string {
|
||
|
|
return fmt.Sprintf("%v-%v", GenerateUUID(), strconv.Itoa(int(time.Now().Unix())))
|
||
|
|
}
|
||
|
|
|
||
|
|
func GenerateUUID() string {
|
||
|
|
id := uuid.New()
|
||
|
|
return id.String()
|
||
|
|
}
|