Skip to content

Commit

Permalink
Merge pull request #1402 from ccoveille-forks/doc-format
Browse files Browse the repository at this point in the history
chore: format all Markdown files with mdsf
  • Loading branch information
vikash authored Jan 19, 2025
2 parents 29a647b + 838a8d7 commit bc88e7e
Show file tree
Hide file tree
Showing 27 changed files with 594 additions and 593 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ Testing is a crucial aspect of software development, and adherence to these guid
- Prefix unit test functions with `Test`.
- Use clear and descriptive names.
```go
func TestFunctionName(t *testing.T) {
// Test logic
func TestFunctionName(t *testing.T) {
// Test logic
}
```

Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ package main
import "gofr.dev/pkg/gofr"

func main() {
app := gofr.New()
app := gofr.New()

app.GET("/greet", func(ctx *gofr.Context) (interface{}, error) {
return "Hello World!", nil
})
app.GET("/greet", func(ctx *gofr.Context) (interface{}, error) {
return "Hello World!", nil
})

app.Run() // listens and serves on localhost:8000
app.Run() // listens and serves on localhost:8000
}
```

Expand Down
4 changes: 2 additions & 2 deletions docs/advanced-guide/circuit-breaker/page.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ func main() {

app.AddHTTPService("order", "https://order-func",
&service.CircuitBreakerConfig{
// Number of consecutive failed requests after which circuit breaker will be enabled
// Number of consecutive failed requests after which circuit breaker will be enabled
Threshold: 4,
// Time interval at which circuit breaker will hit the aliveness endpoint.
Interval: 1 * time.Second,
Interval: 1 * time.Second,
},
)

Expand Down
10 changes: 5 additions & 5 deletions docs/advanced-guide/custom-spans-in-tracing/page.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ and returns a trace.Span.

```go
func MyHandler(c context.Context) error {
span := c.Trace("my-custom-span")
defer span.Close()
// Do some work here
return nil
span := c.Trace("my-custom-span")
defer span.Close()

// Do some work here
return nil
}
```

Expand Down
2 changes: 1 addition & 1 deletion docs/advanced-guide/gofr-errors/page.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ automatically handle HTTP status code selection. These include:
#### Usage:
To use the predefined HTTP errors, users can simply call them using GoFr's http package:
```go
err := http.ErrorMissingParam{Param: []string{"id"}}
err := http.ErrorMissingParam{Param: []string{"id"}}
```

## Database Errors
Expand Down
99 changes: 52 additions & 47 deletions docs/advanced-guide/grpc/page.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,33 @@ GoFr enables you to create gRPC handlers efficiently while leveraging GoFr's con
**1. Protocol Buffer Compiler (`protoc`) Installation:**

- **Linux (using `apt` or `apt-get`):**

```bash
sudo apt install -y protobuf-compiler
protoc --version # Ensure compiler version is 3+
```
sudo apt install -y protobuf-compiler
protoc --version # Ensure compiler version is 3+
```

- **macOS (using Homebrew):**

```bash
brew install protobuf
protoc --version # Ensure compiler version is 3+
brew install protobuf
protoc --version # Ensure compiler version is 3+
```

**2. Go Plugins for Protocol Compiler:**

a. Install protocol compiler plugins for Go:

```bash
go install google.golang.org/protobuf/cmd/[email protected]
go install google.golang.org/grpc/cmd/[email protected]
```
```bash
go install google.golang.org/protobuf/cmd/[email protected]
go install google.golang.org/grpc/cmd/[email protected]
```

b. Update `PATH` for `protoc` to locate the plugins:

```bash
export PATH="$PATH:$(go env GOPATH)/bin"
```
```bash
export PATH="$PATH:$(go env GOPATH)/bin"
```

## Creating Protocol Buffers

Expand All @@ -44,16 +45,16 @@ For a detailed guide, refer to the official gRPC documentation's tutorial: {% ne

Create a `.proto` file (e.g., `customer.proto`) to define your service and the RPC methods it provides:

```protobuf
// Indicates the protocol buffer version that is being used
syntax = "proto3";
// Indicates the go package where the generated file will be produced
option go_package = "path/to/your/proto/file";
```protobuf
// Indicates the protocol buffer version that is being used
syntax = "proto3";
// Indicates the go package where the generated file will be produced
option go_package = "path/to/your/proto/file";
service {serviceName}Service {
rpc {serviceMethod} ({serviceRequest}) returns ({serviceResponse}) {}
}
```
service {serviceName}Service {
rpc {serviceMethod} ({serviceRequest}) returns ({serviceResponse}) {}
}
```

**2. Specify Request and Response Types:**

Expand All @@ -79,30 +80,32 @@ string address = 3;

Run the following command to generate Go code using the Go gRPC plugins:

```bash
protoc \
--go_out=. \
--go_opt=paths=source_relative \
--go-grpc_out=. \
--go-grpc_opt=paths=source_relative \
{serviceName}.proto
```
```bash
protoc \
--go_out=. \
--go_opt=paths=source_relative \
--go-grpc_out=. \
--go-grpc_opt=paths=source_relative \
{serviceName}.proto
```

