fastglueadapter

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2021 License: MIT Imports: 4 Imported by: 0

README

Fastglue-Adapter Go Reference Zerodha Tech

Helper functions for converting net/http request handlers to fastglue request handlers.

Overview

A port from fasthttpadaptor. While this function may be used for easy switching from net/http to fastglue, it has the following drawbacks comparing to using manually written fastglue request handler:

  • A lot of useful functionality provided by fastglue is missing from net/http handler such as webhooks.
  • net/http -> fastglue handler conversion has some overhead,so the returned handler will be always slower than manually written fastglue handler.

So it is advisable using this function only for quick net/http -> fastglue switching or unavoidable situations.

Install

go get -u github.com/zerodha/fastglue-adapter

Usage

import "github.com/zerodha/fastglue-adapter"

Example

package main

import (
	"fmt"
	"log"
	"net/http"

	"github.com/valyala/fasthttp"
	"github.com/zerodha/fastglue"
	fga "github.com/zerodha/fastglue-adapter"
)

func request(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, "Hello, %q", r.URL.Path)
}
func main() {
	g := fastglue.NewGlue()
	g.GET("/", fga.NewFastGlueHandlerFunc(request))

	s := &fasthttp.Server{}
	if err := g.ListenAndServe(":8000", "", s); err != nil {
		log.Fatal(err.Error())
	}
}

License

The MIT License (MIT)

Copyright (c) 2020 Zerodha Technology Pvt. Ltd. (India)

Documentation

Overview

Package fastglueadapter provides helper functions for converting net/http request handlers to fastglue request handlers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewFastGlueHandler

func NewFastGlueHandler(h http.Handler) fastglue.FastRequestHandler

NewFastGlueHandler wraps net/http handler to fastglue request handler, so it can be passed to fastglue server.

While this function may be used for easy switching from net/http to fastglue, it has the following drawbacks comparing to using manually written fastglue request handler:

  • A lot of useful functionality provided by fastglue is missing from net/http handler.
  • net/http -> fastglue handler conversion has some overhead, so the returned handler will be always slower than manually written fastglue handler.

So it is advisable using this function only for quick net/http -> fastglue switching. Then manually convert net/http handlers to fastglue handlers according to https://github.com/valyala/fastglue#switching-from-nethttp-to-fasthttp .

func NewFastGlueHandlerFunc

func NewFastGlueHandlerFunc(h http.HandlerFunc) fastglue.FastRequestHandler

NewFastGlueHandlerFunc wraps net/http handler func to fastglue request handler, so it can be passed to fastglue server.

While this function may be used for easy switching from net/http to fastglue, it has the following drawbacks comparing to using manually written fastglue request handler:

  • A lot of useful functionality provided by fastglue is missing from net/http handler such as webhooks.
  • net/http -> fastglue handler conversion has some overhead, so the returned handler will be always slower than manually written fastglue handler.

So it is advisable using this function only for quick net/http -> fastglue switching. Then manually convert net/http handlers to fastglue handlers according to https://github.com/valyala/fasthttp#switching-from-nethttp-to-fasthttp .

Types

This section is empty.

Jump to

Keyboard shortcuts

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