You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/advanced-guide/circuit-breaker/page.md
+4-6Lines changed: 4 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Circuit Breaker in HTTP Communication
2
2
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.
4
4
5
5
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.
6
6
@@ -23,12 +23,12 @@ import (
23
23
funcmain() {
24
24
// Create a new application
25
25
app:= gofr.New()
26
-
26
+
27
27
app.AddHTTPService("order", "https://order-func",
28
28
&service.CircuitBreakerConfig{
29
29
// Number of consecutive failed requests after which circuit breaker will be enabled
30
30
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.
32
32
Interval: 1 * time.Second,
33
33
},
34
34
)
@@ -41,6 +41,4 @@ func main() {
41
41
```
42
42
43
43
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.
Copy file name to clipboardExpand all lines: docs/advanced-guide/grpc/page.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,8 @@
1
1
# gRPC
2
2
We have already seen how GoFr can help ease the development of HTTP servers, but there are
3
3
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.
6
6
7
7
## Prerequisites
8
8
- Install the `protoc` protocol buffer compilation
@@ -30,7 +30,7 @@ framework initially developed by Google. {% new-tab-link title="Learn more" href
30
30
## Creating protocol buffers
31
31
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.
32
32
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.
34
34
```protobuf
35
35
// Indicates the protocol buffer version that is being used
36
36
syntax = "proto3";
@@ -67,7 +67,7 @@ message CustomerData {
67
67
}
68
68
```
69
69
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:
Copy file name to clipboardExpand all lines: docs/advanced-guide/handling-data-migrations/page.md
+30-20Lines changed: 30 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
# Handling Data Migrations
2
2
3
3
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.
5
5
6
6
## Usage
7
7
@@ -11,12 +11,13 @@ It is recommended to maintain a migrations directory in your project root to enh
11
11
12
12
**Migration file names**
13
13
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.
15
15
This helps prevent numbering conflicts and allows for maintaining the correct sort order by name in different filesystem views.
16
16
17
17
Create the following file in migrations directory.
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
69
73
70
-
### Initialisation from main.go
71
74
```go
72
75
package main
73
76
@@ -95,11 +98,7 @@ When we run the app we will see the following logs for migrations which ran succ
95
98
INFO [16:55:46] Migration 20240226153000 ran successfully
96
99
```
97
100
98
-
99
-
100
-
101
101
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" /%}
103
102
104
103
## Migration Records
105
104
@@ -108,21 +107,32 @@ This way, you only need to ensure that your migrations are properly in place. {%
108
107
Migration records are stored and maintained in **gofr_migrations** table which has the following schema:
It involves sending the prefix `Basic` trailed by the Base64-encoded `<username>:<password>` within the standard `Authorization` header.
16
16
17
17
### Basic Authentication in GoFr
18
18
19
19
GoFr offers two ways to implement basic authentication:
20
20
21
21
**1. Predefined Credentials**
22
22
23
-
Use `EnableBasicAuth(username, password)` to configure Gofr with pre-defined credentials.
23
+
Use `EnableBasicAuth(username, password)` to configure GoFr with pre-defined credentials.
24
24
25
25
```go
26
26
funcmain() {
@@ -39,7 +39,8 @@ func main() {
39
39
40
40
**2. Custom Validation Function**
41
41
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.
This code snippet demonstrates how to add basic authentication to an HTTP service in GoFr and make a request with the appropriate Authorization header:
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.
77
77
78
78
### Usage:
79
79
GoFr offers two ways to implement API Keys authentication.
80
80
81
81
**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)_**
83
83
84
84
```go
85
85
package main
@@ -97,7 +97,7 @@ func main() {
97
97
```
98
98
99
99
**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)_**
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.
132
132
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" /%}
134
133
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.
Enable OAuth 2.0 with three-legged flow to authenticate requests
143
142
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.
145
144
146
145
```go
147
146
funcmain() {
@@ -163,17 +162,17 @@ For server-to-server communication it follows two-legged OAuth, also known as "c
163
162
where the client application directly exchanges its own credentials (ClientID and ClientSecret)
164
163
for an access token without involving any end-user interaction.
165
164
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:
0 commit comments