Skip to content

Go

The following section covers the components of Go frameworks and their library components that NightVision’s API Discovery capability can detect and use to generate OpenAPI documentation. If a component that you use is not supported, please get in touch with our support team at support@nightviz.ai, and we can add this as a new feature.

Major-version import suffixes are handled automatically: a package imported as github.com/labstack/echo/v4, github.com/gofiber/fiber/v2, or github.com/go-chi/chi/v5 is recognized the same as its unversioned import path, so the tables below apply regardless of the module major version in use.

Library ComponentDescription
New()Function to create a new Engine instance in Gin.
Default()Function to create a new Engine instance with default middleware (logging and recovery).
Engine.ServeHTTP()Method to serve HTTP requests.
Engine.Run()Method to run the Gin server.
Context.MustBindWith()Method to bind the request body to a struct, halting if binding fails.
Context.BindJSONMethod to bind the JSON body of the request to a struct.
Context.QueryMethod to get a query parameter from the URL.
Context.CookieMethod to get a cookie value from the request.
Context.ParamMethod to get a path parameter from the URL.
Context.ShouldBindMethod to bind request data to a struct, returning an error if binding fails.
Context.DefaultQueryMethod to get a query parameter with a default value if not present.
Context.PostFormMethod to get a form parameter from the request body.
Context.ShouldBindJSONMethod to bind the JSON body of the request to a struct, returning an error if binding fails.
Context.JSONMethod to write a JSON response body (also IndentedJSON, PureJSON, SecureJSON, AsciiJSON).
Context.XMLMethod to write an XML response body.
Context.YAMLMethod to write a YAML response body.
RouterGroup.GETMethod to handle HTTP GET requests in a route group.
RouterGroup.PUTMethod to handle HTTP PUT requests in a route group.
RouterGroup.DELETEMethod to handle HTTP DELETE requests in a route group.
RouterGroup.HEADMethod to handle HTTP HEAD requests in a route group.
RouterGroup.HandleMethod to handle custom HTTP methods in a route group.
RouterGroup.GroupMethod to create a new router group with a common route prefix.
RouterGroup.POSTMethod to handle HTTP POST requests in a route group.
RouterGroup.ANYMethod to handle all HTTP request method in a route group.
RouterGroup.PATCHMethod to handle HTTP PATCH requests in a route group.
RouterGroup.OPTIONSMethod to handle HTTP OPTIONS requests in a route group.

Imported as github.com/labstack/echo/v4. The verb methods are shared between the Echo instance and any Group created from it, so e.GET(...) and group.GET(...) are both recognized.

Library ComponentDescription
NewFunction to create a new Echo instance.
Echo.GETMethod to register a handler for HTTP GET requests.
Echo.POSTMethod to register a handler for HTTP POST requests.
Echo.PUTMethod to register a handler for HTTP PUT requests.
Echo.DELETEMethod to register a handler for HTTP DELETE requests.
Echo.PATCHMethod to register a handler for HTTP PATCH requests.
Echo.OPTIONSMethod to register a handler for HTTP OPTIONS requests.
Echo.HEADMethod to register a handler for HTTP HEAD requests.
Echo.CONNECTMethod to register a handler for HTTP CONNECT requests.
Echo.TRACEMethod to register a handler for HTTP TRACE requests.
Echo.AnyMethod to register a handler for all standard HTTP methods.
Echo.MatchMethod to register a handler for an explicit list of HTTP methods.
Echo.AddMethod to register a handler for a method supplied as a string.
Echo.GroupMethod to create a sub-router that shares a common route prefix.
Context.ParamMethod to get a path parameter from the URL.
Context.QueryParamMethod to get a query parameter from the URL.
Context.FormValueMethod to get a form value from the request body.
Context.BindMethod to bind the request body to a struct.

Imported as github.com/gofiber/fiber/v2.

