package hscontrol import ( "bytes" _ "embed" "html/template" "net/http" "github.com/rs/zerolog/log" ) //go:embed gen/openapiv2/headscale/v1/headscale.swagger.json var apiV1JSON []byte func SwaggerUI( writer http.ResponseWriter, req *http.Request, ) { swaggerTemplate := template.Must(template.New("swagger").Parse(`
`)) var payload bytes.Buffer if err := swaggerTemplate.Execute(&payload, struct{}{}); err != nil { log.Error(). Caller(). Err(err). Msg("Could not render Swagger") writer.Header().Set("Content-Type", "text/plain; charset=utf-8") writer.WriteHeader(http.StatusInternalServerError) _, err := writer.Write([]byte("Could not render Swagger")) if err != nil { log.Error(). Caller(). Err(err). Msg("Failed to write response") } return } writer.Header().Set("Content-Type", "text/html; charset=utf-8") writer.WriteHeader(http.StatusOK) _, err := writer.Write(payload.Bytes()) if err != nil { log.Error(). Caller(). Err(err). Msg("Failed to write response") } } func SwaggerAPIv1( writer http.ResponseWriter, req *http.Request, ) { writer.Header().Set("Content-Type", "application/json; charset=utf-8") writer.WriteHeader(http.StatusOK) if _, err := writer.Write(apiV1JSON); err != nil { log.Error(). Caller(). Err(err). Msg("Failed to write response") } }