common

package
v0.0.0-...-9745057 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2020 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package common implements some utility functions for http transaction.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBodyFromReq

func GetBodyFromReq(req *http.Request) (string, error)

GetBodyFromReq reads a body from http request object. A successful call returns the body type of string. If request does not include body, InvalidParam will be returned. In other cases, an appropriate error will be returned.

func MapToJsonByte

func MapToJsonByte(src map[string]interface{}) []byte

ChangeToJson converts map to []byte.

func WriteError

func WriteError(w http.ResponseWriter, err error)

WriteError writes the data to the connection as part of an HTTP reply. The http status code depend on an error type. An error message will be included as a body.

func WriteResponse

func WriteResponse(w http.ResponseWriter, code int, data []byte)

WriteResponse calls WriteSuccess or WriteResponse function to respond to the request. If err is nil, WriteSuccess will be called. otherwise, WriteError will be called.

Types

This section is empty.

Jump to

Keyboard shortcuts

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