Skip to content

zerodha/fastglue-adapter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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())
	}
}

The MIT License (MIT)

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

About

net/http adapter for fastglue

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages