diff --git a/examples/d1-blog-server/app/handler.go b/examples/d1-blog-server/app/handler.go index 8675314..1b5f437 100644 --- a/examples/d1-blog-server/app/handler.go +++ b/examples/d1-blog-server/app/handler.go @@ -8,11 +8,12 @@ import ( "os" "time" + "github.com/google/uuid" + "github.com/mailru/easyjson" "github.com/syumai/workers/cloudflare/d1" _ "github.com/syumai/workers/cloudflare/d1" // register driver "github.com/syumai/workers/examples/d1-blog-server/app/model" - "github.com/syumai/workers/internal/jsutil" ) type articleHandler struct{} @@ -62,7 +63,7 @@ func (h *articleHandler) createArticle(w http.ResponseWriter, req *http.Request, now := time.Now().Unix() article := model.Article{ - ID: jsutil.NewUUID(), + ID: uuid.New().String(), Title: createArticleReq.Title, Body: createArticleReq.Body, CreatedAt: uint64(now), diff --git a/examples/d1-blog-server/go.mod b/examples/d1-blog-server/go.mod index 92d0eed..d3c34c8 100644 --- a/examples/d1-blog-server/go.mod +++ b/examples/d1-blog-server/go.mod @@ -9,4 +9,7 @@ require ( replace github.com/syumai/workers => ../../ -require github.com/josharian/intern v1.0.0 // indirect +require ( + github.com/google/uuid v1.3.0 // indirect + github.com/josharian/intern v1.0.0 // indirect +) diff --git a/examples/d1-blog-server/go.sum b/examples/d1-blog-server/go.sum index 7707cb6..3e8aec9 100644 --- a/examples/d1-blog-server/go.sum +++ b/examples/d1-blog-server/go.sum @@ -1,3 +1,5 @@ +github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= +github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= diff --git a/internal/jsutil/jsutil.go b/internal/jsutil/jsutil.go index d123727..ac21397 100644 --- a/internal/jsutil/jsutil.go +++ b/internal/jsutil/jsutil.go @@ -18,7 +18,6 @@ var ( ErrorClass = Global.Get("Error") ReadableStreamClass = Global.Get("ReadableStream") DateClass = Global.Get("Date") - Crypto = Global.Get("crypto") ) func NewObject() js.Value { @@ -103,7 +102,3 @@ func DateToTime(v js.Value) (time.Time, error) { func TimeToDate(t time.Time) js.Value { return DateClass.New(t.UnixMilli()) } - -func NewUUID() string { - return Crypto.Call("randomUUID").String() -}