diff --git a/documentation.go b/documentation.go index 5da5c29..b94cc74 100644 --- a/documentation.go +++ b/documentation.go @@ -2,6 +2,9 @@ package geh import ( "io/ioutil" + "path" + "path/filepath" + "runtime" ) type DocEndpointHttpProtocol map[string]DocEndpoint @@ -118,7 +121,15 @@ func addEndpointDefinitions(docs *DocEndpoint) { func docsHandler( request Request, response Response, _ ...interface{}, ) *Response { - fileContent, _ := ioutil.ReadFile("./templates/swagger-ui/index.html") + _, filename, _, _ := runtime.Caller(0) + currentDirectory := filepath.Dir(filename) + + fileContent, _ := ioutil.ReadFile( + path.Join( + currentDirectory, + "templates/swagger-ui/index.html", + ), + ) return response.Html(string(fileContent)) } diff --git a/router.go b/router.go index ea04cf6..47762fe 100644 --- a/router.go +++ b/router.go @@ -2,6 +2,8 @@ package geh import ( "net/http" + "path/filepath" + "runtime" "strings" "github.com/gorilla/mux" @@ -43,8 +45,11 @@ func NewRouter( Handler(docsSwaggerHandler), ).Methods(http.MethodGet) + _, filename, _, _ := runtime.Caller(0) + currentDirectory := filepath.Dir(filename) + muxRouter.PathPrefix("/assets/").Handler( - http.FileServer(http.Dir("./")), + http.FileServer(http.Dir(currentDirectory)), ) return &GEHRouter{