docs(backpack,beachcomber,boardwalk,bonfire,bouncer): compile README Go examples via src= (quick-261118-qsd)

- backpack: Greeter and ExampleApp_Publish replace the whole-file fence
- beachcomber: Post's Searchable methods plus a new SearchIndexSchema, a
  Plugin.Boot that installs the gate, and the existing gate/search regions
- boardwalk: new example_test.go; the mount region runs in ExampleHandler
- bonfire: importPostsCommand and acmeMain (the binary's main as a function
  returning the exit code), run by ExampleExecute; ExampleCatalog_Has
- bouncer: users/FindByID and ExampleNewJWTGuard; RefreshRoute run by
  TestDocsRefreshRoute on a production compass config
This commit is contained in:
Jakub Zych
2026-11-18 19:39:50 +01:00
parent 48527e4206
commit a0f5b5e561
9 changed files with 366 additions and 125 deletions

View File

@@ -0,0 +1,45 @@
package boardwalk_test
import (
"fmt"
"net/http"
"net/http/httptest"
"git.golem15.com/golem15/summercms/modules/boardwalk"
)
// mountAdmin serves the embedded admin SPA under /backend; admin API paths
// it does not know answer JSON.
func mountAdmin(mux *http.ServeMux) error {
// docs:start mount
notFoundAPI := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusNotFound)
_, _ = w.Write([]byte(`{"error":"not found"}`))
})
spa, err := boardwalk.Handler("/backend", notFoundAPI)
if err != nil {
return err
}
mux.Handle("/backend/", spa)
// docs:end mount
return nil
}
func ExampleHandler() {
mux := http.NewServeMux()
if err := mountAdmin(mux); err != nil {
fmt.Println(err)
return
}
for _, path := range []string{"/backend/", "/backend/posts/7", "/backend/api/missing"} {
rec := httptest.NewRecorder()
mux.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, path, nil))
fmt.Println(path, rec.Code, rec.Header().Get("Content-Type"), rec.Header().Get(boardwalk.BuildHeader) != "")
}
// Output:
// /backend/ 200 text/html; charset=utf-8 true
// /backend/posts/7 200 text/html; charset=utf-8 true
// /backend/api/missing 404 application/json true
}