response

package
v3.2.2 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2020 License: Apache-2.0 Imports: 5 Imported by: 0

README

Response with Logger

This package enables response with event logging in go-restful apps. For the event logging please read logger/event package

Usage

Importing
import "github.com/AccelByte/go-restful-plugins/v3/pkg/response"
Write Response Success
Write(request, response, httpStatusCode, serviceType, eventID, message, entity)
Write Response Error
WriteError(request, response, httpStatusCode, serviceType, eventErr, errorResponse)
Error Response Example
&Error{
    ErrorCode:    unableToWriteResponse,
    ErrorMessage: "unable to write response",
    ErrorLogMsg:  fmt.Sprintf("unable to write response: %+v, body: %+v, error: %v", response, entity, err),
})

We recommend use "github.com/pkg/errors" to create error and wrap the errors with stack trace to help with debugging

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Write

func Write(request *restful.Request, response *restful.Response, httpStatusCode int, serviceType int, eventID int,
	message string, entity interface{})

Write sends response with specified values

func WriteError

func WriteError(request *restful.Request, response *restful.Response, httpStatusCode int, serviceType int,
	eventErr error, errorResponse *Error)

WriteError sends error message

func WriteErrorWithEventID added in v3.1.3

func WriteErrorWithEventID(request *restful.Request, response *restful.Response, httpStatusCode int,
	serviceType int, eventID int, eventErr error, errorResponse *Error)

WriteErrorWithEventID sends error message with Event ID

Types

type Error

type Error struct {
	ErrorCode    int    `json:"errorCode"`
	ErrorMessage string `json:"errorMessage"`
	ErrorLogMsg  string `json:"-"`
}

Error is response sent when an error occurs Use event ID for error code, register your event ID at: https://docs.google.com/spreadsheets/d/1tUB0BSNLyPgeWEtnNzVQkl6Shud-_ErJja2RjIyt1B0/edit?usp=sharing

Jump to

Keyboard shortcuts

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