generated from Yandex-Practicum/go-musthave-metrics-tpl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.go
More file actions
46 lines (37 loc) · 784 Bytes
/
server.go
File metadata and controls
46 lines (37 loc) · 784 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package server
import (
"net/http"
"github.com/srg-bnd/observator/internal/handlers"
"github.com/srg-bnd/observator/internal/middleware"
"github.com/srg-bnd/observator/internal/storage"
)
const (
defaultHost = `:8080`
)
var (
MemStorage *storage.MemStorage
mux *http.ServeMux
)
func init() {
// Routes
mux = http.NewServeMux()
mux.Handle(
`/update/{metricType}/{metricName}/{metricValue}`,
middleware.Conveyor(
http.HandlerFunc(handlers.UpdateMetricHandler),
middleware.CheckMethodPost,
))
}
// Init server dependencies before startup
func Start() error {
host, err := getHost()
if err != nil {
return err
}
http.ListenAndServe(host, mux)
return nil
}
// Selects the server host
func getHost() (string, error) {
return defaultHost, nil
}