diff --git a/default.go b/default.go index 59cce6c..8ab4c3e 100644 --- a/default.go +++ b/default.go @@ -60,39 +60,61 @@ type DefaultRequestBuilder struct { allowedMethods *[]string header struct { *Header - fields *header + fields header } values struct { *Values - fields *values + fields values } body struct { *Body - fields *body + fields body } } -func NewDefaultRequestBuilder(rb RequestBuilder, am *[]string, h *Header, hf *header, v *Values, vf *values, b *Body, bf *body) DefaultRequestBuilder { +func NewDefaultRequestBuilder(rb RequestBuilder, am *[]string, h *Header, hf header, v *Values, vf values, b *Body, bf body) DefaultRequestBuilder { + 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, allowedMethods: am, header: struct { *Header - fields *header + fields header }{ Header: h, fields: hf, }, values: struct { *Values - fields *values + fields values }{ Values: v, fields: vf, }, body: struct { *Body - fields *body + fields body }{ Body: b, fields: bf, @@ -140,13 +162,46 @@ func (rb *DefaultRequestBuilder) Values(values Values) (errRes ErrorResponse) { } type DefaultResponse struct { - header struct { + response Response + header struct { *Header - fields *header + fields header } body struct { *Body - fields *body + fields body + } +} + +func NewDefaultResponse(r Response, 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, + header: struct { + *Header + fields header + }{ + Header: h, + fields: hf, + }, + body: struct { + *Body + fields body + }{ + Body: b, + fields: bf, + }, } }