Skip to content

Commit 7a1e069

Browse files
Merge pull request #402 from gofr-dev/release/v1.2.0
Release/v1.2.0
2 parents 7fa2a9a + c93ab7e commit 7a1e069

File tree

75 files changed

+1387
-405
lines changed

Some content is hidden

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

75 files changed

+1387
-405
lines changed

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

Lines changed: 4 additions & 6 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

@@ -23,12 +23,12 @@ import (
2323
func main() {
2424
// Create a new application
2525
app := gofr.New()
26-
26+
2727
app.AddHTTPService("order", "https://order-func",
2828
&service.CircuitBreakerConfig{
2929
// Number of consecutive failed requests after which circuit breaker will be enabled
3030
Threshold: 4,
31-
// Time interval at which circuit breaker will hit the aliveness endpoint.
31+
// Time interval at which circuit breaker will hit the aliveness endpoint.
3232
Interval: 1 * time.Second,
3333
},
3434
)
@@ -41,6 +41,4 @@ func main() {
4141
```
4242

4343
Circuit breaker state changes to open when number of consecutive failed requests increases the threshold.
44-
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 title="refer" href="/docs/advanced-guide/monitoring-service-health" /%}.
44+
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.

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: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Handling Data Migrations
22

33
Suppose you manually make changes to your database, and now it's your responsibility to inform other developers to execute them. Additionally, you need to keep track of which changes should be applied to production machines in the next deployment.
4-
Gofr supports data migrations for MySQL, Postgres and Redis which allows to alter the state of a database, be it adding a new column to existing table or modifying the data type of existing column or adding constraints to an existing table, setting and removing keys etc.
4+
Gofr supports data migrations for MySQL, Postgres and Redis which allows to alter the state of a database, be it adding a new column to existing table or modifying the data type of existing column or adding constraints to an existing table, setting and removing keys etc.
55

66
## Usage
77

@@ -11,12 +11,13 @@ It is recommended to maintain a migrations directory in your project root to enh
1111

1212
**Migration file names**
1313

14-
It is recommended that each migration file should be numbered in the format of *YYYYMMDDHHMMSS* when the migration was created.
14+
It is recommended that each migration file should be numbered in the format of _YYYYMMDDHHMMSS_ when the migration was created.
1515
This helps prevent numbering conflicts and allows for maintaining the correct sort order by name in different filesystem views.
1616

1717
Create the following file in migrations directory.
1818

1919
**Filename : 20240226153000_create_employee_table.go**
20+
2021
```go
2122
package migrations
2223

@@ -45,14 +46,15 @@ func createTableEmployee() migration.Migrate {
4546
}
4647
```
4748

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

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

5354
**Create a function which returns all the migrations in a map**
5455

5556
**Filename : all.go**
57+
5658
```go
5759
package migrations
5860

@@ -65,9 +67,10 @@ func All() map[int64]migration.Migrate {
6567
}
6668
```
6769

68-
Migrations will run in ascending order of keys in this map.
70+
Migrations run in ascending order of keys in this map.
71+
72+
### Initialisation from main.go
6973

70-
### Initialisation from main.go
7174
```go
7275
package main
7376

@@ -95,11 +98,7 @@ When we run the app we will see the following logs for migrations which ran succ
9598
INFO [16:55:46] Migration 20240226153000 ran successfully
9699
```
97100

98-
99-
100-
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

@@ -108,21 +107,32 @@ This way, you only need to ensure that your migrations are properly in place. {%
108107
Migration records are stored and maintained in **gofr_migrations** table which has the following schema:
109108

110109
{% table %}
111-
* Field
112-
* Type
110+
111+
- Field
112+
- Type
113+
113114
---
114-
* version
115-
* bigint
115+
116+
- version
117+
- bigint
118+
116119
---
117-
* method
118-
* varchar(4)
120+
121+
- method
122+
- varchar(4)
123+
119124
---
120-
* start_time
121-
* timestamp
125+
126+
- start_time
127+
- timestamp
128+
122129
---
123-
* duration
124-
* bigint
130+
131+
- duration
132+
- bigint
133+
125134
---
135+
126136
{% /table %}
127137

128138
**REDIS**

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+
```

0 commit comments

Comments
 (0)