Library ComponentDescription
NewFunction to create a new App instance.
App.GetMethod to register a handler for HTTP GET requests.
App.PostMethod to register a handler for HTTP POST requests.
App.PutMethod to register a handler for HTTP PUT requests.
App.DeleteMethod to register a handler for HTTP DELETE requests.
App.PatchMethod to register a handler for HTTP PATCH requests.
App.HeadMethod to register a handler for HTTP HEAD requests.
App.OptionsMethod to register a handler for HTTP OPTIONS requests.
App.ConnectMethod to register a handler for HTTP CONNECT requests.
App.TraceMethod to register a handler for HTTP TRACE requests.
App.AllMethod to register a handler for all standard HTTP methods.
App.AddMethod to register a handler for a method supplied as a string.
App.GroupMethod to create a sub-router that shares a common route prefix.
App.RouteMethod to build routes for a shared prefix.
Ctx.ParamsMethod to get a path parameter from the URL.
Ctx.QueryMethod to get a query parameter from the URL.
Ctx.FormValueMethod to get a form value from the request body.
Ctx.BodyParserMethod to bind the request body to a struct.
Ctx.QueryParserMethod to bind query parameters to a struct.

Imported as github.com/go-chi/chi/v5.

Library ComponentDescription
NewRouterFunction to create a new Mux router.
NewMuxFunction to create a new Mux router.
URLParamFunction to read a path parameter from the request.
Mux.GetMethod to register a handler for HTTP GET requests.
Mux.PostMethod to register a handler for HTTP POST requests.
Mux.PutMethod to register a handler for HTTP PUT requests.
Mux.DeleteMethod to register a handler for HTTP DELETE requests.
Mux.PatchMethod to register a handler for HTTP PATCH requests.
Mux.HeadMethod to register a handler for HTTP HEAD requests.
Mux.OptionsMethod to register a handler for HTTP OPTIONS requests.
Mux.ConnectMethod to register a handler for HTTP CONNECT requests.
Mux.TraceMethod to register a handler for HTTP TRACE requests.
Mux.HandleFuncMethod to register a handler for all HTTP methods on a pattern.
Mux.HandleMethod to register an http.Handler for all methods on a pattern.
Mux.MethodFuncMethod to register a handler for a method supplied as a string.
Mux.MethodMethod to register an http.Handler for a method supplied as a string.
Mux.RouteMethod to create a sub-router mounted at a pattern.
Mux.GroupMethod to create an inline group that shares middleware.
Mux.MountMethod to attach another handler or router under a pattern.
Mux.WithMethod to add inline middleware for an endpoint.
Library ComponentDescription
NewRouterFunction to create a new Router.
Router.HandleFuncMethod to register a handler function for a path.
Router.HandleMethod to register an http.Handler for a path.
Router.PathPrefixMethod to match a URL path prefix, returning a Route.
Router.PathMethod to match a full URL path, returning a Route.
Route.SubrouterMethod to create a nested router under a matched Route.
Route.MethodsMethod to restrict a Route to the given HTTP methods.
Route.QueriesMethod to restrict a Route to the given query parameters.
Route.HandlerMethod to set the http.Handler for a matched Route.
Route.HandlerFuncMethod to set the handler function for a matched Route.
Library ComponentDescription
NewFunction to create a new HTTP router instance.
Router.PATCHMethod to handle HTTP PATCH requests.
Router.ServeHTTPMethod to serve HTTP requests, implementing the http.Handler interface.
Router.GETMethod to handle HTTP GET requests.
Router.POSTMethod to handle HTTP POST requests.
Router.PUTMethod to handle HTTP PUT requests.
Router.DELETEMethod to handle HTTP DELETE requests.
Router.OPTIONSMethod to handle HTTP OPTIONS requests.
Library ComponentDescription
RequestRepresents an HTTP request, including methods to access form values, cookies, and more.
Request.FormValueMethod to retrieve form values from an HTTP request.
Request.PostFormValueMethod to retrieve POST form values from an HTTP request.
Request.CookieMethod to retrieve a cookie value from an HTTP request.
Request.PathValueMethod to retrieve a path parameter from an HTTP request (Go 1.22+ routing patterns).
ServeMux.HandleFuncMethod to register a handler function for a pattern on a ServeMux.
ServeMux.HandleMethod to register a handler for a pattern on a ServeMux.
HandleFuncFunction to register a handler function on the default ServeMux.
net/http.ResponseWriterInterface for constructing an HTTP response.
net/http.ServerRepresents an HTTP server, providing methods for starting and stopping the server.
net/http.Server.ListenAndServeMethod to start the server and listen for HTTP requests.

