-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add docs from gofiber/recipes@1542b95
- Loading branch information
1 parent
e04fbcc
commit 2280ecb
Showing
5 changed files
with
133 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |