Skip to content

Swagger with Gorilla Mux - 404 Page Not Found Error #126

@AzzamSyakir

Description

@AzzamSyakir

Hello everyone,
I think this might be a simple issue, but I can't figure out what's wrong. I'm trying to integrate Swagger with Gorilla Mux, but whenever I try to access the Swagger UI, I get a "404 Page Not Found" error.

Here's the code I'm using:

package main

import (
	"fmt"
	"log"
	"net/http"

	_ "my-project/api/docs"

	"github.com/gorilla/mux"
	httpSwagger "github.com/swaggo/http-swagger/v2"
)

// @title Swagger Example API
// @version 1.0
// @description test.
// @tag.name test
// @tag.description test
// @tag.docs.url https://example.com
// @tag.docs.description Best example documentation
// @termsOfService http://swagger.io/terms/
// @contact.name Azzam Syakir
// @contact.url https://github.com/AzzamSyakir
// @contact.email azzam.sykir.work@gmail.com
// @host localhost:8080
func main() {
	r := mux.NewRouter()

	r.PathPrefix("/swagger/*").Handler(httpSwagger.Handler(
		httpSwagger.URL("http://localhost:1323/api/docs/doc.json"), //The url pointing to API definition
		httpSwagger.DeepLinking(true),
		httpSwagger.DocExpansion("none"),
		httpSwagger.DomID("swagger-ui"),
	)).Methods(http.MethodGet)
	fmt.Println("start")
	log.Fatal(http.ListenAndServe(":1323", r))
	fmt.Println("finish")
}

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions