From d602e680570b4aee6ea3e0d6d91ebbc9f914f0fd Mon Sep 17 00:00:00 2001 From: some Date: Wed, 9 Oct 2024 09:58:26 -0400 Subject: [PATCH] Upgrade to use latest router --- go.mod | 2 +- go.sum | 4 ++-- server/callback.go | 23 +++++++++++++++++++---- server/token.go | 21 ++++++++++++++++++--- 4 files changed, 40 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index 647abd7..f6985d2 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.23.1 require ( somehole.com/common/log v0.1.3 somehole.com/common/security v0.2.1 - somehole.com/service/router v0.16.0 + somehole.com/service/router v0.17.0 ) require ( diff --git a/go.sum b/go.sum index ea17284..bc2d151 100644 --- a/go.sum +++ b/go.sum @@ -8,5 +8,5 @@ somehole.com/common/log v0.1.3 h1:2PAui0+5EryTAHqVUZQeepLcJTGssHKz2OL+jBknHI0= somehole.com/common/log v0.1.3/go.mod h1:NS2eHnN120GA6oFbBm3XhB5yHww0eXTbLuMQYZxYNyA= somehole.com/common/security v0.2.1 h1:H7TpErYKsCOxKYYie75jU7azO5vEgeqrQ9uA+AjXafA= somehole.com/common/security v0.2.1/go.mod h1:6SMKdIrfxT460XXWafpD6A9yT/ykwipGsGztA5g5vVM= -somehole.com/service/router v0.16.0 h1:h9swbPfyCmXej26nvoXZYIt3RT/sAZPQZnCz1rbLBQk= -somehole.com/service/router v0.16.0/go.mod h1:F+/sNY4/ei7C9QD5+iA+gUHugcOAcrWspHKwX8d8oiM= +somehole.com/service/router v0.17.0 h1:uKod3d3fLxXHK6DVhvA84FGW56XnQpIkkeM5L5Yw2hg= +somehole.com/service/router v0.17.0/go.mod h1:F+/sNY4/ei7C9QD5+iA+gUHugcOAcrWspHKwX8d8oiM= diff --git a/server/callback.go b/server/callback.go index af1b475..2e14dfd 100644 --- a/server/callback.go +++ b/server/callback.go @@ -6,7 +6,7 @@ import ( ) type CallbackRequestBuilder struct { - router.DefaultRequestBuilder + *router.DefaultRequestBuilder values struct { router.Values State session.State `form:"state"` @@ -14,21 +14,36 @@ type CallbackRequestBuilder struct { } } +func (*CallbackRequestBuilder) Prototype() router.PrototypeRequestBuilder { + rb := CallbackRequestBuilder{} + rb.DefaultRequestBuilder = router.NewDefaultRequestBuilder(). + SetErrorHandler(&ErrorHandler{}). + SetValues(&rb.values.Values, &rb.values). + SetDefaults() + return rb +} + func (rb CallbackRequestBuilder) RequestBuilder() router.RequestBuilder { - rb.DefaultRequestBuilder = router.NewDefaultRequestBuilder(&rb, CallbackRequestBuilder{}, &ErrorHandler{}, nil, nil, nil, &rb.values.Values, &rb.values, nil, nil) return &rb } type CallbackResponse struct { - router.DefaultResponse + *router.DefaultResponse Body struct { router.Body Message string `json:"message"` } } +func (*CallbackResponse) Prototype() router.PrototypeResponse { + r := CallbackResponse{} + r.DefaultResponse = router.NewDefaultResponse(). + SetBody(&r.Body.Body, &r.Body). + SetDefaults() + return r +} + func (r CallbackResponse) Response() router.Response { - r.DefaultResponse = router.NewDefaultResponse(&r, CallbackResponse{}, nil, nil, &r.Body.Body, &r.Body) return &r } diff --git a/server/token.go b/server/token.go index 3239baa..0e7bf28 100644 --- a/server/token.go +++ b/server/token.go @@ -15,13 +15,21 @@ type TokenRequestBuilder struct { } } +func (*TokenRequestBuilder) Prototype() router.PrototypeRequestBuilder { + rb := CallbackRequestBuilder{} + rb.DefaultRequestBuilder = router.NewDefaultRequestBuilder(). + SetErrorHandler(&ErrorHandler{}). + SetValues(&rb.values.Values, &rb.values). + SetDefaults() + return rb +} + func (rb TokenRequestBuilder) RequestBuilder() router.RequestBuilder { - rb.DefaultRequestBuilder = router.NewDefaultRequestBuilder(&rb, TokenRequestBuilder{}, &ErrorHandler{}, nil, nil, nil, &rb.values.Values, &rb.values, nil, nil) return &rb } type TokenResponse struct { - router.DefaultResponse + *router.DefaultResponse Body struct { router.Body VerificationUri string `json:"verification_uri"` @@ -32,8 +40,15 @@ type TokenResponse struct { } } +func (*TokenResponse) Prototype() router.PrototypeResponse { + r := TokenResponse{} + r.DefaultResponse = router.NewDefaultResponse(). + SetBody(&r.Body.Body, &r.Body). + SetDefaults() + return r +} + func (r TokenResponse) Response() router.Response { - r.DefaultResponse = router.NewDefaultResponse(&r, TokenResponse{}, nil, nil, &r.Body.Body, &r.Body) return &r }