Rename api to rest

This commit is contained in:
Daniel 2024-11-10 14:44:52 -05:00
parent 759c274950
commit fb3fb4eeab
4 changed files with 13 additions and 13 deletions

View file

@ -1,4 +1,4 @@
package api package rest
import ( import (
"errors" "errors"

View file

@ -1,4 +1,4 @@
package api package rest
import ( import (
"net/http" "net/http"
@ -16,10 +16,10 @@ type talkgroupAPI struct {
func (tga *talkgroupAPI) Subrouter() http.Handler { func (tga *talkgroupAPI) Subrouter() http.Handler {
r := chi.NewMux() r := chi.NewMux()
r.Get("/{system:\\d+}/{id:\\d+}", tga.talkgroup) r.Get("/{system:\\d+}/{id:\\d+}", tga.get)
r.Put("/{system:\\d+}/{id:\\d+}", tga.putTalkgroup) r.Put("/{system:\\d+}/{id:\\d+}", tga.put)
r.Get("/{system:\\d+}/", tga.talkgroup) r.Get("/{system:\\d+}/", tga.get)
r.Get("/", tga.talkgroup) r.Get("/", tga.get)
return r return r
} }
@ -48,7 +48,7 @@ func (t tgParams) ToID() talkgroups.ID {
} }
} }
func (tga *talkgroupAPI) talkgroup(w http.ResponseWriter, r *http.Request) { func (tga *talkgroupAPI) get(w http.ResponseWriter, r *http.Request) {
ctx := r.Context() ctx := r.Context()
tgs := talkgroups.StoreFrom(ctx) tgs := talkgroups.StoreFrom(ctx)
@ -78,7 +78,7 @@ func (tga *talkgroupAPI) talkgroup(w http.ResponseWriter, r *http.Request) {
respond(w, r, res) respond(w, r, res)
} }
func (tga *talkgroupAPI) putTalkgroup(w http.ResponseWriter, r *http.Request) { func (tga *talkgroupAPI) put(w http.ResponseWriter, r *http.Request) {
var id tgParams var id tgParams
err := decodeParams(&id, r) err := decodeParams(&id, r)
if err != nil { if err != nil {

View file

@ -38,7 +38,7 @@ func (s *Server) setupRoutes() {
s.nex.PrivateRoutes(r) s.nex.PrivateRoutes(r)
s.auth.PrivateRoutes(r) s.auth.PrivateRoutes(r)
s.alerter.PrivateRoutes(r) s.alerter.PrivateRoutes(r)
r.Mount("/api", s.api.Subrouter()) r.Mount("/api", s.rest.Subrouter())
}) })
r.Group(func(r chi.Router) { r.Group(func(r chi.Router) {

View file

@ -7,12 +7,12 @@ import (
"time" "time"
"dynatron.me/x/stillbox/pkg/alerting" "dynatron.me/x/stillbox/pkg/alerting"
"dynatron.me/x/stillbox/pkg/api"
"dynatron.me/x/stillbox/pkg/auth" "dynatron.me/x/stillbox/pkg/auth"
"dynatron.me/x/stillbox/pkg/config" "dynatron.me/x/stillbox/pkg/config"
"dynatron.me/x/stillbox/pkg/database" "dynatron.me/x/stillbox/pkg/database"
"dynatron.me/x/stillbox/pkg/nexus" "dynatron.me/x/stillbox/pkg/nexus"
"dynatron.me/x/stillbox/pkg/notify" "dynatron.me/x/stillbox/pkg/notify"
"dynatron.me/x/stillbox/pkg/rest"
"dynatron.me/x/stillbox/pkg/sinks" "dynatron.me/x/stillbox/pkg/sinks"
"dynatron.me/x/stillbox/pkg/sources" "dynatron.me/x/stillbox/pkg/sources"
"dynatron.me/x/stillbox/pkg/talkgroups" "dynatron.me/x/stillbox/pkg/talkgroups"
@ -37,7 +37,7 @@ type Server struct {
notifier notify.Notifier notifier notify.Notifier
hup chan os.Signal hup chan os.Signal
tgs talkgroups.Store tgs talkgroups.Store
api api.API rest rest.API
} }
func New(ctx context.Context, cfg *config.Config) (*Server, error) { func New(ctx context.Context, cfg *config.Config) (*Server, error) {
@ -61,7 +61,7 @@ func New(ctx context.Context, cfg *config.Config) (*Server, error) {
} }
tgCache := talkgroups.NewCache() tgCache := talkgroups.NewCache()
api := api.New() api := rest.New()
srv := &Server{ srv := &Server{
auth: authenticator, auth: authenticator,
@ -73,7 +73,7 @@ func New(ctx context.Context, cfg *config.Config) (*Server, error) {
alerter: alerting.New(cfg.Alerting, tgCache, alerting.WithNotifier(notifier)), alerter: alerting.New(cfg.Alerting, tgCache, alerting.WithNotifier(notifier)),
notifier: notifier, notifier: notifier,
tgs: tgCache, tgs: tgCache,
api: api, rest: api,
} }
srv.sinks.Register("database", sinks.NewDatabaseSink(srv.db), true) srv.sinks.Register("database", sinks.NewDatabaseSink(srv.db), true)