webservice

package module
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

README

webservice

Golang Microservice helper based on gorilla/mux

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllowAllCorsMiddleware

func AllowAllCorsMiddleware(h http.Handler) http.Handler

AllowAllCorsMiddleware returns middleware function that can be used in router.Use()

func ProcessHTTPError

func ProcessHTTPError(err error, w http.ResponseWriter, _ *http.Request)

ProcessHTTPError writes formated error response to w

Types

type AppHandler

type AppHandler func(w http.ResponseWriter, r *http.Request) error

AppHandler is handler that take care of content type and error handling

func (AppHandler) ServeHTTP

func (ah AppHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

Satisfies the http.Handler interface

type AppHandlerWithUserID

type AppHandlerWithUserID func(userID string, w http.ResponseWriter, r *http.Request) error

AppHandlerWithUserID is handler that take care of userID, content type and error handling

func (AppHandlerWithUserID) ServeHTTP

func (ah AppHandlerWithUserID) ServeHTTP(w http.ResponseWriter, r *http.Request)

Satisfies the http.Handler interface

type GelfFormatter

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

GelfFormatter ...

func (*GelfFormatter) Format

func (f *GelfFormatter) Format(entry *logrus.Entry) ([]byte, error)

Format formats the log entry to GELF JSON

type ServerErrorData

type ServerErrorData struct {
	Parent      error  `json:"-"`
	Code        int    `json:"code,omitempty"`
	Message     string `json:"message,omitempty"`
	Description string `json:"description,omitempty"`
	Stack       string `json:"-"`
}

ServerErrorData is custom error that should be used to describe better errors

func ServerError

func ServerError(Parent error, Code int, Message string) *ServerErrorData

ServerError Create error object

func (*ServerErrorData) Error

func (e *ServerErrorData) Error() string

type ServerErrorLoginRequired

type ServerErrorLoginRequired struct {
	*ServerErrorData
	LoginRequired bool `json:"login_required,omitempty"`
}

ServerErrorLoginRequired is server error that can provide info if login is required

type ServerErrorWithText

type ServerErrorWithText struct {
	*ServerErrorData
	ErrorText string `json:"error,omitempty"`
}

ServerErrorWithText extra text

type ServerStatus

type ServerStatus struct {
	Running bool `json:"running"`
	// Name    string `json:"name"`
	Process string `json:"process"`
	Pid     int    `json:"pid"`
}

ServerStatus return actual state and process data so you can test with url/state the correct installation of microservice

func NewServerStatus

func NewServerStatus() *ServerStatus

NewServerStatus create default service status

type SimpleService

type SimpleService interface {
	Start() (err error)                                                                           // Start service
	SetTimeouts(writeTimeout time.Duration, readTimeout time.Duration, idleTimeout time.Duration) // set timeouts. 0 will use default values. It must be called before start
}

SimpleService ...

func NewSimpleService

func NewSimpleService(obj SimpleServiceObject) SimpleService

NewSimpleService creates new simple service object

type SimpleServiceBase

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

SimpleServiceBase ...

func (*SimpleServiceBase) SetTimeouts added in v0.2.1

func (s *SimpleServiceBase) SetTimeouts(writeTimeout time.Duration, readTimeout time.Duration, idleTimeout time.Duration)

func (*SimpleServiceBase) Start

func (s *SimpleServiceBase) Start() (err error)

Start starts service

type SimpleServiceBeforeEnd added in v0.2.2

type SimpleServiceBeforeEnd interface {
	BeforeEnd()
}

SimpleServiceBeforeEnd ...

type SimpleServiceBeforeStart

type SimpleServiceBeforeStart interface {
	BeforeStart() (err error)
}

SimpleServiceBeforeStart ...

type SimpleServiceGetHTTPHandler

type SimpleServiceGetHTTPHandler interface {
	GetHTTPHandler() (handler http.Handler, err error)
}

SimpleServiceGetHTTPHandler ...

type SimpleServiceObject

type SimpleServiceObject interface {
}

SimpleServiceObject ...

type SimpleServicePreparePFlags

type SimpleServicePreparePFlags interface {
	PreparePFlags() (err error)
}

SimpleServicePreparePFlags ...

Directories

Path Synopsis
examples
custom-routes command
dummy command
input-params command
timeouts command

Jump to

Keyboard shortcuts

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