httprouteradapter

package module
v0.0.0-...-0c633ec Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2023 License: MIT Imports: 4 Imported by: 0

README

httprouter-adapter

httprouter-adapter is an adapter designed to seamlessly integrate httprouter with qiwlar, a lightweight web framework for Go. Additionally, it provides a convenient decorator called Params() to retrieve all path parameters.

Example Usage

Here's an example of how to use httprouter-adapter in your Go application:

// main.go

package main

import (
    httprouteradapter "github.com/levnikort/httprouter-adapter"
    "github.com/levnikort/qiwlar"
    "net/http"
)

func main() {
    http.ListenAndServe(
        ":8080",
        qiwlar.New(
            nil,
            httprouteradapter.New(),
        ),
    )
}

// app_controller.go

package auth

import (
    "fmt"
    d "github.com/levnikort/qiwlar/decorator"
    hrd "github.com/levnikort/httprouter-adapter/decorator"
    "github.com/levnikort/qiwlar"
    "github.com/julienschmidt/httprouter"
)

type AppController struct {
    qiwlar.Controller
}

func (ac *AppController) Inject() interface{} {
    return func() {}
}

func (ac *AppController) Initialize() {
    ac.Equip("auth")(
        hrd.Params(),
        d.Post("sign-in/:id"),
        func(params httprouter.Params) string {
            fmt.Println(b)
            return "id - " + params.ByName("id")
        },
    )
}

In this example, we import httprouter-adapter and use it in conjunction with qiwlar to create a web server. The Params() decorator is applied to a route, allowing you to easily access path parameters in your request handler.

By using httprouter-adapter, you can streamline the integration of httprouter with qiwlar in your Go web applications, making it easier to build robust and efficient RESTful APIs.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HRAdapter

type HRAdapter struct {
	httprouter.Router
}

func New

func New() *HRAdapter

func (*HRAdapter) AddRoute

func (hra *HRAdapter) AddRoute(pattern, httpMethod string, handler http.HandlerFunc)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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