webservice

package module
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2025 License: Apache-2.0 Imports: 18 Imported by: 0

README

webservice

Golang Microservice helper based on gorilla/mux

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Version   string
	BuildTime string
	CommitSHA string
)

Functions

func AllowAllCorsMiddleware

func AllowAllCorsMiddleware(h http.Handler) http.Handler

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

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 BuildInfo added in v0.5.0

type BuildInfo struct {
	Name          string `json:"name,omitempty"`
	Version       string `json:"version,omitempty"`
	BuildTime     string `json:"build_time,omitempty"`
	CommitSHA     string `json:"commit_sha,omitempty"`
	PreferLdflags bool   `json:"-"`
}

BuildInfo represents build information for the service

type Config added in v0.5.0

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

Config holds all configuration for WebService

type ConfigureRouterHandler added in v0.4.0

type ConfigureRouterHandler interface {
	ConfigureRouter(router *mux.Router) (handler http.Handler, err error)
}

ConfigureRouterHandler ...

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 ServerStatus

type ServerStatus struct {
	Running   bool   `json:"running,omitempty"`
	Process   string `json:"process,omitempty"`
	Pid       int    `json:"pid,omitempty"`
	StripPath string `json:"strip_path,omitempty"`
	JwksURL   string `json:"jwks_url,omitempty"`
	BuildInfo
}

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

func NewServerStatus

func NewServerStatus(bi BuildInfo) *ServerStatus

NewServerStatus create default service status

type Timeouts added in v0.5.0

type Timeouts struct {
	WriteTimeout time.Duration
	ReadTimeout  time.Duration
	IdleTimeout  time.Duration
}

type WebService added in v0.5.0

type WebService interface {
	Start() (err error) // Start service
}

WebService ...

func New added in v0.5.0

func New(obj WebServiceObject, options ...WebServiceOption) WebService

New creates new web service object

type WebServiceBase added in v0.5.0

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

WebServiceBase ...

func (*WebServiceBase) Start added in v0.5.0

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

Start starts service

type WebServiceBeforeEnd added in v0.5.0

type WebServiceBeforeEnd interface {
	BeforeEnd()
}

WebServiceBeforeEnd ...

type WebServiceBeforeStart added in v0.5.0

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

WebServiceBeforeStart ...

type WebServiceGetHTTPHandlerObsolete added in v0.5.0

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

WebServiceGetHTTPHandlerObsolete ...

type WebServiceGetStatusHandler added in v0.5.0

type WebServiceGetStatusHandler interface {
	GetServerStatus() (status interface{})
}

WebServiceGetStatusHandler ...

type WebServiceObject added in v0.5.0

type WebServiceObject interface {
}

WebServiceObject ...

type WebServiceOption added in v0.5.0

type WebServiceOption func(*Config)

WebServiceOption defines a function type for setting options

func WithBuildInfo added in v0.5.0

func WithBuildInfo(bi BuildInfo) WebServiceOption

WithBuildInfo sets the build information

func WithIdleTimeout added in v0.5.0

func WithIdleTimeout(timeout time.Duration) WebServiceOption

WithIdleTimeout sets the idle timeout

func WithReadTimeout added in v0.5.0

func WithReadTimeout(timeout time.Duration) WebServiceOption

WithReadTimeout sets the read timeout

func WithTimeouts added in v0.5.0

func WithTimeouts(write, read, idle time.Duration) WebServiceOption

WithTimeouts sets all timeout values at once

func WithWriteTimeout added in v0.5.0

func WithWriteTimeout(timeout time.Duration) WebServiceOption

WithWriteTimeout sets the write timeout

type WebServicePreparePFlags added in v0.5.0

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

WebServicePreparePFlags ...

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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