NightVision follows the command trees registered through these CLI frameworks so that routes registered inside a command handler are discovered.

Library ComponentDescription
CommandRepresents a command in the Cobra CLI library.
Command.ExecuteMethod to execute the command.
Command.ExecuteContextMethod to execute the command with a context for cancellation.
Command.AddCommandMethod to add a child command to this command.
Library ComponentDescription
NewAppFunction to create a new CLI application instance.
AppRepresents a CLI application in the Urfave CLI library.
App.RunMethod to run the CLI application.
CommandCommand represents a subcommands and commands for a cli.App
Library ComponentDescription
CommandRepresents a command in the Serpent CLI library.
Command.InvokeMethod to begin an invocation for the command.
Command.AddSubcommandsMethod to attach child commands to this command.
Invocation.WithOSMethod that configures the invocation with OS arguments and streams.
Invocation.RunMethod to dispatch the matched command and its subcommands.

NightVision runs the constructors and functions wired through an fx application so that routes registered by a wired function are discovered.

Library ComponentDescription
NewFunction to construct an fx application from a set of options.
ModuleFunction to group options into a named module.
OptionsFunction to bundle multiple options into one.
InvokeFunction to register functions that fx runs at application start.
ProvideFunction to register constructors that supply the application’s dependencies.
AnnotateFunction to attach annotations to a constructor or invoked function.
AnnotatedStruct that wraps a constructor with annotations via its Target field.

NightVision reads authentication guards on Go routes and records them as OpenAPI security schemes. See the Framework Support Index for how schemes and the x-unsound marker are represented. A route is recognized as secured when a documented auth library is used, or when a middleware or handler reads a credential header and rejects unauthenticated requests with a 401/403.

Resolved by import path, so the scheme is read directly from the library:

LibraryOpenAPI Security Scheme
github.com/golang-jwt/jwt, github.com/labstack/echo-jwt, labstack/echo middleware.JWT, github.com/appleboy/gin-jwt, github.com/gofiber/jwt (jwtware), github.com/gofiber/contrib/jwt, github.com/go-chi/jwtauthHTTP bearer (JWT)
github.com/gin-gonic/gin gin.BasicAuth, labstack/echo middleware.BasicAuth, github.com/gofiber/fiber/middleware/basicauthHTTP basic
github.com/gofiber/keyauth, labstack/echo middleware.KeyAuthBearer, or API key in a header, query parameter, or cookie, per the KeyLookup/AuthScheme configuration

go-chi/jwtauth’s Verifier alone does not secure a route (it only parses the token into the request context); the paired Authenticator middleware is what rejects unauthenticated requests.

Recognized middleware and handler patterns

Section titled “Recognized middleware and handler patterns”

When no documented library is matched, a route is secured if a middleware or handler reads a credential and challenges unauthenticated requests. These derivations are flagged x-unsound because enforcement is inferred from behavior rather than read from a library:

PatternOpenAPI Security Scheme
Reads the Authorization header (or (*http.Request).BasicAuth()) and returns 401/403HTTP bearer by default; HTTP basic or digest when the code compares the value against a "Basic "/"Digest "/"Bearer " scheme prefix
Reads an API-key header (X-API-Key, X-Auth-Token, Api-Key, and similar) and returns 401/403API key (header)
gorilla/mux Headers("Authorization", "") or HeadersRegexp("Authorization", "^Bearer") route matchersHTTP bearer, or the scheme named by the regular expression

Go auth extraction records the scheme and transport only; role and scope names are not extracted.

Scheme keyOpenAPI type
bearerAuthhttp, scheme bearer, bearerFormat JWT
basicAuthhttp, scheme basic
digestAuthhttp, scheme digest
apiKey / apiKeyQueryapiKey in a header (default name X-API-Key) or query parameter (default name api_key)
sessionAuthapiKey in a cookie (default name session)