Created
October 4, 2024 06:45
-
-
Save gofer/5c6a21c232eadb7f2614659637cc67ff to your computer and use it in GitHub Desktop.
UUID v7をプレゼンテーション層でいい感じに扱う
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using UUIDNext; | |
using Microsoft.AspNetCore.Authentication; | |
public class Program | |
{ | |
private static Guid GenerateId() => Uuid.NewDatabaseFriendly(UUIDNext.Database.PostgreSql); | |
private static string ToControllerId(Guid id) => Base64UrlTextEncoder.Encode(id.ToByteArray(true)); | |
private static Guid FromControllerId(string id) => new Guid(Base64UrlTextEncoder.Decode(id), true); | |
public static void Main() | |
{ | |
var id = GenerateId(); | |
var sid = ToControllerId(id); | |
var gid = FromControllerId(sid); | |
Console.WriteLine($"id: {id} / {sid} / {gid}"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment