svapi

package module
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2019 License: BSD-3-Clause Imports: 7 Imported by: 0

README

go-svapi

package for easy api developing based on fasthttp

Website | Contributing

license GoDoc Coverage Status Build Status Go Report Card Release

Installation

go get -u github.com/riftbit/go-svapi

Usage

This is a minimal example.

in dev

Documentation

Index

Constants

View Source
const (
	// ContentTypeJSON Content type for JSON
	ContentTypeJSON string = "application/json; charset=utf-8"

	// ContentTypeXML Content type for XML
	ContentTypeXML = "application/xml; charset=utf-8"

	// ContentTypeRssXML Content type for RSS
	ContentTypeRssXML = "application/rss+xml; charset=utf-8"

	// ContentTypeAtomXML Content type for ATOM
	ContentTypeAtomXML = "application/atom+xml; charset=utf-8"

	// ContentTypeHTML Content type for HTML
	ContentTypeHTML = "text/html; charset=utf-8"

	// ContentTypeProtobuf Content type for ProtoBuf
	ContentTypeProtobuf = "application/protobuf"
)

Variables

This section is empty.

Functions

func WriteResponseBytes

func WriteResponseBytes(ctx *fasthttp.RequestCtx, status int, contentType string, resp []byte)

WriteResponseBytes write response to client with status code, body and content type

func WriteResponseString

func WriteResponseString(ctx *fasthttp.RequestCtx, status int, contentType string, resp string)

WriteResponseString write response to client with status code, body and content type

Types

type ErrorHandlerFunction

type ErrorHandlerFunction func(ctx *fasthttp.RequestCtx, err error)

ErrorHandlerFunction type that define function that used to process error from api method

type SVAPI

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

SVAPI - main structure

func NewServer

func NewServer() *SVAPI

NewServer returns a new API server.

func (*SVAPI) CallAPI

func (as *SVAPI) CallAPI(ctx *fasthttp.RequestCtx, method string)

CallAPI call api method and process it. Modifying body after this function not recommended

func (*SVAPI) GetServiceMap

func (as *SVAPI) GetServiceMap() map[string][]string

GetServiceMap returns an api methods list

func (*SVAPI) RegisterService

func (as *SVAPI) RegisterService(receiver interface{}, name string) error

RegisterService adds a new service to the api server.

The name parameter is optional: if empty it will be inferred from the receiver type name.

Methods from the receiver will be extracted if these rules are satisfied:

  • The receiver is exported (begins with an upper case letter) or local (defined in the package registering the service).
  • The method name is exported.
  • The method has one argument: *fasthttp.RequestCtx.
  • All arguments are pointers.
  • The method has return type error that will be processed by error handler method.

All other methods are ignored.

func (*SVAPI) SetErrorHandlerFunction added in v0.5.0

func (as *SVAPI) SetErrorHandlerFunction(errHndl ErrorHandlerFunction)

SetErrorHandlerFunction allows to set custom error handler for api function returned error

Jump to

Keyboard shortcuts

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