Compare commits

...

1 Commits

Author SHA1 Message Date
Yuan Teoh
9bc91a6cd8 feat(server/admin): add new admin api router 2025-08-28 14:03:22 -07:00
2 changed files with 37 additions and 0 deletions

32
internal/server/admin.go Normal file
View File

@@ -0,0 +1,32 @@
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package server
import (
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
"github.com/go-chi/render"
)
// adminRouter creates a router that represents the routes under /admin
func adminRouter(s *Server) (chi.Router, error) {
r := chi.NewRouter()
r.Use(middleware.AllowContentType("application/json"))
r.Use(middleware.StripSlashes)
r.Use(render.SetContentType(render.ContentTypeJSON))
return r, nil
}

View File

@@ -337,6 +337,11 @@ func NewServer(ctx context.Context, cfg ServerConfig) (*Server, error) {
}
r.Mount("/ui", webR)
}
adminR, err := adminRouter(s)
if err != nil {
return nil, err
}
r.Mount("/admin", adminR)
// default endpoint for validating server is running
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte("🧰 Hello, World! 🧰"))