aboutsummaryrefslogtreecommitdiff
path: root/internal/api/new.go
blob: 7febfe7e622e8ab899f00ce9886db8cb93994146 (plain)
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
package api

import "net/http"

func New(config Config) *Server {
	mux := http.NewServeMux()

	server := &http.Server{
		Addr:    config.Address,
		Handler: mux,
	}

	srv := &Server{
		config: config,

		mux:  mux,
		http: server,

		gallery:    config.Gallery,
		thumbnails: config.Thumbnails,
	}

	srv.mux.HandleFunc(
		"GET /health",
		srv.handleHealth,
	)

	srv.mux.HandleFunc(
		"GET /api/photos",
		srv.handlePhotos,
	)

	srv.mux.HandleFunc(
		"GET /thumb/{id}",
		srv.handleThumbnail,
	)

	srv.mux.HandleFunc(
		"GET /photo/{id}",
		srv.handlePhoto,
	)

	return srv
}