Skip to content

Commit c4c6555

Browse files
authored
add patch method to app (#396)
1 parent 0dc3f63 commit c4c6555

File tree

13 files changed

+76
-73
lines changed

13 files changed

+76
-73
lines changed

docs/advanced-guide/circuit-breaker/page.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Circuit Breaker in HTTP Communication
22

3-
Calls to remote resources and services can fail due to temporary issues like slow network connections or timeouts, as well as longer-lasting problems such as service unavailability. While transient faults can be mitigated using the "Retry pattern," there are cases where continual retries are futile, such as during severe service failures.
3+
Calls to remote resources and services can fail due to temporary issues like slow network connections or timeouts, service unavailability. While transient faults can be mitigated using the "Retry pattern", there are cases where continual retries are futile, such as during severe service failures.
44

55
In such scenarios, it's crucial for applications to recognize when an operation is unlikely to succeed and handle the failure appropriately rather than persistently retrying. Indiscriminate use of HTTP retries can even lead to unintentional denial-of-service attacks within the software itself, as multiple clients may flood a failing service with retry attempts.
66

docs/advanced-guide/custom-spans-in-tracing/page.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
# Custom Spans In Tracing
22

3-
GoFr's built-in tracing provides valuable insights into your application's behavior. However, sometimes you might need
4-
even more granular details about specific operations within your application. This is where `custom spans` come in.
3+
GoFr's built-in tracing provides valuable insights into application's behavior. However, sometimes you might need
4+
even more granular details about specific operations within your application. This is where `custom spans` can be used.
55

66
## How it helps?
77
By adding custom spans in traces to your requests, you can:
88

99
- **Gain granular insights:** Custom spans allow you to track specific operations or functions within your application,
1010
providing detailed performance data.
11-
- **Identify bottlenecks:** By analyzing custom spans, you can pinpoint areas of your code that may be causing
11+
- **Identify bottlenecks:** Analyzing custom spans helps to pinpoint areas of your code that may be causing
1212
performance bottlenecks or inefficiencies.
13-
- **Improve debugging:** Custom spans enhance your ability to debug issues by providing visibility into the execution
14-
flow of your application.
13+
- **Improve debugging:** Custom spans enhance the ability to debug issues by providing visibility into the execution
14+
flow of an application.
1515

1616
## Usage
1717

18-
To add a custom trace to a request, you can use the `Trace()` method of GoFr context, which takes the name of the span as an argument
18+
To add a custom trace to a request, GoFr context provides `Trace()` method, which takes the name of the span as an argument
1919
and returns a trace.Span.
2020

2121
```go
@@ -28,7 +28,7 @@ func MyHandler(c context.Context) error {
2828
}
2929
```
3030

31-
In this example, **my-custom-span** is the name of the custom span that you want to add to the request.
31+
In this example, **my-custom-span** is the name of the custom span that is added to the request.
3232
The defer statement ensures that the span is closed even if an error occurs to ensure that the trace is properly recorded.
3333

3434

docs/advanced-guide/grpc/page.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# gRPC
22
We have already seen how GoFr can help ease the development of HTTP servers, but there are
33
cases where performance is primiraliy required sacrificing flexibility. In these types of
4-
scenarios gRPC protocol comes into picture. gRPC is an open-source RPC(Remote Procedure Call)
5-
framework initially developed by Google. {% new-tab-link title="Learn more" href="https://grpc.io/docs/what-is-grpc/introduction/" /%}
4+
scenarios gRPC protocol comes into picture. {% new-tab-link title="gRPC" href="https://grpc.io/docs/what-is-grpc/introduction/" /%} is an open-source RPC(Remote Procedure Call)
5+
framework initially developed by Google.
66

77
## Prerequisites
88
- Install the `protoc` protocol buffer compilation
@@ -30,7 +30,7 @@ framework initially developed by Google. {% new-tab-link title="Learn more" href
3030
## Creating protocol buffers
3131
For a detailed guide, please take a look at the {% new-tab-link title="Tutorial" href="https://grpc.io/docs/languages/go/basics/" /%} at official gRPC docs.
3232

33-
Fistly, we need to create a `customer.proto` file to define our service and the rpc methods that the service provides.
33+
We need to create a `customer.proto` file to define our service and the rpc methods that the service provides.
3434
```protobuf
3535
// Indicates the protocol buffer version that is being used
3636
syntax = "proto3";
@@ -67,7 +67,7 @@ message CustomerData {
6767
}
6868
```
6969

70-
Now run the following command to gegnerate go code using the Go gRPC plugins:
70+
Now run the following command to generate go code using the Go gRPC plugins:
7171
```shell
7272
protoc \
7373
--go_out=. \

docs/advanced-guide/handling-data-migrations/page.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func createTableEmployee() migration.Migrate {
4747
```
4848

4949
`migration.Datasource` have the datasources whose migrations are supported i.e. Redis and SQL (MySQL and PostgreSQL).
50-
All the migrations always run in a transaction.
50+
All migrations always run in a transaction.
5151

5252
For MySQL it is highly recommended to use `IF EXISTS` and `IF NOT EXIST` in DDL commands as MySQL implicitly commits these commands.
5353

@@ -67,7 +67,7 @@ func All() map[int64]migration.Migrate {
6767
}
6868
```
6969

70-
Migrations will run in ascending order of keys in this map.
70+
Migrations run in ascending order of keys in this map.
7171

7272
### Initialisation from main.go
7373

@@ -99,7 +99,6 @@ INFO [16:55:46] Migration 20240226153000 ran successfully
9999
```
100100

101101
GoFr maintains the records in the database itself which helps in tracking which migrations have already been executed and ensures that only migrations that have never been run are executed.
102-
This way, you only need to ensure that your migrations are properly in place. {% new-tab-link title="Learn more" href="https://cloud.google.com/architecture/database-migration-concepts-principles-part-1" /%}
103102

104103
## Migration Records
105104

docs/advanced-guide/remote-log-level-change/page.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
# Remote Log Level Change
22

3-
Gofr makes it easy to adjust the detail captured in your application's logs, even while it's running!
3+
Gofr makes it easy to adjust the details captured in the application's logs, even while it's running!
44

55
This feature allows users to effortlessly fine-tune logging levels without the need for redeployment, enhancing the monitoring and debugging experience.
66
It is facilitated through simple configuration settings.
77

88
## How it helps?
99

10-
- **Effortless Adjustments:** Modify the level of detail in your logs anytime without restarting your application.
11-
This is especially helpful during troubleshooting.
10+
- **Effortless Adjustments:** Modify the log level anytime without restarting the application. This is especially helpful during troubleshooting.
1211
- **Enhanced Visibility:** Easily switch to a more detailed log level (e.g., `DEBUG`) to gain deeper insights into specific issues,
1312
and then switch back to a less detailed level (e.g., `INFO`) for regular operation.
1413
- **Improved Performance:** Generating a large number of logs can overwhelm the logging system, leading to increased I/O operations and resource consumption,
@@ -19,7 +18,7 @@ It is facilitated through simple configuration settings.
1918
To enable remote log level update, users need to specify the following configuration parameter:
2019

2120
```bash
22-
REMOTE_LOG_URL=<URL to your remote log level endpoint> (e.g., https://your-service.com/log-levels)
21+
REMOTE_LOG_URL=<URL to user's remote log level endpoint> (e.g., https://log-service.com/log-levels)
2322
REMOTE_LOG_FETCH_INTERVAL=<Interval in seconds> (default: 15)
2423
```
2524
@@ -44,6 +43,6 @@ The remote log level endpoint should return a JSON response in the following for
4443
```
4544
4645
- **serviceName:** Identifies the service for which log levels are configured.
47-
- **logLevel:** The new log level you want to set for the specified service.
46+
- **logLevel:** The new log level user want to set for the specified service.
4847
4948
GoFr parses this response and adjusts log levels based on the provided configurations.

docs/advanced-guide/using-publisher-subscriber/page.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func (ctx *gofr.Context) error
115115
```
116116

117117
`Subscribe` method of GoFr App will continuously read a message from the configured `PUBSUB_BACKEND` which
118-
can be either `KAFKA` or `GOOGLE` as of now. These can be configured in your configs folder under `.env`
118+
can be either `KAFKA` or `GOOGLE` as of now. These can be configured in the configs folder under `.env`
119119

120120
> The returned error determines which messages are to be committed and which ones are to be consumed again.
121121

@@ -127,7 +127,7 @@ app.Subscribe("order-status", func(ctx *gofr.Context)error{
127127
})
128128
```
129129

130-
The context `ctx` provides you with the following methods :
130+
The context `ctx` provides user with the following methods :
131131

132132
Bind() - Bind the message value to a given interface.
133133
Param(p string)/PathParam(p string) - Will return the topic when the same is passed as param.

docs/quick-start/configuration/page.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
# Configurations
22

3-
GoFr reads configuration via environment variables. It provides an easy way to manage this. Application code is decoupled from how configuration is managed as per the {% new-tab-link title="12-factor" href="https://12factor.net/config" /%}.
4-
Configs in GoFr can be used to initialise datasources, tracing. In doing so it abstract the logic and gives an easy interface to setup different things.
3+
GoFr simplifies configuration management by reading configuration via environment variables.
4+
Application code is decoupled from how configuration is managed as per the {%new-tab-link title="12-factor" href="https://12factor.net/config" %}.
5+
Configs in GoFr can be used to initialise datasources, tracing , setting log levels, changing default http or metrics port.
6+
This abstraction provides a user-friendly interface for configuring your application without modifying the code itself.
57

68
To set configs create a `configs` directory in the project's root and add `.env` file.
79

10+
Follow this directory structure within your GoFr project:
11+
```dotenv
12+
my-gofr-app/
13+
├── config/
14+
│ ├── dev.env
15+
│ ├── staging.env
16+
│ └── prod.env
17+
├── main.go
18+
└── ...
19+
```
20+
821
By default, GoFr starts HTTP server at port 8000, in order to change that we can add the config `HTTP_PORT`
922
Similarly to Set the app-name you can add `APP_NAME`. For example:
1023

docs/quick-start/connecting-mysql/page.md

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Just like Redis gofr also supports connection to SQL(mysql and postgres) databas
44

55
## Setup
66

7-
You can run MySQL and create a database locally using the following docker command:
7+
Users can run MySQL and create a database locally using the following docker command:
88

99
```bash
1010
docker run --name gofr-mysql -e MYSQL_ROOT_PASSWORD=root123 -e MYSQL_DATABASE=test_db -p 3306:3306 -d mysql:8.0.30
@@ -38,7 +38,7 @@ DB_PORT=3306
3838
DB_DIALECT=mysql
3939
```
4040

41-
Now in the following example let's store customer data using **POST** `/customer` and then use **GET** `/customer` to retrieve the same.
41+
Now in the following example, we'll store customer data using **POST** `/customer` and then use **GET** `/customer` to retrieve the same.
4242
We will be storing the customer data with `id` and `name`.
4343

4444
After adding code to add and retrieve data from MySQL datastore, `main.go` will be updated to the following.
@@ -118,13 +118,6 @@ curl --location --request POST 'http://localhost:9000/customer/abc'
118118

119119
curl --location --request POST 'http://localhost:9000/customer/xyz'
120120
```
121-
122-
You will see the following output if database is successfully updated
123-
124-
```json
125-
{}
126-
```
127-
128121
Now when we access {% new-tab-link title="http://localhost:9000/customer" href="http://localhost:9000/customer" /%} we should see the following output
129122

130123
```json

docs/quick-start/connecting-redis/page.md

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,39 @@ GoFr simplifies the process of connecting to Redis.
44

55
## Setup:
66

7-
Before using Redis with GoFr, you need to have Redis installed. You can use Docker to set up a Redis container:
7+
Ensure you have Redis installed on your system.
8+
9+
Optionally, you can use Docker to set up a development environment as described below.
810

911
```bash
1012
docker run --name gofr-redis -p 6379:6379 -d redis
1113
```
1214

13-
To set a sample key, run the following command:
15+
You can set a sample key `greeting` using the following command:
1416

1517
```bash
16-
docker exec -it gofr-redis bash -c 'redis-cli SET greeting "Hello from Redis."'docker exec -it gofr-redis bash -c 'redis-cli SET greeting "Hello from Redis."'
18+
docker exec -it gofr-redis bash -c 'redis-cli SET greeting "Hello from Redis."'
1719
```
1820

1921
## Configuration & Usage
2022

21-
GoFr requires certain configurations to connect to Redis. The necessary configurations include
22-
`REDIS_HOST`and `REDIS_PORT`. Update the `.env` file in the configs directory with the following content:
23+
GoFr applications relies on environment variables to configure and connect to a Redis server.
24+
These variables are stored in a file named `.env` located within the configs directory in your project root.
25+
26+
Following configuration keys are required for Redis connectivity:
27+
28+
* `REDIS_HOST`: It specifies the hostname or IP address of your Redis server.
29+
* `REDIS_PORT`: It specifies the port number on which your Redis server is listening. The default Redis port is 6379.
2330

24-
```swift
31+
```bash
2532
APP_NAME=test-service
2633
HTTP_PORT=9000
2734

2835
REDIS_HOST=localhost
2936
REDIS_PORT=6379
3037
```
3138

32-
Once the Redis configurations are set, you can use Redis in your GoFr application.
33-
Below is an example of how to retrieve data from Redis in the `main.go` file:
39+
The following code snippet demonstrates how to retrieve data from a Redis key named "greeting":
3440

3541
```go
3642
package main
@@ -64,6 +70,3 @@ func main() {
6470
app.Run()
6571
}
6672
```
67-
68-
The above code demonstrates how to perform Redis operations using the latest GoFr syntax.
69-
You can adapt this example to fit your application's specific requirements.

docs/quick-start/introduction/page.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
11
# Prerequisite
22

33
- Go 1.20 or above.
4-
To check the version use the following command `go version`.
4+
To check Go version use the following command `go version`.
55

66
- Prior familiarity with Golang syntax is essential. {% new-tab-link title="Golang Tour" href="https://tour.golang.org/" /%} is highly recommended as it has an excellent guided tour.
77

88
## Write your first GoFr API
99

10-
Let's start by initializing the go module by using the following command.
10+
Let's start by initializing the {% new-tab-link title="go module" href="https://go.dev/ref/mod" /%} by using the following command.
1111

1212
```bash
1313
go mod init github.com/example
1414
```
1515

16-
To know more about go modules refer {% new-tab-link title="here" href="https://go.dev/ref/mod" /%}.
17-
18-
Add {% new-tab-link title="gofr" href="https://github.com/gofr-dev/gofr" /%} package to the project using the following command
16+
Add {% new-tab-link title="gofr" href="https://github.com/gofr-dev/gofr" /%} package to the project using the following command.
1917

2018
```bash
2119
go get gofr.dev
2220
```
2321

24-
Now add the following code to _main.go_ file
22+
This code snippet showcases the creation of a simple GoFr application that defines a route and serves a response.
23+
You can add this code to your main.go file.
2524

2625
```go
2726
package main
@@ -44,15 +43,15 @@ func main() {
4443
}
4544
```
4645

47-
Before running the server run the following go command to download and sync the required modules.
46+
Before starting the server, run the following command in your terminal to ensure you have downloaded and synchronized all required dependencies for your project.
4847

4948
`go mod tidy`
5049

51-
To run the server, use the command
50+
Once the dependencies are synchronized, start the GoFr server using the following command:
5251

5352
`go run main.go`
5453

55-
This would start the server at 8000 port, you can access {% new-tab-link title="http://localhost:8000/greet" href="http://localhost:8000/greet" /%} from your browser, you would be able to see the output as following with _Status Code 200_ as per REST Standard
54+
This would start the server at 8000 port, `/greet` endpoint can be accessed from your browser at {% new-tab-link title="http://localhost:8000/greet" href="http://localhost:8000/greet" /%} , you would be able to see the output as following with _Status Code 200_ as per REST Standard.
5655

5756
```json
5857
{ "data": "Hello World!" }
@@ -66,11 +65,11 @@ The `hello-world` server involves three essential steps:
6665

6766
When `gofr.New()` is called, it initializes the framework and handles various setup tasks like initialising logger, metrics, datasources etc based on the configs.
6867

69-
_This single line is a standard part of all gofr-based servers._
68+
_This single line is a standard part of all gofr servers._
7069

7170
2. **Attaching a Handler to a Path:**
7271

73-
In this step, we instruct the server to associate an HTTP request with a specific handler function. This is achieved through `app.GET("/greet", HandlerFunction)`, where _GET /greet_ maps to HandlerFunction. Likewise, `app.POST("/todo", ToDoCreationHandler)` links a _POST_ request to the /todo endpoint with _ToDoCreationHandler_.
72+
In this step, the server is instructed to associate an HTTP request with a specific handler function. This is achieved through `app.GET("/greet", HandlerFunction)`, where _GET /greet_ maps to HandlerFunction. Likewise, `app.POST("/todo", ToDoCreationHandler)` links a _POST_ request to the /todo endpoint with _ToDoCreationHandler_.
7473

7574
**Good To Know**
7675

0 commit comments

Comments
 (0)