api

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2023 License: MIT Imports: 7 Imported by: 0

README

API

Static Badge Build Go Reference codecov Release Go Report Card codebeat badge License

API is a package to provide http server with commons features. The core use the echo framework.

Install

$> go get github.com/gofast-pkg/api@latest

Usage

// Read documentation for more details usages
// With New(), api assume that you initialize the configuration with viper.
// Else, call the NewWithConfig() method to get you api instance.
import (
    "github.com/spf13/viper"
    "github.com/go-fast/api"
)

func main() {
    viper.AutomaticEnv()

    api, err := server.New()
    if err != nil {
        panic(err)
    }
    if err = s.Start(); err != nil {
        panic(err)
    }
}

Contributing

 ❕  Use issues for everything

Read more informations with the CONTRIBUTING_GUIDE

For all changes, please update the CHANGELOG.txt file by replacing the existant content.

Thank you  🙏  👍 

Made with contrib.rocks.

Licence

MIT

Documentation

Overview

Package api: provides a simple way to create a new API This package is a wrapper of echo framework. https://echo.labstack.com/ The package api is ready for integration with swagger.

Index

Constants

View Source
const (
	CONF_HTTP_PORT    = "HTTP_PORT"
	CONF_HTTP_SSL     = "HTTP_SSL_ENABLE"
	CONF_HTTP_CERT    = "HTTP_SSL_CERT"
	CONF_HTTP_KEY     = "HTTP_SSL_KEY"
	CONF_HTTP_SWAGGER = "HTTP_SWAGGER_ENABLE"
)

Variables

View Source
var (
	// ConfigurationPrefix is the prefix for the configuration keys.
	// Default is empty.
	// Example:
	//   - if ConfigurationPrefix is "APP", the configuration key for host will be "APP_PGSQL_HOST".
	// After the call to config(), the ConfigurationPrefix is reset to empty.
	ConfigurationPrefix = ""
)
View Source
var (
	// ErrMissingConfig is the error returned when a config key is missing.
	ErrMissingConfig = errors.New("missing config key")
)

Functions

This section is empty.

Types

type API

type API interface {
	// SubRouter return with the prefix path specified on parameter
	// jwtSecure is a flag to enable jwt middleware
	// the jwtSecure is not implemented yet
	SubRouter(prefix string, jwtSecure bool) (*echo.Group, error)
	// Start run the server on the port specified on config
	Start() error
}

API wrap the echo framwork Provides a simple way to create a new API Featuring wiht healthcheck and swagger endpoints

func New

func New() (API, error)

New instance of API. The config is loaded automatically. New method assume that the loader is initialized via viper.

func NewWithConfig

func NewWithConfig(c Config) (API, error)

NewWithConfig instance of API. The config is loaded from parameter.

type Config

type Config struct {
	Port    string
	SSL     SSL
	Swagger bool
}

Config support to the server

type Handler

type Handler struct{}

func (Handler) Healthcheck

func (h Handler) Healthcheck(c echo.Context) error

Healthcheck method @Summary Healthcheck @Description return the healthcheck of the service @Tags healthcheck @Produce json @Success 200 {object} Healthcheck @Router /healthcheck [get]

type Healthcheck

type Healthcheck struct {
	Health bool `json:"health"`
}

Healthcheck model to describe the response http of the healthcheck endpoint. @Description return the healthcheck of the service @Description Health field is true if the service is healthy

type SSL

type SSL struct {
	Cert   string
	Key    string
	Enable bool
}

SSL specification app

Jump to

Keyboard shortcuts

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