diff --git a/index/server/pkg/server/endpoint.go b/index/server/pkg/server/endpoint.go index a4584fe2..8f6f1155 100644 --- a/index/server/pkg/server/endpoint.go +++ b/index/server/pkg/server/endpoint.go @@ -24,9 +24,9 @@ import ( "gopkg.in/segmentio/analytics-go.v3" ) -// ServeRootEndpoint sets up the handler for the root (/) endpoint on the server +// serveRootEndpoint sets up the handler for the root (/) endpoint on the server // If html is requested (i.e. from a web browser), the viewer is displayed, otherwise the devfile index is served. -func ServeRootEndpoint(c *gin.Context) { +func serveRootEndpoint(c *gin.Context) { // Determine if text/html was requested by the client acceptHeader := c.Request.Header.Values("Accept") if util.IsHtmlRequested(acceptHeader) { @@ -36,11 +36,11 @@ func ServeRootEndpoint(c *gin.Context) { } } -func ServeDevfileIndexV1(c *gin.Context) { +func serveDevfileIndexV1(c *gin.Context) { serveDevfileIndex(c, true) } -func ServeDevfileIndexV2(c *gin.Context) { +func serveDevfileIndexV2(c *gin.Context) { serveDevfileIndex(c, false) } @@ -62,26 +62,26 @@ func serveDevfileIndex(c *gin.Context, wantV1Index bool) { buildIndexAPIResponse(c, wantV1Index) } -func ServeDevfileIndexV1WithType(c *gin.Context) { +func serveDevfileIndexV1WithType(c *gin.Context) { // Serve the index with type buildIndexAPIResponse(c, true) } -func ServeDevfileIndexV2WithType(c *gin.Context) { +func serveDevfileIndexV2WithType(c *gin.Context) { // Serve the index with type buildIndexAPIResponse(c, false) } -// ServeHealthCheck serves endpoint `/health` for registry health check -func ServeHealthCheck(c *gin.Context) { +// serveHealthCheck serves endpoint `/health` for registry health check +func serveHealthCheck(c *gin.Context) { c.JSON(http.StatusOK, gin.H{ "message": "the server is up and running", }) } -func ServeDevfileWithVersion(c *gin.Context) { +func serveDevfileWithVersion(c *gin.Context) { name := c.Param("name") version := c.Param("version") bytes, devfileIndex := fetchDevfile(c, name, version) @@ -111,21 +111,21 @@ func ServeDevfileWithVersion(c *gin.Context) { } } -// ServeDevfile returns the devfile content -func ServeDevfile(c *gin.Context) { +// serveDevfile returns the devfile content +func serveDevfile(c *gin.Context) { // append the stack version, for endpoint /devfiles/name without version c.Params = append(c.Params, gin.Param{Key: "version", Value: "default"}) - ServeDevfileWithVersion(c) + serveDevfileWithVersion(c) } -// ServeDevfileStarterProject returns the starter project content for the devfile using default version -func ServeDevfileStarterProject(c *gin.Context) { +// serveDevfileStarterProject returns the starter project content for the devfile using default version +func serveDevfileStarterProject(c *gin.Context) { c.Params = append(c.Params, gin.Param{Key: "version", Value: "default"}) - ServeDevfileStarterProjectWithVersion(c) + serveDevfileStarterProjectWithVersion(c) } // serveDevfileStarterProject returns the starter project content for the devfile using specified version -func ServeDevfileStarterProjectWithVersion(c *gin.Context) { +func serveDevfileStarterProjectWithVersion(c *gin.Context) { devfileName := c.Param("name") version := c.Param("version") starterProjectName := c.Param("starterProjectName") diff --git a/index/server/pkg/server/endpoint_test.go b/index/server/pkg/server/endpoint_test.go index 4a1ce4fe..a27fd728 100644 --- a/index/server/pkg/server/endpoint_test.go +++ b/index/server/pkg/server/endpoint_test.go @@ -49,7 +49,7 @@ func TestServeHealthCheck(t *testing.T) { w := httptest.NewRecorder() c, _ := gin.CreateTestContext(w) - ServeHealthCheck(c) + serveHealthCheck(c) wantStatusCode := 200 if gotStatusCode := w.Code; !reflect.DeepEqual(gotStatusCode, wantStatusCode) { @@ -136,7 +136,7 @@ func TestServeDevfileIndexV1(t *testing.T) { c.Params = test.params - ServeDevfileIndexV1(c) + serveDevfileIndexV1(c) if gotStatusCode := w.Code; !reflect.DeepEqual(gotStatusCode, test.wantCode) { t.Errorf("Did not get expected status code, Got: %v, Expected: %v", gotStatusCode, test.wantCode) @@ -196,7 +196,7 @@ func TestServeDevfileIndexV2(t *testing.T) { c.Params = test.params - ServeDevfileIndexV2(c) + serveDevfileIndexV2(c) if gotStatusCode := w.Code; !reflect.DeepEqual(gotStatusCode, test.wantCode) { t.Errorf("Did not get expected status code, Got: %v, Expected: %v", gotStatusCode, test.wantCode) diff --git a/index/server/pkg/server/index.go b/index/server/pkg/server/index.go index 4caeeff0..f00e7cc2 100644 --- a/index/server/pkg/server/index.go +++ b/index/server/pkg/server/index.go @@ -55,18 +55,18 @@ func CreateIndexServer() *gin.Engine { router := gin.Default() // Registry REST APIs - router.GET("/", ServeRootEndpoint) - router.GET("/index", ServeDevfileIndexV1) - router.GET("/index/:type", ServeDevfileIndexV1WithType) - router.GET("/health", ServeHealthCheck) - router.GET("/devfiles/:name", ServeDevfile) - router.GET("/devfiles/:name/:version", ServeDevfileWithVersion) - router.GET("/devfiles/:name/starter-projects/:starterProjectName", ServeDevfileStarterProject) - router.GET("/devfiles/:name/:version/starter-projects/:starterProjectName", ServeDevfileStarterProjectWithVersion) + router.GET("/", serveRootEndpoint) + router.GET("/index", serveDevfileIndexV1) + router.GET("/index/:type", serveDevfileIndexV1WithType) + router.GET("/health", serveHealthCheck) + router.GET("/devfiles/:name", serveDevfile) + router.GET("/devfiles/:name/:version", serveDevfileWithVersion) + router.GET("/devfiles/:name/starter-projects/:starterProjectName", serveDevfileStarterProject) + router.GET("/devfiles/:name/:version/starter-projects/:starterProjectName", serveDevfileStarterProjectWithVersion) // Registry REST APIs for index v2 - router.GET("/v2index", ServeDevfileIndexV2) - router.GET("/v2index/:type", ServeDevfileIndexV2WithType) + router.GET("/v2index", serveDevfileIndexV2) + router.GET("/v2index/:type", serveDevfileIndexV2WithType) // Set up a simple proxy for /v2 endpoints // Only allow HEAD and GET requests