Add Prototype method to Defaults

This commit is contained in:
some 2024-10-09 00:28:18 -04:00
parent c0dedb7d96
commit 0165e58ddb
Signed by: some
GPG Key ID: 65D0589220B9BFC8

View File

@ -57,6 +57,7 @@ func (e DefaultError) BodyBytes() (body []byte) {
type DefaultRequestBuilder struct {
requestBuilder RequestBuilder
prototype PrototypeRequestBuilder
allowedMethods *[]string
header struct {
*Header
@ -72,7 +73,7 @@ type DefaultRequestBuilder struct {
}
}
func NewDefaultRequestBuilder(rb RequestBuilder, am *[]string, h *Header, hf header, v *Values, vf values, b *Body, bf body) DefaultRequestBuilder {
func NewDefaultRequestBuilder(rb RequestBuilder, rbp PrototypeRequestBuilder, am *[]string, h *Header, hf header, v *Values, vf values, b *Body, bf body) DefaultRequestBuilder {
if am == nil {
amd := make([]string, 0)
am = &amd
@ -97,6 +98,7 @@ func NewDefaultRequestBuilder(rb RequestBuilder, am *[]string, h *Header, hf hea
}
return DefaultRequestBuilder{
requestBuilder: rb,
prototype: rbp,
allowedMethods: am,
header: struct {
*Header
@ -122,6 +124,10 @@ func NewDefaultRequestBuilder(rb RequestBuilder, am *[]string, h *Header, hf hea
}
}
func (rb *DefaultRequestBuilder) Prototype() PrototypeRequestBuilder {
return rb.prototype
}
func (rb *DefaultRequestBuilder) Allowed(method string) (errRes ErrorResponse) {
var ok bool
for _, m := range *rb.allowedMethods {
@ -158,8 +164,9 @@ func (rb *DefaultRequestBuilder) Values(values Values) (errRes ErrorResponse) {
}
type DefaultResponse struct {
response Response
header struct {
response Response
prototype PrototypeResponse
header struct {
*Header
fields header
}
@ -169,7 +176,7 @@ type DefaultResponse struct {
}
}
func NewDefaultResponse(r Response, h *Header, hf header, b *Body, bf body) DefaultResponse {
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
@ -183,7 +190,8 @@ func NewDefaultResponse(r Response, h *Header, hf header, b *Body, bf body) Defa
bf = &bfd
}
return DefaultResponse{
response: r,
response: r,
prototype: rp,
header: struct {
*Header
fields header
@ -201,6 +209,10 @@ func NewDefaultResponse(r Response, h *Header, hf header, b *Body, bf body) Defa
}
}
func (r *DefaultResponse) Prototype() PrototypeResponse {
return r.prototype
}
func (r *DefaultResponse) Header() (header Header) {
if r.header.Header == nil {
r.header.Header.Parse(r.header.fields)