Expose
@klotho::expose
Specified on a resource to expose that resource to the public.
Supported Libraries
- chi/v5
Annotate the ListenAndServe()
of net/http to enable. Note that you must provide a target = "public"
directive, as described below.
caution
Experimental and subject to change
Currently only supports routes specified directly on the chi/v5 mux using r.<METHOD>
. Using the older go-chi/chi v1.5.4 package will not work.
r := chi.NewRouter()
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Hello from Klotho!"))
})
/**
* @klotho::expose {
* target = "public"
* id = "app"
* }
*/
http.ListenAndServe(":3000", r)
To mount external routers use the chi/v5 Mount
function.
extraRouter := chi.NewRouter()
extraRouter.Get("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Extra routes"))
})
r.Mount("/extra", extraRouter)
Directives
Directive | Type | Description |
---|---|---|
id | string | (Required) The exposed endpoint's id. Changing this results in a new endpoint (URL). |
target | string | (Required) Must be set and the only allowed value is "public" |
Providers
- AWS
- GCP
- Creates an API Gateway.
caution
GCP hasn't been updated to v1 yet, so this is just a projection of what it may be.
- Creates an API Gateway.