routeBuilder

package
v1.0.21 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2022 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseBuilder

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

BaseBuilder is the core builder in here all the routes and middlewares are rememberd

type ContentType

type ContentType uint8

ContentType represends a content type

const (
	// JSON is a content type
	JSON ContentType = iota
	// HTML is a content type
	HTML
)

func (ContentType) String

func (c ContentType) String() string

type M

type M struct {
	Tags []Tag
	Fn   fiber.Handler
}

M gives this package more information about a middleware

type Method

type Method uint8

Method represends a http method

const (
	// Get is a http method
	Get Method = iota
	// Post is a http method
	Post
	// Patch is a http method
	Patch
	// Put is a http method
	Put
	// Delete is a http method
	Delete
)

func (Method) String

func (m Method) String() string

type OpenAPI

type OpenAPI struct {
	OpenAPI    string                     `json:"openapi"` // Version
	Info       *OpenAPIInfo               `json:"info,omitempty"`
	Servers    []OpenAPIServer            `json:"servers,omitempty"`
	Paths      map[string]OpenAPIPathItem `json:"paths,omitempty"`
	Components *OpenAPIComponents         `json:"components,omitempty"`
	// Security   []OpenAPISecurityRequirement `json:"security,omitempty"` // TODO
	Tags []Tag `json:"tags,omitempty"`
}

OpenAPI implements the root OpenAPI Response Object Ref: https://swagger.io/specification/#oas-object

type OpenAPIComponents

type OpenAPIComponents struct {
	Schemas map[string]any `json:"schemas,omitempty"`
}

OpenAPIComponents implements the OpenAPI Components Ref: https://swagger.io/specification/#components-object

type OpenAPIContact

type OpenAPIContact struct {
	Name  string `json:"name,omitempty"`
	URL   string `json:"url,omitempty"`
	Email string `json:"email,omitempty"`
}

OpenAPIContact implements the OpenAPI Contact Object Ref: https://swagger.io/specification/#contact-object

type OpenAPIInfo

type OpenAPIInfo struct {
	Title          string         `json:"title,omitempty"`
	Description    string         `json:"description,omitempty"`
	TermsOfService string         `json:"termsOfService,omitempty"`
	Contact        OpenAPIContact `json:"contact,omitempty"`
	License        OpenAPILicense `json:"license,omitempty"`
	Version        string         `json:"version,omitempty"`
}

OpenAPIInfo contains information about the API. Ref: https://swagger.io/specification/#info-object

type OpenAPILicense

type OpenAPILicense struct {
	Name string `json:"name,omitempty"`
	URL  string `json:"url,omitempty"`
}

OpenAPILicense implements the OpenAPI License Object Ref: https://swagger.io/specification/#license-object

type OpenAPIMediaType

type OpenAPIMediaType struct {
	Schema   any            `json:"schema,omitempty"`
	Example  any            `json:"example,omitempty"`
	Examples map[string]any `json:"examples,omitempty"`
}

OpenAPIMediaType implements the me OpenAPI Media Type Object Ref: https://swagger.io/specification/#media-type-object

type OpenAPIOperation

type OpenAPIOperation struct {
	Tags        []string `json:"tags,omitempty"`
	Summary     string   `json:"summary,omitempty"`
	Description string   `json:"description,omitempty"`
	// ExternalDocs any `json:"externalDocs,omitempty"` // TODO
	OperationID string                     `json:"operationId,omitempty"`
	Parameters  []OpenAPIParameter         `json:"parameters,omitempty"`
	RequestBody *OpenAPIRequestBody        `json:"requestBody,omitempty"`
	Responses   map[string]OpenAPIResponse `json:"responses,omitempty"`
	// Callbacks any `json:"callbacks,omitempty"` // TODO
	Deprecated bool `json:"deprecated,omitempty"`
	// Security   []OpenAPISecurityRequirement `json:"security,omitempty"` // TODO
	Servers []OpenAPIServer `json:"servers,omitempty"`
}

OpenAPIOperation implements the OpenAPI Operation Object Ref: https://swagger.io/specification/#operation-object

type OpenAPIParameter

type OpenAPIParameter struct {
	Name            string `json:"name,omitempty"`
	In              string `json:"in,omitempty"`
	Description     string `json:"description,omitempty"`
	Required        bool   `json:"required,omitempty"`
	Deprecated      bool   `json:"deprecated,omitempty"`
	AllowEmptyValue bool   `json:"allowEmptyValue,omitempty"`
	//
	Style         string `json:"style,omitempty"`
	Explode       bool   `json:"explode,omitempty"`
	AllowReserved bool   `json:"allowReserved,omitempty"`
	Schema        any    `json:"schema,omitempty"`
	Example       any    `json:"example,omitempty"`
	Examples      any    `json:"examples,omitempty"`
}

