Skip to main content

Expose

@klotho::expose

Specified on a resource to expose that resource to the public.

Supported Libraries

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

DirectiveTypeDescription
idstring(Required) The exposed endpoint's id. Changing this results in a new endpoint (URL).
targetstring(Required) Must be set and the only allowed value is "public"

Providers