web

package module
v0.0.0-...-9ecf7b7 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2023 License: MPL-2.0 Imports: 12 Imported by: 1

README

Web lib

An extended handler that runs on HTTP protocol. Use it to support Http in your services.

The handler is defined in handler.go. The HTTP protocol layer is defined in the web.go.

The HTTP protocol is based on valyala/fasthttp.

The messages are received only in POST method. Supports only message.Request in the POST body.

Usage

package main

import (
	"github.com/ahmetson/datatype-lib/data_type/key_value"
	"github.com/ahmetson/datatype-lib/message"
	"github.com/ahmetson/handler-lib/config"
	"github.com/ahmetson/web-lib"
)

func onIndex(req message.Request) *message.Reply {
	return req.Ok(key_value.Empty())
}

func main() {
	handlerConfig, _ := config.NewHandler(config.ReplierType, "web")
	handlerConfig.Port = 80

	handler, _ := web.New()
	handler.SetConfig(handlerConfig)
	_ = handler.Route("index", onIndex)
	_ = handler.Start()
}

Todo

  • Add a routing to map to the GET paths.
  • Add support for the raw message

Documentation

Index

Constants

View Source
const (
	LayerRunning = "running"
	LayerClosed  = "closed"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler struct {
	*base.Handler
	// contains filtered or unexported fields
}

func New

func New() *Handler

func (*Handler) SetConfig

func (web *Handler) SetConfig(handler *config.Handler)

func (*Handler) SetLogger

func (web *Handler) SetLogger(parent *log.Logger) error

SetLogger sets the logger.

func (*Handler) Start

func (web *Handler) Start() error

func (*Handler) Type

func (web *Handler) Type() config.HandlerType

Jump to

Keyboard shortcuts

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