summaryrefslogtreecommitdiffstats
path: root/api/router.go
blob: 076beecfed269e05eba1af5da92084bb3df7b924 (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
package api

import (
	"net/http"

	"git.leonardobishop.net/stash/api/handlers"
	"git.leonardobishop.net/stash/api/middleware"
	"git.leonardobishop.net/stash/internal/config"
	"git.leonardobishop.net/stash/pkg/entries"
	"git.leonardobishop.net/stash/pkg/html"
)

type ApiServices struct {
	EntiresService entries.Service
	HtmlService    html.Service

	Config *config.Config
}

func NewServer(api ApiServices) *http.ServeMux {
	mux := http.NewServeMux()

	mux.HandleFunc("POST /record", middleware.Cors(handlers.RecordEntry(api.EntiresService, api.Config.Token)))
	mux.HandleFunc("GET /html", handlers.GetEntriesHtml(api.EntiresService, api.HtmlService))
	mux.HandleFunc("GET /", handlers.Pong())

	return mux
}