http

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2022 License: BSD-3-Clause Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GenericErrorMessage = "An error occurred"
)
View Source
const ShutdownTimeout = 1 * time.Second

ShutdownTimeout is the time given for outstanding requests to finish before shutdown.

Variables

This section is empty.

Functions

func ErrorResponseJSON

func ErrorResponseJSON(c echo.Context, err error, details interface{}) error

ErrorResponseJSON returns an HTTP error response with JSON content.

func ListenAndServeTLSRedirect

func ListenAndServeTLSRedirect(domain string) error

ListenAndServeTLSRedirect runs an HTTP server on port 80 to redirect users to the TLS-enabled port 443 server.

func MessageFromErr

func MessageFromErr(err error) string

MessageFromErr returns the message for the given app error. EINTERNAL & EUNKNOWN message is obscured by HTTP response.

func StatusCodeFromErr

func StatusCodeFromErr(err error) int

StatusCodeFromErr returns the HTTP status code for the given app error.

func SuccessResponseJSON

func SuccessResponseJSON(c echo.Context, httpCode int, data interface{}) error

SuccessResponseJSON returns a JSON response with the given status code and data.

Types

type ErrorAPI

type ErrorAPI struct {
	Code    string      `json:"code"`
	Message string      `json:"message"`
	Details interface{} `json:"details"`
}

ErrorAPI represents an error returned by the API.

func NewErrorAPI

func NewErrorAPI(err error, details interface{}) *ErrorAPI

NewErrorAPI returns an ErrorAPI instance.

type ServerAPI

type ServerAPI struct {

	// Addr Bind address for the server.
	Addr string
	// Domain name to use for the server.
	// If specified, server is run on TLS using acme/autocert.
	Domain string

	// JWTSecret is the secret used to sign JWT tokens.
	JWTSecret string

	// service handler
	ServiceHandler *handler.ServiceHandler

	// loggin service used by HTTP Server.
	LogService log.Logger
	// contains filtered or unexported fields
}

ServerAPI is the main server for the API

func NewServerAPI

func NewServerAPI() *ServerAPI

NewServerAPI creates a new API server.

func (*ServerAPI) AuthLoginHandler

func (s *ServerAPI) AuthLoginHandler(c echo.Context) error

AuthLoginHandler handles the login request.

func (*ServerAPI) AuthLogoutHandler

func (s *ServerAPI) AuthLogoutHandler(c echo.Context) error

AuthLogoutHandler handles the logout request.

func (*ServerAPI) AuthRefreshHandler

func (s *ServerAPI) AuthRefreshHandler(c echo.Context) error

AuthRefreshHandler handles the refresh request.

func (*ServerAPI) AuthRegisterHandler

func (s *ServerAPI) AuthRegisterHandler(c echo.Context) error

AuthRegisterHandler handles the register request.

func (*ServerAPI) Close

func (s *ServerAPI) Close() error

func (*ServerAPI) ContractCallHandler added in v0.0.7

func (s *ServerAPI) ContractCallHandler(c echo.Context) error

ContractCallHandler is the handler for the /contract/:id/call API.

func (*ServerAPI) ContractCallRevHandler added in v0.0.7

func (s *ServerAPI) ContractCallRevHandler(c echo.Context) error

ContractCallRevHandler is the handler for the /contract/:id/call/:rev API.

func (*ServerAPI) ContractCreateHandler added in v0.0.7

func (s *ServerAPI) ContractCreateHandler(c echo.Context) error

ContractCreateHandler is the handler for the /contract create API.

func (*ServerAPI) ContractHandler added in v0.0.7

func (s *ServerAPI) ContractHandler(c echo.Context) error

ContractHandler is the handler for the /contract/:id search API.

func (*ServerAPI) ContractMakeRevisionHandler added in v0.0.7

func (s *ServerAPI) ContractMakeRevisionHandler(c echo.Context) error

ContractMakeRevisionHandler is the handler for the /contract/:id/revision create API.

func (*ServerAPI) ContractUpdateHandler added in v0.0.7

func (s *ServerAPI) ContractUpdateHandler(c echo.Context) error

ContractUpdateHandler is the handler for the /contract/:id update API.

func (*ServerAPI) HTTPContextMiddleware

func (s *ServerAPI) HTTPContextMiddleware(next echo.HandlerFunc) echo.HandlerFunc

HTTPContextMiddleware is the middleware for setting the HTTP tag in the context.

func (*ServerAPI) JWTVerifyMiddleware

func (s *ServerAPI) JWTVerifyMiddleware(next echo.HandlerFunc) echo.HandlerFunc

JWTVerifyMiddleware is the middleware for validating JWT tokens. It is used for all routes that require authentication. Once the token is successfully parsed, checks if user exists with the auth stored in the claims.

func (*ServerAPI) Open

func (s *ServerAPI) Open() (err error)

Open validates the server options and start it on the bind address.

func (*ServerAPI) Port

func (s *ServerAPI) Port() int

Port returns the TCP port for the running server. This is useful in tests where we allocate a random port by using ":0".

func (*ServerAPI) RecoverPanicMiddleware

func (s *ServerAPI) RecoverPanicMiddleware(next echo.HandlerFunc) echo.HandlerFunc

RecoverPanicMiddleware is the middleware for handling panics.

func (*ServerAPI) Scheme

func (s *ServerAPI) Scheme() string

Scheme returns the scheme used by the server.

func (*ServerAPI) URL

func (s *ServerAPI) URL() string

URL returns the URL for the server. This is useful in tests where we allocate a random port by using ":0".

func (*ServerAPI) UseTLS

func (s *ServerAPI) UseTLS() bool

UseTLS returns true if the server is using TLS.

func (*ServerAPI) UserHandler

func (s *ServerAPI) UserHandler(c echo.Context) error

UserHandler is the handler for the /user API.

func (*ServerAPI) UserUpdateHandler

func (s *ServerAPI) UserUpdateHandler(c echo.Context) error

UserUpdateHandler is the handler for the /user update API.

func (*ServerAPI) VmStatsHandler

func (s *ServerAPI) VmStatsHandler(c echo.Context) error

Jump to

Keyboard shortcuts

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