Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
func New(options Options) router.Controller
New creates a new API Graph router.Controller with the given options. It registers a handler that renders a graph of the application's routes. It generates an HTML page with a D3.js visualization of the routes, showing the paths, methods, and handlers. The graph is interactive, allowing users to directly open the handler files in Visual Studio Code. Users can also to hover over links and nodes to see more details.
Parameters:
- options: Options for the graph, such as the theme. If no options are provided, the default theme is used. The theme determines the background color, text color, and link color of the graph. The default theme is light, but a dark theme is also available. To use the dark theme, pass "dark" as the theme.
The generated HTML includes a D3.js script that creates a horizontal tree layout of the routes. Each node represents a route, and each link represents the relationship between parent and child routes. The nodes display the route paths and methods, and clicking on a node opens the corresponding handler file in Visual Studio Code using the vscode://file/ URL scheme.
Usage:
func main() {
app := iris.New()
app.Router("/apigraph", apigraph.New(apigraph.Options{Theme: "dark"}))
// Example routes with the same path but different methods:
app.Get("/", func(ctx iris.Context) { ctx.WriteString("GET /") })
app.Get("/users", func(ctx iris.Context) { ctx.WriteString("GET /users") })
app.Get("/users/list", func(ctx iris.Context) { ctx.WriteString("GET /users/list") })
app.Post("/users", func(ctx iris.Context) { ctx.WriteString("POST /users") })
app.Get("/users/{id:int}", func(ctx iris.Context) { ctx.WriteString("GET /users/{id:int}") })
app.Put("/users/{id:int}", func(ctx iris.Context) { ctx.WriteString("PUT /users/{id:int}") })
app.Get("/users/{id:int}/posts", func(ctx iris.Context) { ctx.WriteString("GET /users/{id:int}/posts") })
app.Listen(":8080")
}
func RegisterTheme ¶
func RegisterTheme(theme Theme)
RegisterTheme registers a theme . If a theme with the same name already exists, it is overwritten.
Types ¶
type DefaultTheme ¶
type DefaultTheme struct {
// Name is the name of the theme.
Name string
// BackgroundColor is the background color of the graph.
BackgroundColor string
// Color is the text color of the graph.
Color string
// ReactColor is the color used for interactive elements.
ReactColor string
// StrokeColor is the color used for strokes around elements.
StrokeColor string
}
DefaultTheme defines the default theme structure.
func (*DefaultTheme) GetName ¶
func (t *DefaultTheme) GetName() string
GetName returns the name of the theme.
func (*DefaultTheme) GetStyle ¶
func (t *DefaultTheme) GetStyle() string
GetStyle generates the CSS for the theme.