all repos

onasty @ 0afb97fab040e0d661ed9118394a39bcb9d87720

a one-time notes service

onasty/internal/transport/http/httpserver/httpserver.go (view raw)

Smirnov Oleksandr Smirnov Oleksandr
ss2316544@gmail.com
init commit, idk why am i doing this to myself, help please..., 1 year ago
1
package httpserver
2
3
import (
4
	"context"
5
	"net/http"
6
	"time"
7
)
8
9
type Server struct {
10
	http *http.Server
11
}
12
13
func NewServer(port string, handler http.Handler) *Server {
14
	// TODO: add those settings to the config module
15
	return &Server{
16
		http: &http.Server{
17
			Addr:           ":" + port,
18
			Handler:        handler,
19
			ReadTimeout:    10 * time.Second,
20
			WriteTimeout:   10 * time.Second,
21
			MaxHeaderBytes: 1 << 20, // 1mb
22
		},
23
	}
24
}
25
26
func (s *Server) Start() error {
27
	return s.http.ListenAndServe()
28
}
29
30
func (s *Server) Stop(ctx context.Context) error {
31
	return s.http.Shutdown(ctx)
32
}