Skip to content

Commit

Permalink
chore: format all Markdown files with mdsf
Browse files Browse the repository at this point in the history
mdsf is a tool that formats Markdown files with fenced code blocks.
https://github.com/hougesen/mdsf

It is used to ensure that all code blocks are formatted in a consistent way.
  • Loading branch information
ccoVeille committed Jan 18, 2025
1 parent 5c2080a commit fa30ecf
Show file tree
Hide file tree
Showing 26 changed files with 471 additions and 483 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
5 changes: 3 additions & 2 deletions docs/advanced-guide/grpc/page.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,14 @@ Run the following command to generate Go code using the Go gRPC plugins:

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:**
Expand Down
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
44 changes: 20 additions & 24 deletions docs/advanced-guide/handling-file/page.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ GoFr also supports FTP/SFTP file-store. Developers can also connect and use thei
package main

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

"gofr.dev/pkg/gofr/datasource/file/ftp"
"gofr.dev/pkg/gofr/datasource/file/ftp"
)

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

app.AddFileStore(ftp.New(&ftp.Config{
Host: "127.0.0.1",
Expand All @@ -28,8 +28,8 @@ func main() {
Port: 21,
RemoteDir: "/ftp/user",
}))
app.Run()

app.Run()
}
```

Expand All @@ -38,22 +38,22 @@ func main() {
package main

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

"gofr.dev/pkg/gofr/datasource/file/sftp"
"gofr.dev/pkg/gofr/datasource/file/sftp"
)

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

app.AddFileStore(sftp.New(&sftp.Config{
Host: "127.0.0.1",
User: "user",
Password: "password",
Port: 22,
Host: "127.0.0.1",
User: "user",
Password: "password",
Port: 22,
}))
app.Run()

app.Run()
}
```

Expand All @@ -67,16 +67,14 @@ To run S3 File-Store locally we can use localstack,
package main

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

"gofr.dev/pkg/gofr/datasource/file/s3"
"gofr.dev/pkg/gofr/datasource/file/s3"
)

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



app := gofr.New()

// Note that currently we do not handle connections through session token.
// BaseEndpoint is not necessary while connecting to AWS as it automatically resolves it on the basis of region.
// However, in case we are using any other AWS compatible service, such like running or testing locally, then this needs to be set.
Expand All @@ -88,8 +86,8 @@ func main() {
AccessKeyID: app.Config.Get("AWS_ACCESS_KEY_ID"),
SecretAccessKey: app.Config.Get("AWS_SECRET_ACCESS_KEY"),
}))
app.Run()

app.Run()
}
```
> Note: The current implementation supports handling only one bucket at a time,
Expand Down Expand Up @@ -202,7 +200,6 @@ _, err = csvFile.WriteAt([]byte("test content"), 4)
if err != nil {
return nil, err
}

```

### Getting Information of the file/directory
Expand All @@ -217,7 +214,6 @@ if entry.IsDir() {
}

fmt.Printf("%v: %v Size: %v Last Modified Time : %v\n" entryType, entry.Name(), entry.Size(), entry.ModTime())

```
>Note: In S3:
> - Names without a file extension are treated as directories by default.
Expand Down
30 changes: 15 additions & 15 deletions docs/advanced-guide/http-authentication/page.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ Use `EnableBasicAuth(username, password)` to configure GoFr with pre-defined cre
```go
func main() {
app := gofr.New()

app.EnableBasicAuth("admin", "secret_password") // Replace with your credentials

app.GET("/protected-resource", func(c *gofr.Context) (interface{}, error) {
// Handle protected resource access
// Handle protected resource access
return nil, nil
})

Expand All @@ -44,18 +44,18 @@ The `validationFunc` takes the username and password as arguments and returns tr

```go
func validateUser(c *container.Container, username, password string) bool {
// Implement your credential validation logic here
// This example uses hardcoded credentials for illustration only
return username == "john" && password == "doe123"
}
// Implement your credential validation logic here
// This example uses hardcoded credentials for illustration only
return username == "john" && password == "doe123"
}

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

app.EnableBasicAuthWithValidator(validateUser)
app.EnableBasicAuthWithValidator(validateUser)

app.GET("/secure-data", func(c *gofr.Context) (interface{}, error) {
// Handle access to secure data
app.GET("/secure-data", func(c *gofr.Context) (interface{}, error) {
// Handle access to secure data
return nil, nil
})

Expand Down Expand Up @@ -146,10 +146,10 @@ Use `EnableOAuth(jwks-endpoint,refresh_interval)` to configure GoFr with pre-def
func main() {
app := gofr.New()

app.EnableOAuth("http://jwks-endpoint", 20)
app.EnableOAuth("http://jwks-endpoint", 20)

app.GET("/protected-resource", func(c *gofr.Context) (interface{}, error) {
// Handle protected resource access
// Handle protected resource access
return nil, nil
})

Expand Down
Loading

0 comments on commit fa30ecf

Please sign in to comment.