Attempt generic NewServer

This commit is contained in:
some 2024-10-09 00:14:54 -04:00
parent a1bb62cc09
commit bade24097f
Signed by: some
GPG Key ID: 65D0589220B9BFC8
4 changed files with 17 additions and 33 deletions

2
go.mod
View File

@ -5,7 +5,7 @@ go 1.23.1
require ( require (
somehole.com/common/log v0.1.3 somehole.com/common/log v0.1.3
somehole.com/common/security v0.2.1 somehole.com/common/security v0.2.1
somehole.com/service/router v0.12.0 somehole.com/service/router v0.13.3
) )
require ( require (

4
go.sum
View File

@ -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/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 h1:H7TpErYKsCOxKYYie75jU7azO5vEgeqrQ9uA+AjXafA=
somehole.com/common/security v0.2.1/go.mod h1:6SMKdIrfxT460XXWafpD6A9yT/ykwipGsGztA5g5vVM= somehole.com/common/security v0.2.1/go.mod h1:6SMKdIrfxT460XXWafpD6A9yT/ykwipGsGztA5g5vVM=
somehole.com/service/router v0.12.0 h1:nrBn+OJF9cN22vgXcZYdcSbLTamPwMEvu4NG2lJLO88= somehole.com/service/router v0.13.3 h1:q4jGnqMIB+o78ZUmKy9HVMFpO/fjRh6Wud3WGIMH1rM=
somehole.com/service/router v0.12.0/go.mod h1:F+/sNY4/ei7C9QD5+iA+gUHugcOAcrWspHKwX8d8oiM= somehole.com/service/router v0.13.3/go.mod h1:F+/sNY4/ei7C9QD5+iA+gUHugcOAcrWspHKwX8d8oiM=

View File

@ -1,14 +1,12 @@
package server package server
import ( import (
"encoding/json"
"somehole.com/service/oauth2/session" "somehole.com/service/oauth2/session"
"somehole.com/service/router" "somehole.com/service/router"
) )
type CallbackRequestBuilder struct { type CallbackRequestBuilder struct {
router.UnimplementedRequestBuilder router.DefaultRequestBuilder
values struct { values struct {
router.Values router.Values
State session.State `form:"state"` State session.State `form:"state"`
@ -17,27 +15,21 @@ type CallbackRequestBuilder struct {
} }
func (rb CallbackRequestBuilder) RequestBuilder() router.RequestBuilder { func (rb CallbackRequestBuilder) RequestBuilder() router.RequestBuilder {
rb.DefaultRequestBuilder = router.NewDefaultRequestBuilder(&rb, nil, nil, nil, &rb.values.Values, &rb.values, nil, nil)
return &rb return &rb
} }
func (rb *CallbackRequestBuilder) Values(values router.Values) (errRes router.ErrorResponse) {
err := rb.values.Values.Parse(values)
if err != nil {
return ErrorBadRequest
}
return Ok
}
type CallbackResponse struct { type CallbackResponse struct {
router.UnimplementedResponse router.DefaultResponse
Body struct { Body struct {
router.Body
Message string `json:"message"` Message string `json:"message"`
} }
} }
func (r *CallbackResponse) BodyBytes() (body []byte) { func (r CallbackResponse) Response() router.Response {
body, _ = json.Marshal(r.Body) r.DefaultResponse = router.NewDefaultResponse(&r, nil, nil, &r.Body.Body, &r.Body)
return return &r
} }
type UnimplementedCallbackServer struct{} type UnimplementedCallbackServer struct{}

View File

@ -1,14 +1,12 @@
package server package server
import ( import (
"encoding/json"
"somehole.com/service/oauth2/session" "somehole.com/service/oauth2/session"
"somehole.com/service/router" "somehole.com/service/router"
) )
type TokenRequestBuilder struct { type TokenRequestBuilder struct {
router.UnimplementedRequestBuilder router.DefaultRequestBuilder
values struct { values struct {
router.Values router.Values
ResponseType string `form:"response_type"` ResponseType string `form:"response_type"`
@ -18,20 +16,14 @@ type TokenRequestBuilder struct {
} }
func (rb TokenRequestBuilder) RequestBuilder() router.RequestBuilder { func (rb TokenRequestBuilder) RequestBuilder() router.RequestBuilder {
rb.DefaultRequestBuilder = router.NewDefaultRequestBuilder(&rb, nil, nil, nil, &rb.values.Values, &rb.values, nil, nil)
return &rb return &rb
} }
func (rb *TokenRequestBuilder) Values(values router.Values) (errRes router.ErrorResponse) {
err := rb.values.Values.Parse(values)
if err != nil {
return ErrorBadRequest
}
return Ok
}
type TokenResponse struct { type TokenResponse struct {
router.UnimplementedResponse router.DefaultResponse
Body struct { Body struct {
router.Body
VerificationUri string `json:"verification_uri"` VerificationUri string `json:"verification_uri"`
UserCode session.Code `json:"user_code"` UserCode session.Code `json:"user_code"`
DeviceCode session.Code `json:"device_code"` DeviceCode session.Code `json:"device_code"`
@ -40,9 +32,9 @@ type TokenResponse struct {
} }
} }
func (r *TokenResponse) BodyBytes() (body []byte) { func (r TokenResponse) Response() router.Response {
body, _ = json.Marshal(r.Body) r.DefaultResponse = router.NewDefaultResponse(&r, nil, nil, &r.Body.Body, &r.Body)
return return &r
} }
type UnimplementedTokenServer struct{} type UnimplementedTokenServer struct{}