From 7280eed20ca78fe3944418541b31d37f13010860 Mon Sep 17 00:00:00 2001 From: some Date: Thu, 10 Oct 2024 15:27:29 -0400 Subject: [PATCH] Change method names to prevent conflicts --- default.go | 42 +++++++++++++++++++++--------------------- server.go | 24 ++++++++++++------------ 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/default.go b/default.go index 995aaec..8228423 100644 --- a/default.go +++ b/default.go @@ -50,7 +50,7 @@ func (e DefaultError) Response() *GenericResponse { } return &GenericResponse{ Status: e.Status(), - Header: Header{"Content-Type": []string{"text/javascript", "charset=utf-8"}}, + Header: Header{"Content-Type": []string{"text/javascript", "charInit=utf-8"}}, Body: body, } } @@ -93,40 +93,40 @@ func NewDefaultRequestBuilder() *DefaultRequestBuilder { return &DefaultRequestBuilder{} } -func (rqb *DefaultRequestBuilder) SetErrorHandler(errorHandler Error) *DefaultRequestBuilder { +func (rqb *DefaultRequestBuilder) InitErrorHandler(errorHandler Error) *DefaultRequestBuilder { rqb.errorHandler = errorHandler return rqb } -func (rqb *DefaultRequestBuilder) SetAllowedMethods(allowedMethods *[]string) *DefaultRequestBuilder { +func (rqb *DefaultRequestBuilder) InitAllowedMethods(allowedMethods *[]string) *DefaultRequestBuilder { rqb.allowedMethods = allowedMethods return rqb } -func (rqb *DefaultRequestBuilder) SetUrl(url *url.URL) *DefaultRequestBuilder { +func (rqb *DefaultRequestBuilder) InitUrl(url *url.URL) *DefaultRequestBuilder { rqb.url = url return rqb } -func (rqb *DefaultRequestBuilder) SetHeader(parsed *Header, fields header) *DefaultRequestBuilder { +func (rqb *DefaultRequestBuilder) InitHeader(parsed *Header, fields header) *DefaultRequestBuilder { rqb.header.Header = parsed rqb.header.fields = fields return rqb } -func (rqb *DefaultRequestBuilder) SetValues(parsed *Values, fields values) *DefaultRequestBuilder { +func (rqb *DefaultRequestBuilder) InitValues(parsed *Values, fields values) *DefaultRequestBuilder { rqb.values.Values = parsed rqb.values.fields = fields return rqb } -func (rqb *DefaultRequestBuilder) SetBody(parsed *Body, fields body) *DefaultRequestBuilder { +func (rqb *DefaultRequestBuilder) InitBody(parsed *Body, fields body) *DefaultRequestBuilder { rqb.body.Body = parsed rqb.body.fields = fields return rqb } -func (rqb *DefaultRequestBuilder) SetDefaults() *DefaultRequestBuilder { +func (rqb *DefaultRequestBuilder) Init() *DefaultRequestBuilder { if rqb.errorHandler == nil { rqb.errorHandler = &DefaultErrorHandler{} } @@ -159,7 +159,7 @@ func (rqb *DefaultRequestBuilder) SetDefaults() *DefaultRequestBuilder { return rqb } -func (rqb *DefaultRequestBuilder) Allowed(method string) (e Error) { +func (rqb *DefaultRequestBuilder) SetAllowed(method string) (e Error) { var ok bool for _, m := range *rqb.allowedMethods { if m == method { @@ -172,12 +172,12 @@ func (rqb *DefaultRequestBuilder) Allowed(method string) (e Error) { return } -func (rqb *DefaultRequestBuilder) Url(url url.URL) (e Error) { +func (rqb *DefaultRequestBuilder) SetUrl(url url.URL) (e Error) { *rqb.url = url return } -func (rqb *DefaultRequestBuilder) Header(header map[string][]string) (e Error) { +func (rqb *DefaultRequestBuilder) SetHeader(header map[string][]string) (e Error) { *rqb.header.Header = header err := rqb.header.Header.Unmarshal(rqb.header.fields) if err != nil { @@ -186,13 +186,13 @@ func (rqb *DefaultRequestBuilder) Header(header map[string][]string) (e Error) { return } -func (rqb *DefaultRequestBuilder) Body(body io.ReadCloser) (e Error) { +func (rqb *DefaultRequestBuilder) SetBody(body io.ReadCloser) (e Error) { defer body.Close() json.NewDecoder(body).Decode(rqb.body.fields) return } -func (rqb *DefaultRequestBuilder) Values(values map[string][]string) (e Error) { +func (rqb *DefaultRequestBuilder) SetValues(values map[string][]string) (e Error) { *rqb.values.Values = values err := rqb.values.Values.Unmarshal(rqb.values.fields) if err != nil { @@ -236,29 +236,29 @@ func NewDefaultResponseBuilder() *DefaultResponseBuilder { return &DefaultResponseBuilder{} } -func (rsb *DefaultResponseBuilder) SetErrorHandler(errorHandler Error) *DefaultResponseBuilder { +func (rsb *DefaultResponseBuilder) InitErrorHandler(errorHandler Error) *DefaultResponseBuilder { rsb.errorHandler = errorHandler return rsb } -func (rsb *DefaultResponseBuilder) SetStatus(code *int) *DefaultResponseBuilder { +func (rsb *DefaultResponseBuilder) InitStatus(code *int) *DefaultResponseBuilder { rsb.status = code return rsb } -func (rsb *DefaultResponseBuilder) SetHeader(parsed *Header, fields header) *DefaultResponseBuilder { +func (rsb *DefaultResponseBuilder) InitHeader(parsed *Header, fields header) *DefaultResponseBuilder { rsb.header.Header = parsed rsb.header.fields = fields return rsb } -func (rsb *DefaultResponseBuilder) SetBody(parsed *Body, fields body) *DefaultResponseBuilder { +func (rsb *DefaultResponseBuilder) InitBody(parsed *Body, fields body) *DefaultResponseBuilder { rsb.body.Body = parsed rsb.body.fields = fields return rsb } -func (rsb *DefaultResponseBuilder) SetDefaults() *DefaultResponseBuilder { +func (rsb *DefaultResponseBuilder) Init() *DefaultResponseBuilder { if rsb.errorHandler == nil { rsb.errorHandler = &DefaultErrorHandler{} } @@ -281,7 +281,7 @@ func (rsb *DefaultResponseBuilder) SetDefaults() *DefaultResponseBuilder { return rsb } -func (rsb *DefaultResponseBuilder) Header(header map[string][]string) (e Error) { +func (rsb *DefaultResponseBuilder) SetHeader(header map[string][]string) (e Error) { *rsb.header.Header = header err := rsb.header.Header.Unmarshal(rsb.header.fields) if err != nil { @@ -290,8 +290,8 @@ func (rsb *DefaultResponseBuilder) Header(header map[string][]string) (e Error) return } -func (rsb *DefaultResponseBuilder) Write(body []byte) (e Error) { - *rsb.body.Body = append(*rsb.body.Body, body...) +func (rsb *DefaultResponseBuilder) SetBody(body []byte) (e Error) { + *rsb.body.Body = body return } diff --git a/server.go b/server.go index a760a17..7e722c5 100644 --- a/server.go +++ b/server.go @@ -52,11 +52,11 @@ func (*Request[RQB]) RequestBuilder() RequestBuilder { type RequestBuilder interface { mustEmbedDefaultRequestBuilder() New() (rqb RequestBuilder) - Allowed(method string) (err Error) - Url(url url.URL) (err Error) - Header(map[string][]string) (err Error) - Values(map[string][]string) (err Error) - Body(body io.ReadCloser) (err Error) + SetAllowed(method string) (err Error) + SetUrl(url url.URL) (err Error) + SetHeader(map[string][]string) (err Error) + SetValues(map[string][]string) (err Error) + SetBody(body io.ReadCloser) (err Error) Request() *GenericRequest } @@ -68,8 +68,8 @@ func (*Response[RSB]) ResponseBuilder() ResponseBuilder { type ResponseBuilder interface { mustEmbedDefaultResponseBuilder() New() (rsb ResponseBuilder) - Header(map[string][]string) (err Error) - Write(body []byte) (err Error) + SetHeader(map[string][]string) (err Error) + SetBody(body []byte) (err Error) Response() *GenericResponse } @@ -147,20 +147,20 @@ func (srv *server[RQB, RSB]) ServeHTTP(w http.ResponseWriter, r *http.Request) { var rqb RQB rqb = rqb.New().(RQB) wr := writer{ResponseWriter: w, Logger: srv.logger} - if ok := wr.handleError(rqb.Allowed(r.Method)); !ok { + if ok := wr.handleError(rqb.SetAllowed(r.Method)); !ok { return } - if ok := wr.handleError(rqb.Url(*r.URL)); !ok { + if ok := wr.handleError(rqb.SetUrl(*r.URL)); !ok { return } - if ok := wr.handleError(rqb.Header(r.Header)); !ok { + if ok := wr.handleError(rqb.SetHeader(r.Header)); !ok { return } - if ok := wr.handleError(rqb.Body(r.Body)); !ok { + if ok := wr.handleError(rqb.SetBody(r.Body)); !ok { return } r.ParseForm() - if ok := wr.handleError(rqb.Values(r.Form)); !ok { + if ok := wr.handleError(rqb.SetValues(r.Form)); !ok { return } for _, stage := range srv.serve {