resp

package
v1.0.0-sql.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 14, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DataAge

type DataAge struct {
	Min *time.Time `json:"min"`
	Max *time.Time `json:"max"`
	All []int64    `json:"-"`
}

type RequestTimings

type RequestTimings struct {
	Start    time.Time     `json:"start"`
	End      time.Time     `json:"end"`
	Duration time.Duration `json:"duration"`
}

type Response

type Response struct {
	Timer      *RequestTimings          `json:"request_timings,omitempty"`
	DataAge    *DataAge                 `json:"data_age"`
	StatusCode int                      `json:"status"`
	Errors     []error                  `json:"errors"`
	Metadata   map[string]interface{}   `json:"metadata"`
	Result     []map[string]interface{} `json:"result"`
}

func New

func New() *Response

func (*Response) AddDataAge

func (r *Response) AddDataAge(times ...time.Time)

AddDataAge is used to track the created times of the data associated with this api response. This provides a way to show messages about when the data was created / updated in front ends

func (*Response) End

func (rp *Response) End(w http.ResponseWriter, r *http.Request)

func (*Response) GetDataAgeMax

func (r *Response) GetDataAgeMax() (t time.Time)

GetDataAgeMax returns the max date stored within the data in this api response (effectively the "youngest")

func (*Response) GetDataAgeMin

func (r *Response) GetDataAgeMin() (t time.Time)

GetDataAgeMin returns the min date stored within the data in this api response (effectively the "oldest")

func (*Response) Start

func (rp *Response) Start(w http.ResponseWriter, r *http.Request)

func (*Response) TimerDuration

func (r *Response) TimerDuration() time.Duration

TimerDuration uses the end & start times to work out how long a http request has taken to be processed. This informaton is helpful for assessing performance over the api

func (*Response) TimerEnd

func (r *Response) TimerEnd()

TimerEnd is companiion to TimerStart, this tracks the end of the http request being processed and can then be used to work out duration.

func (*Response) TimerStart

func (r *Response) TimerStart()

TimerStart is called early in the http request handler to accurately track the start time of the request. This is then used with end time to work out durations that can be checked for performance etc

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL