Skip to content

Commit 6c4624b

Browse files
committed
Merge branch 'development' of github.com:gofr-dev/gofr into development
2 parents 23635d4 + 9b87848 commit 6c4624b

File tree

69 files changed

+1097
-167
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+1097
-167
lines changed

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

Lines changed: 1 addition & 3 deletions
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

@@ -42,5 +42,3 @@ func main() {
4242

4343
Circuit breaker state changes to open when number of consecutive failed requests increases the threshold.
4444
When it is in open state, GoFr makes request to the aliveness endpoint (default being - /.well-known/alive) at an equal interval of time provided in config.
45-
46-
To override the default aliveness endpoint {% new-tab-link newtab=false title="refer" href="/docs/advanced-guide/monitoring-service-health" /%}.

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/http-authentication/page.md

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
# HTTP Authentication
2+
23
Authentication is a crucial aspect of web applications, controlling access to resources based on user roles or permissions.
3-
It is the process of verifying a user's identity to grant access to protected resources. It ensures only
4-
authenticated users can perform actions or access data within an application.
4+
It is the process of verifying a user's identity to grant access to protected resources. It ensures that only authenticated
5+
users can perform actions or access data within an application.
56

67
GoFr offer various approaches to implement authorization.
78

89
## 1. HTTP Basic Auth
910
*Basic Authentication* is a simple HTTP authentication scheme where the user's credentials (username and password) are
1011
transmitted in the request header in a Base64-encoded format.
1112

12-
Basic auth is the simplest way to authenticate your APIs. It's built on
13-
{% new-tab-link title="HTTP protocol authentication scheme" href="https://datatracker.ietf.org/doc/html/rfc7617" /%}. It involves sending the term
14-
15-
`Basic` trailed by the Base64-encoded `<username>:<password>` within the standard `Authorization` header.
13+
Basic auth is the simplest way to authenticate your APIs. It's built on
14+
{% new-tab-link title="HTTP protocol authentication scheme" href="https://datatracker.ietf.org/doc/html/rfc7617" /%}.
15+
It involves sending the prefix `Basic` trailed by the Base64-encoded `<username>:<password>` within the standard `Authorization` header.
1616

1717
### Basic Authentication in GoFr
1818

1919
GoFr offers two ways to implement basic authentication:
2020

2121
**1. Predefined Credentials**
2222

23-
Use `EnableBasicAuth(username, password)` to configure Gofr with pre-defined credentials.
23+
Use `EnableBasicAuth(username, password)` to configure GoFr with pre-defined credentials.
2424

2525
```go
2626
func main() {
@@ -39,7 +39,8 @@ func main() {
3939

4040
**2. Custom Validation Function**
4141

42-
Use `EnableBasicAuthWithFunc(validationFunc)` to implement your own validation logic for credentials. The `validationFunc` takes the username and password as arguments and returns true if valid, false otherwise.
42+
Use `EnableBasicAuthWithFunc(validationFunc)` to implement your own validation logic for credentials.
43+
The `validationFunc` takes the username and password as arguments and returns true if valid, false otherwise.
4344

4445
```go
4546
func validateUser(username string, password string) bool {
@@ -63,7 +64,6 @@ func main() {
6364
```
6465

6566
### Adding Basic Authentication to HTTP Services
66-
6767
This code snippet demonstrates how to add basic authentication to an HTTP service in GoFr and make a request with the appropriate Authorization header:
6868

6969
```go
@@ -73,13 +73,13 @@ app.AddHTTPService("order", "https://localhost:2000",
7373
```
7474

7575
## 2. API Keys Auth
76-
Users include a unique API key in the request header for validation against a store of authorized keys.
76+
*API Key Authentication* is an HTTP authentication scheme where a unique API key is included in the request header for validation against a store of authorized keys.
7777

7878
### Usage:
7979
GoFr offers two ways to implement API Keys authentication.
8080

8181
**1. Framework Default Validation**
82-
- Users can select the framework's default validation using **_EnableAPIKeyAuth(apiKeys ...string)_**
82+
- GoFr's default validation can be selected using **_EnableAPIKeyAuth(apiKeys ...string)_**
8383

8484
```go
8585
package main
@@ -97,7 +97,7 @@ func main() {
9797
```
9898

9999
**2. Custom Validation Function**
100-
- Users can create their own validator function `apiKeyValidator(apiKey string) bool` for validating APIKeys and pass the func in **_EnableAPIKeyAuthWithFunc(validator)_**
100+
- GoFr allows a custom validator function `apiKeyValidator(apiKey string) bool` for validating APIKeys and pass the func in **_EnableAPIKeyAuthWithFunc(validator)_**
101101

102102
```go
103103
package main
@@ -128,11 +128,10 @@ app.AddHTTPService("http-server-using-redis", "http://localhost:8000", &service.
128128
```
129129

130130
## 3. OAuth 2.0
131-
OAuth 2.0 is the industry-standard protocol for authorization.
131+
{% new-tab-link title="OAuth" href="https://www.rfc-editor.org/rfc/rfc6749" /%} 2.0 is the industry-standard protocol for authorization.
132132
It focuses on client developer simplicity while providing specific authorization flows for web applications, desktop applications, mobile phones, and living room devices.
133-
To know more about it refer {% new-tab-link title="here" href="https://www.rfc-editor.org/rfc/rfc6749" /%}
134133

135-
It involves sending the term `Bearer` trailed by the encoded token within the standard `Authorization` header.
134+
It involves sending the prefix `Bearer` trailed by the encoded token within the standard `Authorization` header.
136135

137136
### OAuth Authentication in GoFr
138137

@@ -141,7 +140,7 @@ GoFr supports authenticating tokens encoded by algorithm `RS256/384/512`.
141140
### App level Authentication
142141
Enable OAuth 2.0 with three-legged flow to authenticate requests
143142

144-
Use `EnableOAuth(jwks-endpoint,refresh_interval)` to configure Gofr with pre-defined credentials.
143+
Use `EnableOAuth(jwks-endpoint,refresh_interval)` to configure GoFr with pre-defined credentials.
145144

146145
```go
147146
func main() {
@@ -163,17 +162,17 @@ For server-to-server communication it follows two-legged OAuth, also known as "c
163162
where the client application directly exchanges its own credentials (ClientID and ClientSecret)
164163
for an access token without involving any end-user interaction.
165164

166-
This code snippet demonstrates how two-legged OAuth authentication is added to an HTTP service in GoFr and make a request with the appropriate Authorization header.
165+
This code snippet demonstrates how two-legged OAuth authentication is added to an HTTP service in GoFr and make a request with the appropriate Authorization header:
167166

168167
```go
169-
a.AddHTTPService("orders", "http://localhost:9000",
168+
app.AddHTTPService("orders", "http://localhost:9000",
170169
&service.OAuthConfig{ // Replace with your credentials
171-
ClientID: "0iyeGcLYWudLGqZfD6HvOdZHZ5TlciAJ",
172-
ClientSecret: "GQXTY2f9186nUS3C9WWi7eJz8-iVEsxq7lKxdjfhOJbsEPPtEszL3AxFn8k_NAER",
173-
TokenURL: "https://dev-zq6tvaxf3v7p0g7j.us.auth0.com/oauth/token",
174-
Scopes: []string{"read:order"},
175-
EndpointParams: map[string][]string{
176-
"audience": {"https://dev-zq6tvaxf3v7p0g7j.us.auth0.com/api/v2/"},
170+
ClientID: "0iyeGcLYWudLGqZfD6HvOdZHZ5TlciAJ",
171+
ClientSecret: "GQXTY2f9186nUS3C9WWi7eJz8-iVEsxq7lKxdjfhOJbsEPPtEszL3AxFn8k_NAER",
172+
TokenURL: "https://dev-zq6tvaxf3v7p0g7j.us.auth0.com/oauth/token",
173+
Scopes: []string{"read:order"},
174+
EndpointParams: map[string][]string{
175+
"audience": {"https://dev-zq6tvaxf3v7p0g7j.us.auth0.com/api/v2/"},
177176
},
178177
})
179-
```
178+
```

docs/advanced-guide/http-communication/page.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# Interservice HTTP Calls
1+
# Inter-Service HTTP Calls
22

3-
GoFr promotes microservice architecture and to facilitate the same, it provides the support
4-
to initialize HTTP services at application level using `AddHTTPService()` method.
5-
Support for inter-service http calls provide the following benefits:
3+
GoFr promotes microservice architecture and to facilitate the same, it provides the support to initialize HTTP services
4+
at application level using `AddHTTPService()` method.
65

7-
1. Access to the method from container - GET, PUT, POST, PATCH, DELETE.
6+
Support for inter-service HTTP calls provide the following benefits:
7+
1. Access to the methods from container - GET, PUT, POST, PATCH, DELETE.
88
2. Logs and traces for the request.
99
3. {% new-tab-link newtab=false title="Circuit breaking" href="/docs/advanced-guide/circuit-breaker" /%} for enhanced resilience and fault tolerance.
1010
4. {% new-tab-link newtab=false title="Custom Health Check" href="/docs/advanced-guide/monitoring-service-health" /%} Endpoints
@@ -13,15 +13,15 @@ Support for inter-service http calls provide the following benefits:
1313

1414
### Registering a simple HTTP Service
1515

16-
Users can register a new HTTP service using the application method `AddHTTPService()`.
17-
It takes in a service name and service address argument to register your dependent service at application level.
18-
Users can easily register multiple dependent services easily, which is a common use case in a microservice architecture.
16+
GoFr allows registering a new HTTP service using the application method `AddHTTPService()`.
17+
It takes in a service name and service address argument to register the dependent service at application level.
18+
Registration of multiple dependent services is quite easier, which is a common use case in a microservice architecture.
1919

2020
> The services instances are maintained by the container.
2121
22-
Users can provide other options additionally to coat their basic http client with features like circuit-breaker and
23-
custom health check to add to the functionality of the HTTP service.
24-
The design choice for this was made so that user can add as many options as required and are order agnostic,
22+
Other provided options can be added additionally to coat the basic http client with features like circuit-breaker and
23+
custom health check and add to the functionality of the HTTP service.
24+
The design choice for this was made such as many options as required can be added and are order agnostic,
2525
i.e. the order of the options is not important.
2626

2727
> Service names are to be kept unique to one service.
@@ -31,7 +31,6 @@ app.AddHTTPService(<service_name> , <service_address>)
3131
```
3232

3333
#### Example
34-
3534
```go
3635
package main
3736

@@ -55,8 +54,9 @@ func main() {
5554

5655
### Accessing HTTP Service in handler
5756

58-
Users can access the HTTP service client from anywhere using the gofr.Context that gets passed on from the handler.
59-
The service name that was given at the time of registering the service.
57+
The HTTP service client is accessible anywhere from `gofr.Context` that gets passed on from the handler.
58+
Using the `GetHTTPService` method with the service name that was given at the time of registering the service,
59+
the client can be retrieved as shown below:
6060

6161
```go
6262
svc := ctx.GetHTTPService(<service_name>)

docs/advanced-guide/monitoring-service-health/page.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# Monitoring Service Health
22

3-
Health check in microservices refers to a mechanism or process implemented within each service to assess its operational status and readiness to handle requests. It involves regularly querying the service to determine if it is functioning correctly, typically by evaluating its responsiveness and ability to perform essential tasks. Health checks play a critical role in ensuring service availability, detecting failures, preventing cascading issues, and facilitating effective traffic routing in distributed systems.
3+
Health check in microservices refers to a mechanism or process implemented within each service to assess its operational status
4+
and readiness to handle requests. It involves regularly querying the service to determine if it is functioning correctly,
5+
typically by evaluating its responsiveness and ability to perform essential tasks. Health checks play a critical role in ensuring service availability,
6+
detecting failures, preventing cascading issues, and facilitating effective traffic routing in distributed systems.
47

5-
## GoFr by default registers two endpoints which are :
8+
## GoFr by default registers two endpoints which are:
69

710
### 1. Aliveness - /.well-known/alive
811

9-
It is an endpoint which return the following response when the service is UP with a 200 response code.
12+
It is an endpoint which returns the following response with a 200 status code, when the service is UP.
1013

1114
```json
1215
{
@@ -18,8 +21,7 @@ It is an endpoint which return the following response when the service is UP wit
1821

1922
It is also used when state of {% new-tab-link newtab=false title="circuit breaker" href="/docs/advanced-guide/circuit-breaker" /%} is open.
2023

21-
To override the endpoint when registering HTTP Service pass the following option.
22-
24+
To override this endpoint, pass the following option while registering HTTP Service:
2325
```go
2426
&service.HealthConfig{
2527
HealthEndpoint: "breeds",
@@ -28,10 +30,9 @@ To override the endpoint when registering HTTP Service pass the following option
2830

2931
### 2. Health-Check - /.well-known/health-check
3032

31-
It returns if the service is UP or DOWN along with stats, host, status about the dependent datasources and services.
32-
33-
Sample response of how it appears when all the services, and connected data sources are up.
33+
It is an endpoint which returns whether the service is UP or DOWN along with stats, host, status about the dependent datasources and services.
3434

35+
Sample response of how it appears when all the services, and connected data sources are UP:
3536
```json
3637
{
3738
"data": {

0 commit comments

Comments
 (0)