server

package
v0.0.0-...-33ecef7 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2020 License: MIT Imports: 36 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = &ErrResponse{HTTPStatusCode: 404, StatusText: "Resource not found."}

ErrNotFound is a pre-built not-found error

Functions

func ErrInternal

func ErrInternal(err error) render.Renderer

ErrInternal returns a generic server error to the user

func ErrInvalidRequest

func ErrInvalidRequest(err error) render.Renderer

ErrInvalidRequest is used to indicate an error on user input (with wrapped error)

func RenderOrErrInternal

func RenderOrErrInternal(w http.ResponseWriter, r *http.Request, d render.Renderer)

RenderOrErrInternal will render whatever you pass it (assuming it has Renderer) or prints an internal error

Types

type ErrResponse

type ErrResponse struct {
	Err            error `json:"-"` // low-level runtime error
	HTTPStatusCode int   `json:"-"` // http response status code

	StatusText string `json:"status"`          // user-level status message
	AppCode    int64  `json:"code,omitempty"`  // application-specific error code
	ErrorText  string `json:"error,omitempty"` // application-level error message, for debugging
}

ErrResponse is a generic struct for returning a standard error document

func (*ErrResponse) Render

func (e *ErrResponse) Render(w http.ResponseWriter, r *http.Request) error

Render is the Renderer for ErrResponse struct

type JSONMarshaler

type JSONMarshaler struct{}

func (*JSONMarshaler) ContentType

func (jm *JSONMarshaler) ContentType() string

func (*JSONMarshaler) Marshal

func (jm *JSONMarshaler) Marshal(v interface{}) ([]byte, error)

func (*JSONMarshaler) NewDecoder

func (jm *JSONMarshaler) NewDecoder(r io.Reader) gwruntime.Decoder

func (*JSONMarshaler) NewEncoder

func (jm *JSONMarshaler) NewEncoder(w io.Writer) gwruntime.Encoder

func (*JSONMarshaler) Unmarshal

func (jm *JSONMarshaler) Unmarshal(data []byte, v interface{}) error

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is the GRPC server

func New

func New() (*Server, error)

New will setup the server

func (*Server) ErrInternalLog

func (s *Server) ErrInternalLog(err error) render.Renderer

ErrInternalLog will log an error and return a generic server error to the user

func (*Server) GRPCServer

func (s *Server) GRPCServer() *grpc.Server

GRPCServer will return the grpc server to allow functions to register themselves

func (*Server) GwReg

func (s *Server) GwReg(gwrf gwRegFunc)

GwReg will save a gateway registration function for later when the server is started

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

ListenAndServe will listen for requests

func (*Server) SetupRoutes

func (s *Server) SetupRoutes()

SetupRoutes configures all the routes for this service

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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