Documentation ¶
Overview ¶
**************************************************************************** * Copyright 2022 51 Degrees Mobile Experts Limited (51degrees.com) * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. * **************************************************************************
Index ¶
- Variables
- func GetDateFromMinutes(t uint32) time.Time
- func GetDateInMinutes(t time.Time) uint32
- func GetWriter(writer http.ResponseWriter, contentType string) *gzip.Writer
- func HTTPTest(t *testing.T, method string, url *url.URL, body io.Reader, ...) *httptest.ResponseRecorder
- func ReadBool(b *bytes.Buffer) (bool, error)
- func ReadByte(b *bytes.Buffer) (byte, error)
- func ReadByteArray(b *bytes.Buffer) ([]byte, error)
- func ReadByteArrayArray(b *bytes.Buffer) ([][]byte, error)
- func ReadByteArrayNoLength(b *bytes.Buffer, l int) ([]byte, error)
- func ReadDate(b *bytes.Buffer) (time.Time, error)
- func ReadDateFromUInt32(b *bytes.Buffer) (time.Time, error)
- func ReadFloat32(b *bytes.Buffer) (float32, error)
- func ReadMarshaller(b *bytes.Buffer, m encoding.BinaryUnmarshaler) error
- func ReadString(b *bytes.Buffer) (string, error)
- func ReadStrings(b *bytes.Buffer) ([]string, error)
- func ReadTime(b *bytes.Buffer) (time.Time, error)
- func ReadUint16(b *bytes.Buffer) (uint16, error)
- func ReadUint32(b *bytes.Buffer) (uint32, error)
- func ResponseAsByteArrayTest(t *testing.T, rr *httptest.ResponseRecorder) []byte
- func ResponseAsMapTest(t *testing.T, rr *httptest.ResponseRecorder) map[string]interface{}
- func ResponseAsStringTest(t *testing.T, rr *httptest.ResponseRecorder) string
- func ReturnApplicationError(writer http.ResponseWriter, err *HttpError)
- func ReturnError(writer http.ResponseWriter, err *HttpError)
- func ReturnServerError(writer http.ResponseWriter, err error)
- func SendByteArray(writer http.ResponseWriter, data []byte)
- func SendByteArrayUncompressed(writer http.ResponseWriter, data []byte)
- func SendHTMLTemplate(writer http.ResponseWriter, temp *template.Template, model interface{})
- func SendJS(writer http.ResponseWriter, data []byte)
- func SendJSTemplate(writer http.ResponseWriter, temp *template.Template, model interface{})
- func SendResponse(writer http.ResponseWriter, contentType string, data []byte, compress bool)
- func SendString(writer http.ResponseWriter, value string)
- func SendTemplate(writer http.ResponseWriter, temp *template.Template, contentType string, ...)
- func TestCompareDate(t *testing.T, a time.Time, b time.Time)
- func WriteBool(b *bytes.Buffer, v bool) error
- func WriteByte(b *bytes.Buffer, i byte) error
- func WriteByteArray(b *bytes.Buffer, v []byte) error
- func WriteByteArrayArray(b *bytes.Buffer, v [][]byte) error
- func WriteByteArrayNoLength(b *bytes.Buffer, v []byte) error
- func WriteDate(b *bytes.Buffer, t time.Time) error
- func WriteDateToUInt32(b *bytes.Buffer, t time.Time) error
- func WriteFloat32(b *bytes.Buffer, f float32) error
- func WriteMarshaller(b *bytes.Buffer, m encoding.BinaryMarshaler) error
- func WriteString(b *bytes.Buffer, s string) error
- func WriteStrings(b *bytes.Buffer, v []string) error
- func WriteTime(b *bytes.Buffer, t time.Time) error
- func WriteUint16(b *bytes.Buffer, i uint16) error
- func WriteUint32(b *bytes.Buffer, i uint32) error
- type HttpError
Constants ¶
This section is empty.
Variables ¶
The base year for all dates encoded with the io time methods.
Functions ¶
func GetDateFromMinutes ¶
GetTimeFromMinutes returns the date time from the minutes provided.
func GetDateInMinutes ¶
GetDateInMinutes returns the number of minutes that have elapsed since the IoDateBase epoch.
func GetWriter ¶
func GetWriter(writer http.ResponseWriter, contentType string) *gzip.Writer
GetWriter creates a new compressed writer for the content type provided.
func HTTPTest ¶
func HTTPTest( t *testing.T, method string, url *url.URL, body io.Reader, handler func(w http.ResponseWriter, r *http.Request)) *httptest.ResponseRecorder
HTTPTest returns a test response after having processed the handler, method, URL, and body provided. t testing instance method HTTP method host url HTTP url values query values body data handler HTTP handler being tested
func ReadByteArray ¶
ReadByteArray reads the first 4 bytes as an unsigned 32 bit integer to determine the length of the byte array contained in the following bytes.
func ReadByteArrayArray ¶
ReadByteArrayArray from two dimensional array of bytes.
func ReadByteArrayNoLength ¶
ReadByteArrayNoLength reads the number of bytes specified into a new byte array.
func ReadDate ¶
ReadDate reads the date from the unsigned 16 bit integer and then determines the date by adding this to the IoDateBase epoch.
func ReadDateFromUInt32 ¶
ReadDateFromUInt32 reads the date from the buffer where the date is stored as the number of minutes as an unsigned 32 bit integer that have elapsed since the IoDateBase epoch.
func ReadMarshaller ¶
func ReadMarshaller(b *bytes.Buffer, m encoding.BinaryUnmarshaler) error
ReadMarshaller reads the content into the unmarshaler instance.
func ReadString ¶
ReadString reads a null (zero) terminated string from the byte buffer.
func ReadStrings ¶
ReadStrings into one dimensional array of strings.
func ReadUint16 ¶
ReadUint16 reads an unsigned 16 bit integer from the buffer. The integer is stored in little endian format.
func ReadUint32 ¶
ReadUint32 reads an unsigned 32 bit integer from the buffer. The integer is stored in little endian format.
func ResponseAsByteArrayTest ¶ added in v0.1.2
func ResponseAsByteArrayTest( t *testing.T, rr *httptest.ResponseRecorder) []byte
ResponseAsByteArrayTest decompresses the response as a byte array.
func ResponseAsMapTest ¶ added in v0.1.2
func ResponseAsMapTest( t *testing.T, rr *httptest.ResponseRecorder) map[string]interface{}
ResponseAsMapTest decompresses the response and returns the body as a map.
func ResponseAsStringTest ¶ added in v0.1.2
func ResponseAsStringTest( t *testing.T, rr *httptest.ResponseRecorder) string
ResponseAsStringTest decompresses the response and returns the body as a string.
func ReturnApplicationError ¶
func ReturnApplicationError(writer http.ResponseWriter, err *HttpError)
ReturnApplicationError handles HTTP application errors consistently. writer for the response err details of the error
func ReturnError ¶
func ReturnError(writer http.ResponseWriter, err *HttpError)
ReturnError handles all HTTP errors consistently. writer for the response err details of the error
func ReturnServerError ¶
func ReturnServerError(writer http.ResponseWriter, err error)
ReturnServerError handles HTTP server errors consistently ensuring they are output to the logger. writer for the response message to be sent in the response err the error to be logged and included in the response if debug is true
func SendByteArray ¶
func SendByteArray(writer http.ResponseWriter, data []byte)
SendByteArray writes the data as an octet-stream.
func SendByteArrayUncompressed ¶
func SendByteArrayUncompressed(writer http.ResponseWriter, data []byte)
SendByteArrayUncompressed writes the data as an octet-stream without compression.
func SendHTMLTemplate ¶
func SendHTMLTemplate( writer http.ResponseWriter, temp *template.Template, model interface{})
SendHTMLTemplate parses the template with the model provided and then outputs the result as HTML.
func SendJS ¶
func SendJS(writer http.ResponseWriter, data []byte)
SendJS sends the JSON data provided.
func SendJSTemplate ¶
func SendJSTemplate( writer http.ResponseWriter, temp *template.Template, model interface{})
SendJSTemplate parses the template with the model provided and then outputs the result as JS.
func SendResponse ¶
func SendResponse( writer http.ResponseWriter, contentType string, data []byte, compress bool)
SendResponse writes out the data with the content type provided.
func SendString ¶
func SendString(writer http.ResponseWriter, value string)
SendString writes out the string value with the appropriate content type.
func SendTemplate ¶
func SendTemplate( writer http.ResponseWriter, temp *template.Template, contentType string, model interface{})
SendTemplate parses the template with the model provided and then outputs the result for the content type provided.
func WriteByteArray ¶
ReadByteArray writes the length of the byte array as an unsigned 32 bit integer followed by the bytes.
func WriteByteArrayArray ¶
WriteByteArrayArray two dimensional array of bytes.
func WriteByteArrayNoLength ¶
WriteByteArrayNoLength writes the byte array to the buffer without recording the length. Used with fixed length data.
func WriteDate ¶
WriteDate writes the date as the number of hours since the IoDateBase epoch. Uses an unsigned 16 bit integer.
func WriteDateToUInt32 ¶
WriteDateToUInt32 writes the date to the buffer as an unsigned 32 bit representing the number of minutes that have elapsed since the IoDateBase epoch.
func WriteMarshaller ¶
func WriteMarshaller(b *bytes.Buffer, m encoding.BinaryMarshaler) error
WriteMarshaller writes the result of marshal binary call to the buffer.
func WriteString ¶
WriteString writes a null (zero) terminated string to the byte buffer.
func WriteStrings ¶
WriteStrings one dimensional array of strings.
func WriteUint16 ¶
WriteUint16 reads an unsigned 16 bit integer from the buffer where the integer is stored in little endian format.
Types ¶
type HttpError ¶
type HttpError struct { Request *http.Request // the HTTP request Log bool // true if the error should be written to the log Message string // message to return in the HTTP response Code int // HTTP status code for the response Error error // the server error - never sent in the response }
HttpError associated with HTTP handlers.