OpenAPIParameter implements the OpenAPI Parameter Object Ref: https://swagger.io/specification/#parameter-object

type OpenAPIPathItem

type OpenAPIPathItem struct {
	Ref         string             `json:"$ref,omitempty"`
	Summary     string             `json:"summary,omitempty"`
	Description string             `json:"description,omitempty"`
	Get         *OpenAPIOperation  `json:"get,omitempty"`
	Put         *OpenAPIOperation  `json:"put,omitempty"`
	Post        *OpenAPIOperation  `json:"post,omitempty"`
	Delete      *OpenAPIOperation  `json:"delete,omitempty"`
	Options     *OpenAPIOperation  `json:"options,omitempty"`
	Head        *OpenAPIOperation  `json:"head,omitempty"`
	Patch       *OpenAPIOperation  `json:"patch,omitempty"`
	Trace       *OpenAPIOperation  `json:"trace,omitempty"`
	Servers     []OpenAPIServer    `json:"servers,omitempty"`
	Parameters  []OpenAPIParameter `json:"parameters,omitempty"`
}

OpenAPIPathItem implements the OpenAPI Path Item Object Ref: https://swagger.io/specification/#path-item-object

type OpenAPIRequestBody

type OpenAPIRequestBody struct {
	Description string                      `json:"description,omitempty"`
	Content     map[string]OpenAPIMediaType `json:"content,omitempty"`
	Required    bool                        `json:"required,omitempty"`
}

OpenAPIRequestBody implements the OpenAPI Request Body Object Ref: https://swagger.io/specification/#request-body-object

type OpenAPIResponse

type OpenAPIResponse struct {
	Description string `json:"description,omitempty"`
	// Headers map[string]OpenAPIHeader // TODO
	Content map[string]OpenAPIMediaType `json:"content,omitempty"`
}

OpenAPIResponse implements the OpenAPI Response Object Ref: https://swagger.io/specification/#response-object

type OpenAPIServer

type OpenAPIServer struct {
	URL         string `json:"url,omitempty"`
	Description string `json:"description,omitempty"`
}

OpenAPIServer implements the OpenAPI Server Object Ref: https://swagger.io/specification/#server-object

type R

type R struct {
	// Required
	// You can also use markdown in this field :^)
	Description string

	// Res gives the routes
	Res any
	// OR use res map if there are multiple possible responses
	ResMap map[string]any
	// OR use a completely custom OpenAPIResponse type
	CustomResponse *OpenAPIResponse

	// The main handler for the route
	Fn fiber.Handler

	// Optional
	// Body can be set to hint the route builder what kind of body this request expects
	Body any
	Tags []Tag
}

R gives this package more information about a route From the fiber handler (fn(c *fiber.Ctx) error) we cannot know the expected input and output data

type Route

type Route struct {
	FiberPath           string
	OpenAPIPath         string
	Params              []string
	Kind                string
	Method              Method
	ResponseContentType ContentType
	Info                R
}

Route constains information about a route

type Router

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

Router can be used to define routes and middlwares

func New

func New(app *fiber.App) *Router

New creates a instance of Builder

func (*Router) Delete

func (r *Router) Delete(prefix string, routeDefinition R, middlewares ...M)

Delete defines a DELETE route

func (*Router) Get

func (r *Router) Get(prefix string, routeDefinition R, middlewares ...M)

Get defines a get route with information about the route

func (*Router) Group

func (r *Router) Group(prefix string, group func(*Router), middlewares ...M)

Group prefixes the routes within the group with a route and adds a middleware to them if specified

func (*Router) Patch

func (r *Router) Patch(prefix string, routeDefinition R, middlewares ...M)

Patch defines a PATCH route

func (*Router) Post

func (r *Router) Post(prefix string, routeDefinition R, middlewares ...M)

Post defines a POST route

func (*Router) Put

func (r *Router) Put(prefix string, routeDefinition R, middlewares ...M)

Put defines a PUT route

func (*Router) Routes

func (r *Router) Routes() []Route

Routes returns all routes

func (*Router) Static

func (r *Router) Static(prefix, root string, options ...fiber.Static)

Static defines a static file path We also don't store the static resources as they are not really important to the api users

type Tag

type Tag struct {
	Name        string `json:"name"`
	Description string `json:"description"`
}

Tag is meta information for a route

Jump to

Keyboard shortcuts

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