qshttp

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2023 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EnvAddress = "HTTP_ADDRESS"
	EnvPort    = "HTTP_PORT"
)

Variables

View Source
var (
	ErrNoPort      = errors.New("port not found")
	ErrPortInvalid = errors.New("port is invalid")
	ErrPortNotOpen = errors.New("port is not open")
)

Functions

func ProvideHttpConfigs

func ProvideHttpConfigs(typ qsconfig.ConfigType[*HttpConfigs]) fx.Option

Validate, then provide the app with an HTTP server. This is required if you need to use custom routers such as Gin and Chi

To use this:

var Module = fx.Options(
	qshttp.ProvideHttpConfigs(&qshttp.EnvConfigType{})
)

this code will provide a new default instance of a qshttp.HttpConfigs that can be used to instantiate a http.Server.

in case you want to customize a qshttp.HttpConfig yourself, implements:

qsconfig.ConfigType[*HttpConfigs]

If you need custom dependencies, don't use this, instead, create a fx.Option yourself:

 fx.Provide(func (dep *Dependencies) (*qshttp.HttpConfigs, error) {
		// Do something
		return &qshttp.HttpConfigs{
			// Options here
		}
 })

func ProvideServer

func ProvideServer[H http.Handler]() fx.Option

Create an HTTP server, provided the configs and the HTTP handlers. First, create a config

	var Module = fx.Options(
		qshttp.ProvideHttpConfigs(&qshttp.EnvConfigType{}),
		qsgin.ProvideRouter(&qs)
 )

Types

type EnvConfigType

type EnvConfigType struct{}

Requires these following environment variables

  • HTTP_ADDRESS: Optional, if empty, it defaults to localhost or 127.0.0.1
  • HTTP_PORT: Required, the TCP port for the HTTP server to attach and listen to

func (*EnvConfigType) Config

func (t *EnvConfigType) Config() (*HttpConfigs, error)

type HttpConfigs

type HttpConfigs struct {
	Address string
	Port    string
	OnStart func(args interface{}) error
	OnStop  func(args interface{}) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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