Categorygithub.com/iamaredfoxx/arah
modulepackage
0.0.0-20230303024000-fcf067bdb618
Repository: https://github.com/iamaredfoxx/arah.git
Documentation: pkg.go.dev

# README

Arah by 🦊

Library for managing host and route HTTP based on Echo.



Content

  1. Quickplay
  2. Host
  3. Route
  4. Start HTTP



Quickplay

Back to top


You need to setup hosts and routes, then start the HTTP server, for example.

package main

import (
    "net/http"

    "github.com/iamaredfoxx/arah"
    "github.com/labstack/echo/v4"
)

func main() {
    arah.Register(

        // register host
        arah.HostHandler{
            Route: []arah.RouteInterface{
                exampleRoute{}, // initiate the route
            },
        },

    )

    // serve HTTP
    arah.Bind(
        arah.Start{
            Port: "8080",
        },
    )
}

// This is route
type exampleRoute struct {}

func (exampleRoute) Create(rp arah.RoutePathInterface) {
    rp.Get("/example", func (c echo.Context) error {
        return c.String(http.StatusOK, "example")
    })
}



Host

Back to top


Don't you think you need different host for different section too 😉




Hostname

Back to top


You can specify the hostname by filling in the hostname option.

Default host is required, to do so you can fill the hostname config with "" (empty string)

arah.HostHandler{
    Hostname: "book.example.com"
}



Config

Back to top


More configuration for the host that you can do.

type HostConfiguration struct {
	Debug            bool
	HideBanner       bool
	DisableHTTP2     bool
	ReadTimeout      int64
	WriteTimeout     int64
	Listener         net.Listener
	Validator        echo.Validator
	Binder           echo.Binder
	Renderer         echo.Renderer
	IPExtractor      echo.IPExtractor
	Middleware       []echo.MiddlewareFunc
	HTTPErrorHandler func(err error, c echo.Context)
}

for more detail check out https://echo.labstack.com/guide/customization



List Route

Back to top


Register all your routes in here, like so.

arah.HostHandler{
    Route: []arah.RouteInterface{
        exampleRoute{},
    }
}



Route

Back to top


This is all you can do for now.

Group(group string, f func(rg RoutePathInterface), m ...echo.MiddlewareFunc)

Get(prefix string, f echo.HandlerFunc, m ...echo.MiddlewareFunc) *routePath

Post(prefix string, f echo.HandlerFunc, m ...echo.MiddlewareFunc) *routePath

Put(prefix string, f echo.HandlerFunc, m ...echo.MiddlewareFunc) *routePath

Patch(prefix string, f echo.HandlerFunc, m ...echo.MiddlewareFunc) *routePath

Delete(prefix string, f echo.HandlerFunc, m ...echo.MiddlewareFunc) *routePath

Any(prefix string, f echo.HandlerFunc, m ...echo.MiddlewareFunc) []*routePath

Use(middleware ...echo.MiddlewareFunc)

Use all of that like this

type exampleRoute struct {}

func (exampleRoute) Create(rp arah.RoutePathInterface) {

    rp.Use(func(next HandlerFunc) HandlerFunc{
        // should be return next
    })

    rp.Group("/example", f func(rg RoutePathInterface) {
        rg.Get("/" func (c echo.Context) error {
            // should be return Echo response
        })
    })

    rp.Get("/example", func (c echo.Context) error {
        // should be return Echo response
    })

    rp.Post("/example", func (c echo.Context) error {
        // should be return Echo response
    })

    rp.Put("/example", func (c echo.Context) error {
        // should be return Echo response
    })

    rp.Patch("/example", func (c echo.Context) error {
        // should be return Echo response
    })

    rp.Delete("/example", func (c echo.Context) error {
        // should be return Echo response
    })

    rp.Any("/example", func (c echo.Context) error {
        // should be return Echo response
    })

}



Start HTTP

Back to top


To start HTTP you need different method, for example

arah.Bind(
    arah.Start{
        Port: "8080",
    },
)

All start struct you can use

// Start HTTP
type Start struct {
	Port string
}

// Start HTTP with TLS
type StartTLS struct {
	Port              string
	CertFile, KeyFile interface{}
}


// Start HTTP with auto creating TLS
type StartAutoTLS struct {
	Port string
}


// Start HTTP 2
type StartH2CServer struct {
	Port  string
	HTTP2 http2.Server
}


// Start HTTP with custom configuration HTTP Server
type StartServer struct {
	Server http.Server
}

// If echo has custom Listener, run this one
type StartListener struct {
}

For more detail check out https://echo.labstack.com/guide/http_server

# Functions

Bind Default Host into http and serve it.
Return Host with specified name.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Return Route Path with specified name.
Register the Host Handler.

# Variables

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

Host configuration.
The host handler.
Start HTTP.
Start HTTP with auto creating TLS.
Start HTTP 2.
If echo has custom Listener, run this one.
Start HTTP with custom configuration HTTP Server.
Start HTTP with TLS.

# Interfaces

Route Implementation.
Route Path Implementation.
Start Implementation.