Help us shape the future of Go! Take the 2026 Go Developer Survey

svapi

package module
v0.5.0 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 = "application/json; charset=utf-8"

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

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

	// ContentTypeAtom 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)

SendPushFunction type that define function that used to send push

type SVAPI

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

SVAPI - main structure

func NewServer

func NewServer() *SVAPI

NewServer returns a new RPC 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, error)

GetServiceMap returns an json api schema todo realize this function

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 three arguments: *fasthttp.RequestCtx, *args, *reply.
  • All three arguments are pointers.
  • The second and third arguments are exported or local.
  • The method has return type error.

All other methods are ignored.

func (*SVAPI) SetErrorHandlerFunction added in v0.5.0

func (as *SVAPI) SetErrorHandlerFunction(errHndl ErrorHandlerFunction)

Jump to

Keyboard shortcuts

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