Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Sep 18, 2023
1 parent f24743a commit e767365
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,19 @@ func main() {
app.Get("/", func(ctx *fiber.Ctx) error {
return ctx.SendStatus(200)
})

app.Get("/foo", func(ctx *fiber.Ctx) error {
txn := newrelic.FromContext(ctx)
segment := txn.StartSegment("foo segment")
defer segment.End()

// do foo

return nil
})

cfg := fibernewrelic.Config{
Application: newrelicApp
Application: newrelicApp,
}

app.Use(fibernewrelic.New(cfg))
Expand Down
117 changes: 92 additions & 25 deletions contrib_versioned_docs/version-paseto_v1.x.x/swagger/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
id: swagger
title: Swagger
---

# Swagger
Expand All @@ -14,52 +15,118 @@ Swagger middleware for [Fiber](https://github.com/gofiber/fiber). The middleware

**Note: Requires Go 1.18 and above**

## Install
### Table of Contents
- [Signatures](#signatures)
- [Installation](#installation)
- [Examples](#examples)
- [Config](#config)
- [Default Config](#default-config)

```
go get -u github.com/gofiber/fiber/v2
go get -u github.com/gofiber/contrib/swagger
```

## Signatures
### Signatures
```go
func New(config ...swagger.Config) fiber.Handler
```

## Config

| Property | Type | Description | Default |
|:----------|:---------|:----------------------------------------------------------------------|:--------|
| BasePath | `string` | BasePath is the base path for the configuration file. | `""` |
| FilePath | `string` | FilePath is the file path to the configuration file. | `""` |

### Installation
Swagger is tested on the latests [Go versions](https://golang.org/dl/) with support for modules. So make sure to initialize one first if you didn't do that yet:
```bash
go mod init github.com/<user>/<repo>
```
And then install the swagger middleware:
```bash
go get github.com/gofiber/contrib/swagger
```

## Examples
Import the middleware package that is part of the Fiber web framework
### Examples
Import the middleware package
```go
import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/contrib/swagger"
)
```

Then create a Fiber app with app := fiber.New().

After you initiate your Fiber app, you can use the following possibilities:

## Default Config

Using the default config:
```go
app.Use(swagger.New(cfg))
```

## Custom Config

Using a custom config:
```go
cfg := swagger.Config{
BasePath: "/", //swagger ui base path
BasePath: "/",
FilePath: "./docs/swagger.json",
Path: "swagger",
Title: "Swagger API Docs",
}

app.Use(swagger.New(cfg))
```

Using multiple instances of Swagger:
```go
// Create Swagger middleware for v1
//
// Swagger will be available at: /api/v1/docs
app.Use(swagger.New(swagger.Config{
BasePath: "/api/v1/",
FilePath: "./docs/v1/swagger.json",
Path: "docs",
}))

// Create Swagger middleware for v2
//
// Swagger will be available at: /api/v2/docs
app.Use(swagger.New(swagger.Config{
BasePath: "/api/v2/",
FilePath: "./docs/v2/swagger.json",
Path: "docs",
}))
```

### Config
```go
type Config struct {
// Next defines a function to skip this middleware when returned true.
//
// Optional. Default: nil
Next func(c *fiber.Ctx) bool

// BasePath for the UI path
//
// Optional. Default: /
BasePath string

// FilePath for the swagger.json or swagger.yaml file
//
// Optional. Default: ./swagger.json
FilePath string

// Path combines with BasePath for the full UI path
//
// Optional. Default: docs
Path string

// Title for the documentation site
//
// Optional. Default: Fiber API documentation
Title string

// CacheAge defines the max-age for the Cache-Control header in seconds.
//
// Optional. Default: 3600 (1 hour)
CacheAge int
}
```

### Default Config
```go
var ConfigDefault = Config{
Next: nil,
BasePath: "/",
FilePath: "./swagger.json",
Path: "docs",
Title: "Fiber API documentation",
CacheAge: 3600, // Default to 1 hour
}
```

0 comments on commit e767365

Please sign in to comment.