Skip to content

Commit

Permalink
Add docs from gofiber/recipes@1542b95
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Nov 26, 2024
1 parent e04fbcc commit 2280ecb
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 131 deletions.
2 changes: 1 addition & 1 deletion docs/recipes/autocert/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Autocert
keywords: [autocert, tls, letsencrypt, ssl, https]
keywords: [autocert, tls, letsencrypt, ssl, https, certificate]
---

# Autocert Example
Expand Down
48 changes: 24 additions & 24 deletions docs/recipes/dummyjson/README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
---
title: Dummy JSON Proxy
keywords: [dummyjson, proxy, json, server]
---

# Simple Fiber Proxy Server
---
title: Dummy JSON Proxy
keywords: [dummyjson, proxy, json, server]
---

# Simple Fiber Proxy Server

[![Github](https://img.shields.io/static/v1?label=&message=Github&color=2ea44f&style=for-the-badge&logo=github)](https://github.com/gofiber/recipes/tree/master/dummyjson) [![StackBlitz](https://img.shields.io/static/v1?label=&message=StackBlitz&color=2ea44f&style=for-the-badge&logo=StackBlitz)](https://stackblitz.com/github/gofiber/recipes/tree/master/dummyjson)

This is a basic Go application using the Fiber framework to create a web server. The server listens on port 3000 and has a single route (`GET /`) that fetches data from an external URL (`https://dummyjson.com/products/1`) and forwards it to the client.

### How to Run

1. Clone the repository.
2. Navigate to the project directory.
3. Run `go run main.go`.
4. Visit `http://localhost:3000/` in a web browser or use a tool like `curl` to test it.

### What It Does

- Fetches data from an external service, in this case `DummyJson.com`
- Forwards the fetched data or an error message to the client.

### Error Handling

- Returns a 500 Internal Server Error if any issue occurs during the fetch.
- Returns the same status code as the external service if it's not a 200 OK.
This is a basic Go application using the Fiber framework to create a web server. The server listens on port 3000 and has a single route (`GET /`) that fetches data from an external URL (`https://dummyjson.com/products/1`) and forwards it to the client.

### How to Run

1. Clone the repository.
2. Navigate to the project directory.
3. Run `go run main.go`.
4. Visit `http://localhost:3000/` in a web browser or use a tool like `curl` to test it.

### What It Does

- Fetches data from an external service, in this case `DummyJson.com`
- Forwards the fetched data or an error message to the client.

### Error Handling

- Returns a 500 Internal Server Error if any issue occurs during the fetch.
- Returns the same status code as the external service if it's not a 200 OK.
68 changes: 34 additions & 34 deletions docs/recipes/react-router/web/src/assets/fiber-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion docs/recipes/sqlc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ keywords: [database, sqlc, postgresql]

> #### 🎯 [fiber](https://github.com/gofiber/fiber) + [sqlc](https://github.com/sqlc-dev/sqlc) Example
## 👀 Usage
## Usage

#### 1. Run Postgres

```bash
$ docker compose build
```
Expand Down
142 changes: 71 additions & 71 deletions docs/recipes/swagger/README.md
Original file line number Diff line number Diff line change
@@ -1,74 +1,74 @@
---
title: Swagger
keywords: [swagger, api, documentation, contrib]
---

# Swagger API Documentation
---
title: Swagger
keywords: [swagger, api, documentation, contrib]
---

# Swagger API Documentation

[![Github](https://img.shields.io/static/v1?label=&message=Github&color=2ea44f&style=for-the-badge&logo=github)](https://github.com/gofiber/recipes/tree/master/swagger) [![StackBlitz](https://img.shields.io/static/v1?label=&message=StackBlitz&color=2ea44f&style=for-the-badge&logo=StackBlitz)](https://stackblitz.com/github/gofiber/recipes/tree/master/swagger)

This project demonstrates how to integrate Swagger for API documentation in a Go application.

## Prerequisites

Ensure you have the following installed:

- Golang
- [Swag](https://github.com/swaggo/swag) for generating Swagger docs

## Setup

1. Clone the repository:
```sh
git clone https://github.com/gofiber/recipes.git
cd recipes/swagger
```

2. Install dependencies:
```sh
go get -u github.com/swaggo/swag/cmd/swag
go get -u github.com/swaggo/gin-swagger
go get -u github.com/swaggo/files
```

## Generating Swagger Docs

1. Generate the Swagger documentation:
```sh
swag init
```

## Running the Application

1. Start the application:
```sh
go run main.go
```

2. Access the Swagger UI:
Open your browser and navigate to `http://localhost:8080/swagger/index.html`

## Example

Here is an example of how to document an API endpoint using Swag:

```go
// @Summary Show an account
// @Description get string by ID
// @ID get-string-by-int
// @Accept json
// @Produce json
// @Param id path int true "Account ID"
// @Success 200 {object} model.Account
// @Failure 400 {object} http.Response
// @Failure 404 {object} http.Response
// @Router /accounts/{id} [get]
func GetAccount(c *gin.Context) {
// Your code here
}
```

## References

- [Swag Documentation](https://github.com/swaggo/swag)
- [Gin Swagger Middleware](https://github.com/swaggo/gin-swagger)
This project demonstrates how to integrate Swagger for API documentation in a Go application.

## Prerequisites

Ensure you have the following installed:

- Golang
- [Swag](https://github.com/swaggo/swag) for generating Swagger docs

## Setup

1. Clone the repository:
```sh
git clone https://github.com/gofiber/recipes.git
cd recipes/swagger
```

2. Install dependencies:
```sh
go get -u github.com/swaggo/swag/cmd/swag
go get -u github.com/swaggo/gin-swagger
go get -u github.com/swaggo/files
```

## Generating Swagger Docs

1. Generate the Swagger documentation:
```sh
swag init
```

## Running the Application

1. Start the application:
```sh
go run main.go
```

2. Access the Swagger UI:
Open your browser and navigate to `http://localhost:8080/swagger/index.html`

## Example

Here is an example of how to document an API endpoint using Swag:

```go
// @Summary Show an account
// @Description get string by ID
// @ID get-string-by-int
// @Accept json
// @Produce json
// @Param id path int true "Account ID"
// @Success 200 {object} model.Account
// @Failure 400 {object} http.Response
// @Failure 404 {object} http.Response
// @Router /accounts/{id} [get]
func GetAccount(c *gin.Context) {
// Your code here
}
```

## References

- [Swag Documentation](https://github.com/swaggo/swag)
- [Gin Swagger Middleware](https://github.com/swaggo/gin-swagger)

0 comments on commit 2280ecb

Please sign in to comment.