httpsrv

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2021 License: BSD-3-Clause Imports: 10 Imported by: 0

README

Using blank of http server

package main

import (
	"net/http"
	"time"

	"github.com/deweppro/go-http/v2/servers/httpsrv"
	"github.com/deweppro/go-logger"
)

type Simple struct{}

func (s *Simple) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	w.WriteHeader(200)
	w.Write([]byte("Hello world"))
}

func main() {
	simple := &Simple{}
	srv := httpsrv.NewCustomServer(httpsrv.ConfigItem{Addr: "localhost:8090"}, simple, logger.Default())
	if err := srv.Up(); err != nil {
		panic(err)
	}

	<-time.After(time.Minute)

	if err := srv.Down(); err != nil {
		panic(err)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	HTTP ConfigItem `yaml:"http" json:"http"`
}

Config ...

func (Config) MarshalEasyJSON

func (v Config) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Config) MarshalJSON

func (v Config) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Config) UnmarshalEasyJSON

func (v *Config) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Config) UnmarshalJSON

func (v *Config) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type ConfigItem

type ConfigItem struct {
	Addr         string        `yaml:"addr" json:"addr"`
	ReadTimeout  time.Duration `yaml:"read_timeout" json:"read_timeout"`
	WriteTimeout time.Duration `yaml:"write_timeout" json:"write_timeout"`
	IdleTimeout  time.Duration `yaml:"idle_timeout" json:"idle_timeout"`
}

ConfigItem ...

func (ConfigItem) MarshalEasyJSON

func (v ConfigItem) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (ConfigItem) MarshalJSON

func (v ConfigItem) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*ConfigItem) UnmarshalEasyJSON

func (v *ConfigItem) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*ConfigItem) UnmarshalJSON

func (v *ConfigItem) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server ...

func NewCustomServer

func NewCustomServer(c ConfigItem, h http.Handler, l logger.Logger) *Server

NewCustomServer ...

func NewServer

func NewServer(c *Config, h http.Handler, l logger.Logger) *Server

NewServer ...

func (*Server) Down

func (s *Server) Down() error

Down ...

func (*Server) Up

func (s *Server) Up() error

Up ...

Jump to

Keyboard shortcuts

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