This command generates two files, `{serviceName}.pb.go` and `{serviceName}_grpc.pb.go`, containing the necessary code for performing RPC calls.

## Generating gRPC Handler Template using `gofr wrap grpc`
## Generating gRPC Handler Template using `gofr wrap grpc`

#### Prerequisite: gofr-cli must be installed

To install the CLI -

```bash
go install gofr.dev/cli/gofr@latest
go install gofr.dev/cli/gofr@latest
```

**1. Use the `gofr wrap grpc` Command:**
```bash
gofr wrap grpc -proto=./path/your/proto/file
```

```bash
gofr wrap grpc -proto=./path/your/proto/file
```

This command leverages the `gofr-cli` to generate a `{serviceName}_server.go` file (e.g., `CustomerServer.go`)
containing a template for your gRPC server implementation, including context support, in the same directory as
Expand All @@ -119,24 +122,26 @@ that of the specified proto file.

**1. Import Necessary Packages:**

```go
import (
"gofr.dev/pkg/gofr"
"path/to/your/generated-grpc-server/packageName"
)
```
```go
import (
"path/to/your/generated-grpc-server/packageName"

"gofr.dev/pkg/gofr"
)
```

**2. Register the Service in your `main.go`:**

```go
func main() {
app := gofr.New()
```go
func main() {
app := gofr.New()

packageName.Register{serviceName}ServerWithGofr(app, &packageName.{serviceName}GoFrServer{})

packageName.Register{serviceName}ServerWithGofr(app, &packageName.{serviceName}GoFrServer{})
app.Run()
}
```

app.Run()
}
```
>Note: By default, gRPC server will run on port 9000, to customize the port users can set `GRPC_PORT` config in the .env
> ##### Check out the example of setting up a gRPC server in GoFr: [Visit GitHub](https://github.com/gofr-dev/gofr/blob/main/examples/grpc-server/main.go)
74 changes: 36 additions & 38 deletions docs/advanced-guide/handling-data-migrations/page.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ package migrations

import "gofr.dev/pkg/gofr/migration"


const createTable = `CREATE TABLE IF NOT EXISTS employee
(
id int not null
Expand Down Expand Up @@ -89,7 +88,6 @@ func main() {
// Run the application
a.Run()
}

```

When we run the app we will see the following logs for migrations which ran successfully.
Expand Down Expand Up @@ -171,7 +169,7 @@ When using batch operations, consider using a `LoggedBatch` for atomicity or an
package migrations

import (
"gofr.dev/pkg/gofr/migration"
"gofr.dev/pkg/gofr/migration"
)

const (
Expand All @@ -181,52 +179,52 @@ const (
gender text,
number text
);`

addCassandraRecords = `BEGIN BATCH
INSERT INTO employee (id, name, gender, number) VALUES (1, 'Alison', 'F', '1234567980');
INSERT INTO employee (id, name, gender, number) VALUES (2, 'Alice', 'F', '9876543210');
APPLY BATCH;
`

employeeDataCassandra = `INSERT INTO employee (id, name, gender, number) VALUES (?, ?, ?, ?);`
)

func createTableEmployeeCassandra() migration.Migrate {
return migration.Migrate{
UP: func(d migration.Datasource) error {
// Execute the create table statement
if err := d.Cassandra.Exec(createTableCassandra); err != nil {
return err
}

// Batch processes can also be executed in Exec as follows:
return migration.Migrate{
UP: func(d migration.Datasource) error {
// Execute the create table statement
if err := d.Cassandra.Exec(createTableCassandra); err != nil {
return err
}

// Batch processes can also be executed in Exec as follows:
if err := d.Cassandra.Exec(addCassandraRecords); err != nil {
return err
}

// Create a new batch operation
batchName := "employeeBatch"
if err := d.Cassandra.NewBatch(batchName, 0); err != nil { // 0 for LoggedBatch
return err
}

// Add multiple queries to the batch
if err := d.Cassandra.BatchQuery(batchName, employeeDataCassandra, 1, "Harry", "M", "1234567980"); err != nil {
return err
}

if err := d.Cassandra.BatchQuery(batchName, employeeDataCassandra, 2, "John", "M", "9876543210"); err != nil {
return err
}

// Execute the batch operation
if err := d.Cassandra.ExecuteBatch(batchName); err != nil {
return err
}

return nil
},
}
}

// Create a new batch operation
batchName := "employeeBatch"
if err := d.Cassandra.NewBatch(batchName, 0); err != nil { // 0 for LoggedBatch
return err
}

// Add multiple queries to the batch
if err := d.Cassandra.BatchQuery(batchName, employeeDataCassandra, 1, "Harry", "M", "1234567980"); err != nil {
return err
}

if err := d.Cassandra.BatchQuery(batchName, employeeDataCassandra, 2, "John", "M", "9876543210"); err != nil {
return err
}

// Execute the batch operation
if err := d.Cassandra.ExecuteBatch(batchName); err != nil {
return err
}

return nil
},
}
}
```

Expand Down
Loading

0 comments on commit bc88e7e

Please sign in to comment.