diff --git a/pkg/api/api.go b/pkg/rest/api.go similarity index 99% rename from pkg/api/api.go rename to pkg/rest/api.go index 923f139..0c08daa 100644 --- a/pkg/api/api.go +++ b/pkg/rest/api.go @@ -1,4 +1,4 @@ -package api +package rest import ( "errors" diff --git a/pkg/api/talkgroups.go b/pkg/rest/talkgroups.go similarity index 83% rename from pkg/api/talkgroups.go rename to pkg/rest/talkgroups.go index ac74190..0520af7 100644 --- a/pkg/api/talkgroups.go +++ b/pkg/rest/talkgroups.go @@ -1,4 +1,4 @@ -package api +package rest import ( "net/http" @@ -16,10 +16,10 @@ type talkgroupAPI struct { func (tga *talkgroupAPI) Subrouter() http.Handler { r := chi.NewMux() - r.Get("/{system:\\d+}/{id:\\d+}", tga.talkgroup) - r.Put("/{system:\\d+}/{id:\\d+}", tga.putTalkgroup) - r.Get("/{system:\\d+}/", tga.talkgroup) - r.Get("/", tga.talkgroup) + r.Get("/{system:\\d+}/{id:\\d+}", tga.get) + r.Put("/{system:\\d+}/{id:\\d+}", tga.put) + r.Get("/{system:\\d+}/", tga.get) + r.Get("/", tga.get) 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() tgs := talkgroups.StoreFrom(ctx) @@ -78,7 +78,7 @@ func (tga *talkgroupAPI) talkgroup(w http.ResponseWriter, r *http.Request) { 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 err := decodeParams(&id, r) if err != nil { diff --git a/pkg/server/routes.go b/pkg/server/routes.go index aa3a8a1..b296d6b 100644 --- a/pkg/server/routes.go +++ b/pkg/server/routes.go @@ -38,7 +38,7 @@ func (s *Server) setupRoutes() { s.nex.PrivateRoutes(r) s.auth.PrivateRoutes(r) s.alerter.PrivateRoutes(r) - r.Mount("/api", s.api.Subrouter()) + r.Mount("/api", s.rest.Subrouter()) }) r.Group(func(r chi.Router) { diff --git a/pkg/server/server.go b/pkg/server/server.go index 366bd6c..ebec903 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -7,12 +7,12 @@ import ( "time" "dynatron.me/x/stillbox/pkg/alerting" - "dynatron.me/x/stillbox/pkg/api" "dynatron.me/x/stillbox/pkg/auth" "dynatron.me/x/stillbox/pkg/config" "dynatron.me/x/stillbox/pkg/database" "dynatron.me/x/stillbox/pkg/nexus" "dynatron.me/x/stillbox/pkg/notify" + "dynatron.me/x/stillbox/pkg/rest" "dynatron.me/x/stillbox/pkg/sinks" "dynatron.me/x/stillbox/pkg/sources" "dynatron.me/x/stillbox/pkg/talkgroups" @@ -37,7 +37,7 @@ type Server struct { notifier notify.Notifier hup chan os.Signal tgs talkgroups.Store - api api.API + rest rest.API } 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() - api := api.New() + api := rest.New() srv := &Server{ 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)), notifier: notifier, tgs: tgCache, - api: api, + rest: api, } srv.sinks.Register("database", sinks.NewDatabaseSink(srv.db), true)