Apps: Add Example App to ./apps (#112069)
* [API Server] Add Example App for reference use. * Remove Printlns. * Upgrade app-sdk to v0.46.0, update apps to handle breaking changes. * Only start the reconciler for the example app if the v1alpha1 API version is enabled. * Some comment doc updates. * Run make update-workspace * Set codeowner for /apps/example * Run make gofmt and make update-workspace * Run prettier on apps/example/README.md * Add COPY apps/example to Dockerfile * Add an authorizer to the example app. * Fix import ordering. * Update apps/example/kinds/manifest.cue Co-authored-by: Owen Diehl <ow.diehl@gmail.com> * Run make update-workspace * Re-run make gen-go for enterprise import updates * Run make update-workspace --------- Co-authored-by: Owen Diehl <ow.diehl@gmail.com>
This commit is contained in:
co-authored by
Owen Diehl
parent
d25f5199c7
commit
bf65c43783
@@ -0,0 +1,50 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
"github.com/grafana/grafana-app-sdk/app"
|
||||
"github.com/grafana/grafana/apps/example/pkg/apis/example/v1alpha1"
|
||||
)
|
||||
|
||||
// ExampleGetFooHandler handles requests for the GET /foo subresource route
|
||||
func ExampleGetFooHandler(ctx context.Context, writer app.CustomRouteResponseWriter, request *app.CustomRouteRequest) error {
|
||||
message := "Hello, world!"
|
||||
return json.NewEncoder(writer).Encode(v1alpha1.GetFoo{
|
||||
GetFooBody: v1alpha1.GetFooBody{
|
||||
Message: message,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// GetSomethingHandler handles requests for the GET /something resource route
|
||||
func GetSomethingHandler(ctx context.Context, writer app.CustomRouteResponseWriter, request *app.CustomRouteRequest) error {
|
||||
message := "This is a namespaced route"
|
||||
if request.URL.Query().Has("message") {
|
||||
message = request.URL.Query().Get("message")
|
||||
}
|
||||
return json.NewEncoder(writer).Encode(v1alpha1.GetSomething{
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
APIVersion: fmt.Sprintf("%s/%s", v1alpha1.APIGroup, v1alpha1.APIVersion),
|
||||
},
|
||||
GetSomethingBody: v1alpha1.GetSomethingBody{
|
||||
Namespace: request.ResourceIdentifier.Namespace,
|
||||
Message: message,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// GetOtherHandler handles requests for the GET /other cluster-scoped resource route
|
||||
func GetOtherHandler(ctx context.Context, writer app.CustomRouteResponseWriter, request *app.CustomRouteRequest) error {
|
||||
message := "This is a cluster route"
|
||||
if request.URL.Query().Has("message") {
|
||||
message = request.URL.Query().Get("message")
|
||||
}
|
||||
return json.NewEncoder(writer).Encode(v1alpha1.GetOther{
|
||||
Message: message,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user