rest

package
v0.0.0-...-1903c5f Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2020 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MimeTypeJSON = "application/json"
	MimeTypeYAML = "application/x.yaml"
)
View Source
const (
	API_CALLED_METHOD string = "API call %v, method %v"
	API_CALLED_PARAM  string = "API call with param %s = %v"
	API_CALLED_BODY   string = "API call with body = %v"

	ENVIRONMENT_CREATED string = "Environment %s created"
	ENVIRONMENT_UPDATED string = "Environment %s updated"

	USER_LOGIN  string = "User %s logged, token %s"
	USER_LOGOUT string = "User logged out, token %s"
	TIME_REPORT string = "execution of (%s:%d) took %s \n"

	ERROR_NO_BODY string = "Please send a request body"
	ERROR_CONTENT string = "An error occured %s: %s"

	VALUE_STORED  string = "Value %s:%s has been stored"
	VALUE_DELETED string = "Value %s has been deleted"
)

Variables

View Source
var (
	TScript *log.Logger
	TLog    *log.Logger
	TTime   *log.Logger
	TResult *log.Logger
)

Functions

func BodyMw

func BodyMw(h http.Handler) http.Handler

The BodyMw middleware checks that the request body is not empty and log its content. Its will return an http.StatusBadRequest if the request doesn't have a body

func FilterKeyFound

func FilterKeyFound(key, message string, w http.ResponseWriter) (callerShouldReturn bool)

func FilterSecretKeyFound

func FilterSecretKeyFound(key, message string, w http.ResponseWriter) (callerShouldReturn bool)

func Init

func Init(logger *log.Logger, port int)

Starts the API

func LogMw

func LogMw(h http.Handler) http.Handler

The LogMw middleware logs the url and method for the http request

func NewRouter

func NewRouter(routes Routes) *mux.Router

func Serve

func Serve()

Types

type ApiInfo

type ApiInfo struct {
	Version            string
	Host               string
	Url                string
	EnvironmentDetails *EnvironmentDetails `json:",omitempty"`
	Err                string
}

type EnvironmentDetails

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

func (EnvironmentDetails) MarshalJSON

func (r EnvironmentDetails) MarshalJSON() ([]byte, error)

type EnvironmentLoadRequest

type EnvironmentLoadRequest struct {
	Location string `json:"location"`
}

type FakeInitRequest

type FakeInitRequest struct {
	Location string `json:"location"`
}

type Location

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

type LoginRequest

type LoginRequest struct {
	User     string `json:"user"`
	Password string `json:"pwd"`
}

type LoginResponse

type LoginResponse struct {
	User     string `json:"user"`
	Password string `json:"pwd"`
}

type Middleware

type Middleware func(http.Handler) http.Handler
var (
	IdMw Middleware = createParamMv("id")
)

type Middlewares

type Middlewares []Middleware

type Route

type Route struct {
	Name        string
	Method      string
	Pattern     string
	HandlerFunc http.HandlerFunc
	Middlewares Middlewares
}

type Routes

type Routes []Route

type StorePostRequest

type StorePostRequest struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

Jump to

Keyboard shortcuts

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