Remove Prototype method (require creation), increase factory clarity

This commit is contained in:
some 2024-10-09 09:17:24 -04:00
parent 64fe69244c
commit 3c64d0b477
Signed by: some
GPG Key ID: 65D0589220B9BFC8

View File

@ -64,8 +64,6 @@ func (e DefaultError) BodyBytes() (body []byte) {
}
type DefaultRequestBuilder struct {
requestBuilder RequestBuilder
prototype PrototypeRequestBuilder
errorHandler ErrorHandler
allowedMethods *[]string
header struct {
@ -82,63 +80,65 @@ type DefaultRequestBuilder struct {
}
}
func NewDefaultRequestBuilder(rb RequestBuilder, rbp PrototypeRequestBuilder, eh ErrorHandler, am *[]string, h *Header, hf header, v *Values, vf values, b *Body, bf body) DefaultRequestBuilder {
if eh == nil {
eh = &DefaultErrorHandler{}
}
if am == nil {
amd := make([]string, 0)
am = &amd
}
if h == nil || hf == nil {
hd := make(Header)
h = &hd
hfd := struct{ Header }{Header: hd}
hf = &hfd
}
if v == nil || vf == nil {
vd := make(Values)
v = &vd
vfd := struct{ Values }{Values: vd}
vf = &vfd
}
if b == nil || bf == nil {
bd := make(Body, 0)
b = &bd
bfd := struct{ Body }{Body: bd}
bf = &bfd
}
return DefaultRequestBuilder{
requestBuilder: rb,
prototype: rbp,
errorHandler: eh,
allowedMethods: am,
header: struct {
*Header
fields header
}{
Header: h,
fields: hf,
},
values: struct {
*Values
fields values
}{
Values: v,
fields: vf,
},
body: struct {
*Body
fields body
}{
Body: b,
fields: bf,
},
}
func NewDefaultRequestBuilder() *DefaultRequestBuilder {
return &DefaultRequestBuilder{}
}
func (rb *DefaultRequestBuilder) Prototype() PrototypeRequestBuilder {
return rb.prototype
func (rb *DefaultRequestBuilder) SetErrorHandler(errorHandler ErrorHandler) *DefaultRequestBuilder {
rb.errorHandler = errorHandler
return rb
}
func (rb *DefaultRequestBuilder) SetAllowedMethods(allowedMethods []string) *DefaultRequestBuilder {
rb.allowedMethods = &allowedMethods
return rb
}
func (rb *DefaultRequestBuilder) SetHeader(parsed *Header, fields header) *DefaultRequestBuilder {
rb.header.Header = parsed
rb.header.fields = fields
return rb
}
func (rb *DefaultRequestBuilder) SetValues(parsed *Values, fields values) *DefaultRequestBuilder {
rb.values.Values = parsed
rb.values.fields = fields
return rb
}
func (rb *DefaultRequestBuilder) SetBody(parsed *Body, fields body) *DefaultRequestBuilder {
rb.body.Body = parsed
rb.body.fields = fields
return rb
}
func (rb *DefaultRequestBuilder) SetDefaults() *DefaultRequestBuilder {
if rb.errorHandler == nil {
rb.errorHandler = &DefaultErrorHandler{}
}
if rb.allowedMethods == nil {
amd := make([]string, 0)
rb.allowedMethods = &amd
}
if rb.header.Header == nil || rb.header.fields == nil {
hd := make(Header)
rb.header.Header = &hd
hfd := struct{ Header }{Header: hd}
rb.header.fields = &hfd
}
if rb.values.Values == nil || rb.values.fields == nil {
vd := make(Values)
rb.values.Values = &vd
vfd := struct{ Values }{Values: vd}
rb.values.fields = &vfd
}
if rb.body.Body == nil || rb.body.fields == nil {
bd := make(Body, 0)
rb.body.Body = &bd
bfd := struct{ Body }{Body: bd}
rb.body.fields = &bfd
}
return rb
}
func (rb *DefaultRequestBuilder) Allowed(method string) (errRes ErrorResponse) {
@ -177,9 +177,7 @@ func (rb *DefaultRequestBuilder) Values(values Values) (errRes ErrorResponse) {
}
type DefaultResponse struct {
response Response
prototype PrototypeResponse
header struct {
header struct {
*Header
fields header
}
@ -189,41 +187,36 @@ type DefaultResponse struct {
}
}
func NewDefaultResponse(r Response, rp PrototypeResponse, h *Header, hf header, b *Body, bf body) DefaultResponse {
if h == nil || hf == nil {
hd := make(Header)
h = &hd
hfd := struct{ Header }{Header: hd}
hf = &hfd
}
if b == nil || bf == nil {
bd := make(Body, 0)
b = &bd
bfd := struct{ Body }{Body: bd}
bf = &bfd
}
return DefaultResponse{
response: r,
prototype: rp,
header: struct {
*Header
fields header
}{
Header: h,
fields: hf,
},
body: struct {
*Body
fields body
}{
Body: b,
fields: bf,
},
}
func NewDefaultResponse() *DefaultResponse {
return &DefaultResponse{}
}
func (r *DefaultResponse) Prototype() PrototypeResponse {
return r.prototype
func (r *DefaultResponse) SetHeader(parsed *Header, fields header) *DefaultResponse {
r.header.Header = parsed
r.header.fields = fields
return r
}
func (r *DefaultResponse) SetBody(parsed *Body, fields body) *DefaultResponse {
r.body.Body = parsed
r.body.fields = fields
return r
}
func (r *DefaultResponse) SetDefaults() *DefaultResponse {
if r.header.Header == nil || r.header.fields == nil {
hd := make(Header)
r.header.Header = &hd
hfd := struct{ Header }{Header: hd}
r.header.fields = &hfd
}
if r.body.Body == nil || r.body.fields == nil {
bd := make(Body, 0)
r.body.Body = &bd
bfd := struct{ Body }{Body: bd}
r.body.fields = &bfd
}
return r
}
func (r *DefaultResponse) Header() (header Header) {