From 33794541939c86ad53da96090c6b4845f97ad683 Mon Sep 17 00:00:00 2001 From: Viacheslav Poturaev Date: Tue, 26 Sep 2023 13:17:37 +0200 Subject: [PATCH] Fix handling of absolute schema URLs (#42) --- README.md | 15 +++++++++++++-- internal/index.tpl.go | 5 ++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8bee5af..f893d39 100644 --- a/README.md +++ b/README.md @@ -41,11 +41,22 @@ import ( ) func main() { - http.Handle("/", v5emb.NewHandler("My API", "/swagger.json", "/")) - _ = http.ListenAndServe(":8080", nil) + http.Handle("/api1/docs/", v5emb.New( + "Petstore", + "https://petstore3.swagger.io/api/v3/openapi.json", + "/api1/docs/", + )) + + http.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) { + _, _ = writer.Write([]byte("Hello World!")) + }) + + println("docs at http://localhost:8080/api1/docs/") + _ = http.ListenAndServe("localhost:8080", http.DefaultServeMux) } ``` + If you use `go1.16` or later, you can import natively embedded assets with `"github.com/swaggest/swgui/v5emb"`, it may help to lower application memory usage. diff --git a/internal/index.tpl.go b/internal/index.tpl.go index f4d4392..f044c19 100644 --- a/internal/index.tpl.go +++ b/internal/index.tpl.go @@ -93,7 +93,10 @@ func IndexTpl(assetsBase, faviconBase string, cfg swgui.Config) string {