webapi

package
v0.0.0-...-6fa6eff Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FIZZBUZZ_RESOURCE_ROUTE = "/fizzbuzz"
	FIZZBUZZ_RESOURCE_NAME  = "fizzbuzz"
)
View Source
const (
	STATS_RESOURCE_ROUTE     = "/stats"
	STATS_RESOURCE_NAME      = "stats"
	STATS_DB_COLLECTION_NAME = "access_events"
)

Variables

This section is empty.

Functions

func FizzBuzzHandler

func FizzBuzzHandler(c *gin.Context)

FizzBuzzHandler godoc @Summary Return Fizzbuzz resource @Description get custom Fizzbuzz @Produce json @Param int1 query int true "int1 query parameter" @Param int2 query int true "int2 query parameter" @Param limit query int true "limit query parameter" @Param str1 query string true "str1 query parameter" @Param str2 query string true "str2 query parameter" @Router /fizzbuzz [get]

Types

type APIHandler

type APIHandler interface {
	StatsHandler() gin.HandlerFunc
}

Handler interface for Api server

func NewAPIHandler

func NewAPIHandler(db db.Client) APIHandler

NewAPIHandler create an api handler with injected db client

type APIMiddleware

type APIMiddleware interface {
	StatsMiddleware() gin.HandlerFunc
}

func NewAPIMiddleware

func NewAPIMiddleware(db db.Client) APIMiddleware

New NewAPIMiddleware create an apiMiddleware with injected db client

type AccessEvent

type AccessEvent struct {
	Resource   string              `bson:"resource"`
	Method     string              `bson:"method"`
	Date       time.Time           `bson:"date"`
	Uri        string              `bson:"uri"`
	Parameters map[string][]string `bson:"parameters"`
}

AccessEvent represents a db document of the collection "access_event" holding all api access events

type Config

type Config struct {
	Env     string
	BaseUrl string
	Port    string
}

Config Configuration for web server

type ErrorResponse

type ErrorResponse struct {
	Status  int
	Errors  []string `json:"errors,omitempty"`
	Message string   `json:"message"`
}

ErrorResponse

type Fizzbuzz

type Fizzbuzz struct {
	Int1  int    `schema:"int1,required"`
	Int2  int    `schema:"int2,required"`
	Limit int    `schema:"limit,required"`
	Str1  string `schema:"str1,required"`
	Str2  string `schema:"str2,required"`
}

Fizzbuzz represents the resource payload

type Server

type Server struct {
	Conf       Config
	DBClient   db.Client
	Router     *gin.Engine
	Middleware APIMiddleware
	Handler    APIHandler
}

Server representing a web server and its dependeincies

func (*Server) InitServer

func (s *Server) InitServer()

@title LeBonCoin test fizzbuzz @version 1.0 @description LeBonCoin test fizzbuzz @contact.name Momzor @contact.email m.benaida.pro@gmail.com @license.url https://www.gnu.org/licenses/quick-guide-gplv3.html

type Stats

type Stats struct {
	Hits       int                 `bson:"count"`
	Parameters map[string][]string `bson:"parameters"`
	Resource   string              `bson:"resource"`
}

Stats struct representing the Stats resrouce

Jump to

Keyboard shortcuts

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