httpeasy

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2023 License: MIT Imports: 9 Imported by: 0

README

MIT license codecov lint workflow Help wanted

httpeasy

The package provides everything to create a simple web service. You merely have to announce handlers.

1. Installation

Use go get.

go get github.com/kaatinga/httpeasy

Then import the validator package into your own code.

import "github.com/kaatinga/httpeasy"

2. Usage

Prepare a function that complies with SetUpHandlers type. The function should contain some routes, for example:

func SetUpHandlers(r *httprouter.Router) {
    r.GET("/", Welcome)
}

The package contains a ready config model, set field values in that structure, easies way is to use settings package:

err := settings.LoadSettings(&config.Config)
if err != nil {
    ...
}

Run your server:

err = config.Config.Launch(SetUpHandlers)
if err != nil {
    ...
}

Documentation

Overview

Package httpeasy package is intended for quick web service development.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Adapt added in v0.4.7

func Adapt(next httprouter.Handle, adapters ...Adapter) httprouter.Handle

Adapt composes handlers chain end executes it.

Types

type Adapter added in v0.4.7

type Adapter func(httprouter.Handle) httprouter.Handle

type Config

type Config struct {
	ProductionMode    bool          `env:"PROD"`
	SSL               SSL           `validate:"required_if=ProductionMode true"`
	Port              uint16        `env:"PORT" validate:"min=80,max=65535"`
	ReadTimeout       time.Duration `env:"READ_TIMEOUT" default:"1m"`
	ReadHeaderTimeout time.Duration `env:"READ_HEADER_TIMEOUT" default:"15s"`
	WriteTimeout      time.Duration `env:"WRITE_TIMEOUT" default:"1m"`
	// contains filtered or unexported fields
}

Config - http service configuration compatible to settings package. https://github.com/kaatinga/settings

func NewConfig

func NewConfig() *Config

NewConfig creates new config model that later can be processed by settings package or updated manually.

func (*Config) Init added in v1.1.1

func (config *Config) Init()

func (*Config) Launch

func (config *Config) Launch(handlers SetUpHandlers) error

Launch enables the configured web service with the handlers that announced in a function matched with SetUpHandlers type.

func (*Config) Terminate added in v1.1.1

func (config *Config) Terminate()

type SSL

type SSL struct {
	Domain string `env:"DOMAIN" validate:"fqdn"`
	Email  string `env:"EMAIL" validate:"email"`
}

type SetUpHandlers

type SetUpHandlers func(r *httprouter.Router)

SetUpHandlers type to announce handlers.

Jump to

Keyboard shortcuts

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