api

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: May 7, 2021 License: MIT Imports: 21 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MetricTypes = struct {
	APIRequestPath string
}{
	APIRequestPath: "api_request_path",
}

MetricTypes constants

View Source
var VERSION = "1.2.0"

VERSION identifies Arkadiko's current version

Functions

func FailWith

func FailWith(status int, message string, c echo.Context) error

FailWith fails with the specified message

func GetTX

GetTX returns new relic transaction

func HealthCheckHandler

func HealthCheckHandler(app *App) func(c echo.Context) error

HealthCheckHandler is the handler responsible for validating that the app is still up

func SendMqttHandler

func SendMqttHandler(app *App) func(c echo.Context) error

SendMqttHandler is the handler responsible for sending messages to mqtt

func SucceedWith

func SucceedWith(payload map[string]interface{}, c echo.Context) error

SucceedWith sends payload to user with status 200

func WithSegment

func WithSegment(name string, c echo.Context, f func() error) error

WithSegment adds a segment to new relic transaction

Types

type App

type App struct {
	Debug      bool
	Port       int
	Host       string
	ConfigPath string
	Errors     metrics.EWMA
	App        *jecho.Echo
	Config     *viper.Viper
	Logger     log.FieldLogger
	MqttClient *mqttclient.MqttClient
	HttpClient *httpclient.HttpClient
	NewRelic   newrelic.Application
	DDStatsD   *DogStatsD
}

App is a struct that represents a arkadiko API Application

func GetApp

func GetApp(host string, port int, configPath string, debug bool, logger log.FieldLogger) (*App, error)

GetApp returns a new arkadiko API Application

func (*App) Configure

func (app *App) Configure() error

Configure instantiates the required dependencies for arkadiko Api Application

func (*App) OnErrorHandler

func (app *App) OnErrorHandler(err error, stack []byte)

OnErrorHandler handles panics

func (*App) Start

func (app *App) Start() error

Start starts listening for web requests at specified host and port

type DogStatsD added in v1.1.0

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

DogStatsD metrics reporter struct

func NewDogStatsD added in v1.1.0

func NewDogStatsD(config *viper.Viper) (*DogStatsD, error)

NewDogStatsD ctor

func (*DogStatsD) Gauge added in v1.1.0

func (d *DogStatsD) Gauge(
	metric string, value float64, tags ...string,
) error

Gauge reports a numeric value that can go up or down

func (*DogStatsD) Increment added in v1.1.0

func (d *DogStatsD) Increment(metric string, tags ...string) error

Increment reports an increment to some metric

func (*DogStatsD) Timing added in v1.1.0

func (d *DogStatsD) Timing(
	metric string, value time.Duration, tags ...string,
) error

Timing reports time interval taken for something

type JSON

type JSON map[string]interface{}

JSON type

type LoggerMiddleware

type LoggerMiddleware struct {
	Logger log.FieldLogger
}

LoggerMiddleware is responsible for logging to Zap all requests

func NewLoggerMiddleware

func NewLoggerMiddleware(theLogger log.FieldLogger) *LoggerMiddleware

NewLoggerMiddleware returns the logger middleware

func (*LoggerMiddleware) Serve

Serve serves the middleware

type MetricsReporter added in v1.1.0

type MetricsReporter interface {
	Timing(metric string, value time.Duration, tags ...string) error
	Gauge(metrics string, value float64, tags ...string) error
	Increment(metric string, tags ...string) error
}

MetricsReporter interface

func NewMetricsReporter added in v1.1.0

func NewMetricsReporter(config *viper.Viper) (MetricsReporter, error)

NewMetricsReporter ctor

type NewRelicMiddleware

type NewRelicMiddleware struct {
	App    *App
	Logger log.FieldLogger
}

NewRelicMiddleware is responsible for logging to Zap all requests

func NewNewRelicMiddleware

func NewNewRelicMiddleware(app *App, theLogger log.FieldLogger) *NewRelicMiddleware

NewNewRelicMiddleware returns the logger middleware

func (*NewRelicMiddleware) Serve

Serve serves the middleware

type RecoveryMiddleware

type RecoveryMiddleware struct {
	OnError func(error, []byte)
}

RecoveryMiddleware recovers from errors

func NewRecoveryMiddleware

func NewRecoveryMiddleware(onError func(error, []byte)) *RecoveryMiddleware

NewRecoveryMiddleware returns a configured middleware

func (*RecoveryMiddleware) Serve

Serve executes on error handler when errors happen

type ResponseTimeMetricsMiddleware added in v1.1.0

type ResponseTimeMetricsMiddleware struct {
	DDStatsD *DogStatsD
}

ResponseTimeMetricsMiddleware struct encapsulating DDStatsD

func NewResponseTimeMetricsMiddleware added in v1.1.0

func NewResponseTimeMetricsMiddleware(ddStatsD *DogStatsD) *ResponseTimeMetricsMiddleware

ResponseTimeMetricsMiddleware returns a new ResponseTimeMetricsMiddleware

func (ResponseTimeMetricsMiddleware) Serve added in v1.1.0

func (responseTimeMiddleware ResponseTimeMetricsMiddleware) Serve(next echo.HandlerFunc) echo.HandlerFunc

ResponseTimeMetricsMiddleware is a middleware to measure the response time of a route and send it do StatsD

type SentryMiddleware

type SentryMiddleware struct {
	App *App
}

SentryMiddleware is responsible for sending all exceptions to sentry

func NewSentryMiddleware

func NewSentryMiddleware(app *App) *SentryMiddleware

NewSentryMiddleware returns a new sentry middleware

func (*SentryMiddleware) Serve

Serve serves the middleware

type VersionMiddleware

type VersionMiddleware struct {
	Version string
}

VersionMiddleware inserts the current version in all requests

func NewVersionMiddleware

func NewVersionMiddleware() *VersionMiddleware

NewVersionMiddleware with API version

func (*VersionMiddleware) Serve

Serve serves the middleware

Jump to

Keyboard shortcuts

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