Attempt generic NewServer
This commit is contained in:
parent
a1bb62cc09
commit
bade24097f
2
go.mod
2
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.12.0
|
||||
somehole.com/service/router v0.13.3
|
||||
)
|
||||
|
||||
require (
|
||||
|
4
go.sum
4
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.12.0 h1:nrBn+OJF9cN22vgXcZYdcSbLTamPwMEvu4NG2lJLO88=
|
||||
somehole.com/service/router v0.12.0/go.mod h1:F+/sNY4/ei7C9QD5+iA+gUHugcOAcrWspHKwX8d8oiM=
|
||||
somehole.com/service/router v0.13.3 h1:q4jGnqMIB+o78ZUmKy9HVMFpO/fjRh6Wud3WGIMH1rM=
|
||||
somehole.com/service/router v0.13.3/go.mod h1:F+/sNY4/ei7C9QD5+iA+gUHugcOAcrWspHKwX8d8oiM=
|
||||
|
@ -1,14 +1,12 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"somehole.com/service/oauth2/session"
|
||||
"somehole.com/service/router"
|
||||
)
|
||||
|
||||
type CallbackRequestBuilder struct {
|
||||
router.UnimplementedRequestBuilder
|
||||
router.DefaultRequestBuilder
|
||||
values struct {
|
||||
router.Values
|
||||
State session.State `form:"state"`
|
||||
@ -17,27 +15,21 @@ type CallbackRequestBuilder struct {
|
||||
}
|
||||
|
||||
func (rb CallbackRequestBuilder) RequestBuilder() router.RequestBuilder {
|
||||
rb.DefaultRequestBuilder = router.NewDefaultRequestBuilder(&rb, nil, nil, nil, &rb.values.Values, &rb.values, nil, nil)
|
||||
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 {
|
||||
router.UnimplementedResponse
|
||||
router.DefaultResponse
|
||||
Body struct {
|
||||
router.Body
|
||||
Message string `json:"message"`
|
||||
}
|
||||
}
|
||||
|
||||
func (r *CallbackResponse) BodyBytes() (body []byte) {
|
||||
body, _ = json.Marshal(r.Body)
|
||||
return
|
||||
func (r CallbackResponse) Response() router.Response {
|
||||
r.DefaultResponse = router.NewDefaultResponse(&r, nil, nil, &r.Body.Body, &r.Body)
|
||||
return &r
|
||||
}
|
||||
|
||||
type UnimplementedCallbackServer struct{}
|
||||
|
@ -1,14 +1,12 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"somehole.com/service/oauth2/session"
|
||||
"somehole.com/service/router"
|
||||
)
|
||||
|
||||
type TokenRequestBuilder struct {
|
||||
router.UnimplementedRequestBuilder
|
||||
router.DefaultRequestBuilder
|
||||
values struct {
|
||||
router.Values
|
||||
ResponseType string `form:"response_type"`
|
||||
@ -18,20 +16,14 @@ type TokenRequestBuilder struct {
|
||||
}
|
||||
|
||||
func (rb TokenRequestBuilder) RequestBuilder() router.RequestBuilder {
|
||||
rb.DefaultRequestBuilder = router.NewDefaultRequestBuilder(&rb, nil, nil, nil, &rb.values.Values, &rb.values, nil, nil)
|
||||
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 {
|
||||
router.UnimplementedResponse
|
||||
router.DefaultResponse
|
||||
Body struct {
|
||||
router.Body
|
||||
VerificationUri string `json:"verification_uri"`
|
||||
UserCode session.Code `json:"user_code"`
|
||||
DeviceCode session.Code `json:"device_code"`
|
||||
@ -40,9 +32,9 @@ type TokenResponse struct {
|
||||
}
|
||||
}
|
||||
|
||||
func (r *TokenResponse) BodyBytes() (body []byte) {
|
||||
body, _ = json.Marshal(r.Body)
|
||||
return
|
||||
func (r TokenResponse) Response() router.Response {
|
||||
r.DefaultResponse = router.NewDefaultResponse(&r, nil, nil, &r.Body.Body, &r.Body)
|
||||
return &r
|
||||
}
|
||||
|
||||
type UnimplementedTokenServer struct{}
|
||||
|
Loading…
Reference in New Issue
Block a user