1
// Copyright 2019 Aporeto Inc.
2
// Licensed under the Apache License, Version 2.0 (the "License");
3
// you may not use this file except in compliance with the License.
4
// You may obtain a copy of the License at
5
//     http://www.apache.org/licenses/LICENSE-2.0
6
// Unless required by applicable law or agreed to in writing, software
7
// distributed under the License is distributed on an "AS IS" BASIS,
8
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9
// See the License for the specific language governing permissions and
10
// limitations under the License.
11

12
package elemental
13

14
import "net/http"
15

16
// A Response contains the response from a Request.
17
type Response struct {
18
	StatusCode int
19
	Data       []byte
20
	Count      int
21
	Total      int
22
	Next       string
23
	Messages   []string
24
	Redirect   string
25
	RequestID  string
26
	Request    *Request
27
	Cookies    []*http.Cookie
28
}
29

30
// NewResponse returns a new Response
31
func NewResponse(req *Request) *Response {
32

33 14
	return &Response{
34 14
		RequestID: req.RequestID,
35 14
		Request:   req,
36
	}
37
}
38

39
// GetEncoding returns the encoding used to encode the entity.
40
func (r *Response) GetEncoding() EncodingType {
41 14
	return r.Request.Accept
42
}
43

44
// Encode encodes the given oject into the response.
45
func (r *Response) Encode(obj interface{}) (err error) {
46

47 14
	r.Data, err = Encode(r.GetEncoding(), obj)
48 14
	return err
49
}

Read our documentation on viewing source code .

Loading