-
-
Notifications
You must be signed in to change notification settings - Fork 629
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2f17617
commit 1f65c82
Showing
2 changed files
with
12 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,25 @@ | ||
package docs | ||
|
||
import ( | ||
"embed" | ||
_ "embed" | ||
"strings" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/gotify/location" | ||
) | ||
|
||
//go:embed spec.json | ||
var box embed.FS | ||
var spec string | ||
|
||
// Serve serves the documentation. | ||
func Serve(ctx *gin.Context) { | ||
base := location.Get(ctx).Host | ||
if basePathFromQuery := ctx.Query("base"); basePathFromQuery != "" { | ||
base = basePathFromQuery | ||
} | ||
ctx.Writer.WriteString(get(base)) | ||
ctx.Writer.WriteString(getSwaggerJSON(base)) | ||
} | ||
|
||
func get(base string) string { | ||
spec, err := box.ReadFile("spec.json") | ||
if err != nil { | ||
panic(err) | ||
} | ||
return strings.Replace(string(spec), "localhost", base, 1) | ||
func getSwaggerJSON(base string) string { | ||
return strings.Replace(spec, "localhost", base, 1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters