aboutsummaryrefslogtreecommitdiff
path: root/src/server/router.go
blob: f0f2dc4fb86aa4ad95c405ae04fdef1a57736f8b (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
package server

import (
	"net/http"

	"github.com/go-chi/chi/v5"
	"github.com/go-chi/chi/v5/middleware"
	"gitlab.com/alexkavon/newsstand/src/conf"
	"gitlab.com/alexkavon/newsstand/src/sessions"
)

type HandlerFunc func(s *Server) http.HandlerFunc

type ErrRes struct {
	Err            error  `json:"-"`
	HTTPStatusCode int    `json:"-"`
	StatusMessage  string `json:"status"`
	ErrorMessage   string `json:"error,omitempty"`
}

func (e *ErrRes) Render(w http.ResponseWriter, r *http.Request) error {
	// http.StatusCode(r, e.HTTPStatusCode)
	return nil
}

type Route struct {
	Name        string
	Method      string
	Path        string
	HandlerFunc HandlerFunc
	Middlewares []func(http.Handler) http.Handler
}

type Routes []Route

func NewRouter(config *conf.Conf) *chi.Mux {
	r := chi.NewRouter()
	r.Use(middleware.Logger)
	sessions.InitStore()
	r.Use(sessions.StartSession)
	return r
}