apicontext

package
v0.0.0-...-91d05ba Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2020 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	RequestCounterVec = prometheus.NewCounterVec(
		prometheus.CounterOpts{
			Namespace: "http",
			Subsystem: "requests",
			Name:      "number_of_requests",
			Help:      "Total number of requests handled by the API",
		},
		[]string{"endpoint", "method"},
	)
)

RequestCounterVec counts total request per endpoint and method

View Source
var (
	RequestDurationGauge = prometheus.NewGaugeVec(
		prometheus.GaugeOpts{
			Namespace: "http",
			Subsystem: "requests",
			Name:      "request_duration",
			Help:      "Avg time of requests handled by the API",
		},
		[]string{"endpoint", "method"},
	)
)

RequestDurationGauge calculates avg time per endpoint and method

Functions

func CorsHandler

func CorsHandler(w http.ResponseWriter, r *http.Request)

CorsHandler swagger:route OPTIONS /

Handler to respond to CORS preflight requests

Responses:

200: OK

func MonitoringMiddleware

func MonitoringMiddleware(next http.Handler) http.Handler

MonitoringMiddleware writes increments request count and calculates request duration and writes to Prometheus metrics

Types

type APIContext

type APIContext struct {
	MongoClient  mongo.Client
	DatabaseName string
	HandlerFunc  http.HandlerFunc
}

APIContext is the struct holds both Db Context and Handlers

func PrepareContext

func PrepareContext() *APIContext

PrepareContext prepares the database connection, bundles it within an APIContext and returns it

func (*APIContext) Index

func (apiContext *APIContext) Index(w http.ResponseWriter, r *http.Request)

Index swagger:route GET / Index

Handler to show welcome message.

Responses:

200: OK

func (*APIContext) Login

func (apiContext *APIContext) Login(w http.ResponseWriter, r *http.Request)

Login swagger:route POST PUT /user Login

Handler to login the user, returns a JWT Token

Responses:

       200: OK
		  400: Bad Request
		  500: Internal Server Error

func (*APIContext) Refresh

func (apiContext *APIContext) Refresh(w http.ResponseWriter, r *http.Request)

Refresh swagger:route POST PUT /login Refresh

Handler to refresh a JWT Token

Responses:

       200: OK
		  400: Bad Request
		  500: Internal Server Error

type Claims

type Claims struct {
	UserID string `json:"userid"`
	jwt.StandardClaims
}

Claims represents the data for a user login

Jump to

Keyboard shortcuts

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