http

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2020 License: MIT Imports: 12 Imported by: 2

Documentation

Overview

Package http implements the HTTP transport protocol.

Index

Constants

View Source
const (
	DebugMode   = "debug"
	TestMode    = "testing"
	ReleaseMode = "release"
)

Variables

View Source
var (
	DefaultReadTimeout  = 60 * time.Second
	DefaultWriteTimeout = 60 * time.Second
	DefaultMode         = DebugMode
)

Functions

func NewRouter

func NewRouter(logger *zap.Logger, group Group, validator *validator.CustomValidator) (*echo.Echo, error)

NewRouter returns a new Echo router.

Types

type Group added in v0.6.0

type Group func(*echo.Group)

type Option added in v0.6.0

type Option func(*Options)

func WithHost added in v0.6.0

func WithHost(host string) Option

WithHost sets the hostname of the HTTP server.

func WithMode added in v0.6.0

func WithMode(mode string) Option

WithMode sets the mode for the HTTP server.

func WithPort added in v0.6.0

func WithPort(port int) Option

WithPort sets the port of the HTTP server.

func WithReadTimeout added in v0.6.0

func WithReadTimeout(readTimeout time.Duration) Option

WithReadTimeout sets the read-timeout for the HTTP server.

func WithWriteTimeout added in v0.6.0

func WithWriteTimeout(writeTimeout time.Duration) Option

WithWriteTimeout sets the write-timeout for the HTTP server.

type Options

type Options struct {
	// The hostname of the HTTP server.
	Host string

	// The port of the HTTP server.
	Port int

	// Read timeout for the HTTP server.
	ReadTimeout time.Duration

	// Write timeout for the HTTP server.
	WriteTimeout time.Duration

	// Mode of the HTTP server. Includes DebugMode, TestMode, and ReleaseMode.
	Mode string
}

Options for the HTTP server.

func (*Options) Addr

func (o *Options) Addr() string

Addr returns the address of the HTTP server. The format is "host:port".

type Server

type Server struct {
	Name    string
	Version string

	*Options
	// contains filtered or unexported fields
}

Server is the HTTP server.

func New

func New(logger *zap.Logger, router *echo.Echo, registrar registry.Registrar, opts ...Option) *Server

New creates a new HTTP server.

The default options are:

  • ReadTimeout: DefaultReadTimeout
  • WriteTimeout: DefaultWriteTimeout
  • Mode: DebugMode

func (*Server) GetID

func (s *Server) GetID() string

GetID returns the unique identifier of the server. It is useful when a service starts more than one server.

func (*Server) IntranetAddr

func (s *Server) IntranetAddr() string

func (*Server) Service

func (s *Server) Service() *registry.ServiceInstance

func (*Server) Start

func (s *Server) Start() error

Start http server.

func (*Server) Stop

func (s *Server) Stop() error

Stop http server.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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