Golang 에서 UUID 를 만들 때 google 에서 만든 uuid 패키지로 만들면 됩니다.
func makeUuid() string {
newUUID := uuid.New()
log.Printf("uuid: %s", newUUID)
return newUUID.String()
}
UUID 를 검증할 때는 parse 함수를 활용하면 됩니다. 아래는 길이가 다른 경우를 테스트한 경우입니다.
func parseUuid() bool {
s := "c5dbedfd-d149-463e-8c09-7cc1a90364a"
newUUID, err := uuid.Parse(s)
if err != nil {
log.Printf("failed to parse: %+v", err)
return false
}
log.Printf("uuid: %s", newUUID)
return true
}
// failed to parse: invalid UUID length: 35
Google uuid package : https://github.com/google/uuid
[Golang]싱글톤(singleton) 패턴 구현하기 (0) | 2022.07.01 |
---|---|
[Golang] "net/http: TLS handshake timeout" error (0) | 2022.07.01 |
[Golang]PNG 파일 JPG 로 변환하기 (0) | 2022.06.24 |
[Golang]config 파일 관리는 viper 괜찮아요 (0) | 2022.06.16 |
[Golang]파일 타입 알고 싶을 때 DetectContentType (0) | 2022.06.09 |