Skip to content

Commit

Permalink
Merge pull request #1104 from gofr-dev/release/v1.24.0
Browse files Browse the repository at this point in the history
Release/v1.24.0
  • Loading branch information
aryanmehrotra authored Oct 14, 2024
2 parents 9b26f79 + 6d66081 commit 371c49a
Show file tree
Hide file tree
Showing 37 changed files with 6,436 additions and 131 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
No PR should ever decrease the overall code coverage.
* Once your code changes are done along with the testcases, submit a PR to development branch. Please note that all PRs
are merged from feature branches to development first.
* PR should be raised only when development is complete and the code is ready for review. This approach helps reduce the number of open pull requests and facilitates a more efficient review process for the team.
* All PRs need to be reviewed by at least 2 GoFr developers. They might reach out to you for any clarification.
* Thank you for your contribution. :)

Expand Down
4 changes: 2 additions & 2 deletions docs/advanced-guide/dealing-with-sql/page.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ DB_DIALECT=postgres
```

## Usage for SQLite
To connect with PostgreSQL, set `DB_DIALECT` to `sqlite` and `DB_NAME` to the name of your DB File. If the DB file already exists then it will be used otherwise a new one will be created.
To connect with SQLite, set `DB_DIALECT` to `sqlite` and `DB_NAME` to the name of your DB File. If the DB file already exists then it will be used otherwise a new one will be created.

```dotenv
DB_NAME=test.db
Expand All @@ -36,4 +36,4 @@ Add the following configs in `.env` file.
DB_MAX_IDLE_CONNECTION=5 // Default 2
DB_MAX_OPEN_CONNECTION=5 // Default unlimited
```
> ##### Check out the example on how to add configuration for SQL in GoFr: [Visit Github](https://github.com/gofr-dev/gofr/blob/main/examples/http-server/configs/.env)
> ##### Check out the example on how to add configuration for SQL in GoFr: [Visit Github](https://github.com/gofr-dev/gofr/blob/main/examples/http-server/configs/.env)
31 changes: 15 additions & 16 deletions docs/advanced-guide/injecting-databases-drivers/page.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,26 +172,25 @@ with Cassandra. Any driver implementation that adheres to this interface can be
suits your project's needs.

```go
type Cassandra interface {
Query(dest interface{}, stmt string, values ...any) error
type CassandraWithContext interface {
QueryWithCtx(ctx context.Context, dest any, stmt string, values ...any) error

Exec(stmt string, values ...any) error

ExecCAS(dest any, stmt string, values ...any) (bool, error)
ExecWithCtx(ctx context.Context, stmt string, values ...any) error

BatchQuery(stmt string, values ...any) error
ExecCASWithCtx(ctx context.Context, dest any, stmt string, values ...any) (bool, error)

NewBatch(name string, batchType int) error
NewBatchWithCtx(ctx context.Context, name string, batchType int) error

CassandraBatch
Cassandra
CassandraBatchWithContext
}

type CassandraBatch interface {
BatchQuery(name, stmt string, values ...any)
ExecuteBatch(name string) error
ExecuteBatchCAS(name string, dest ...any) (bool, error)
type CassandraBatchWithContext interface {
BatchQueryWithCtx(ctx context.Context, name, stmt string, values ...any) error

ExecuteBatchWithCtx(ctx context.Context, name string) error

ExecuteBatchCASWithCtx(ctx context.Context, name string, dest ...any) (bool, error)
}
```

Expand Down Expand Up @@ -239,7 +238,7 @@ func main() {
return nil, err
}

err = c.Cassandra.Exec(`INSERT INTO persons(id, name, age, location) VALUES(?, ?, ?, ?)`,
err = c.Cassandra.ExecWithCtx(c,`INSERT INTO persons(id, name, age, location) VALUES(?, ?, ?, ?)`,
person.ID, person.Name, person.Age, person.State)
if err != nil {
return nil, err
Expand All @@ -251,7 +250,7 @@ func main() {
app.GET("/user", func(c *gofr.Context) (interface{}, error) {
persons := make([]Person, 0)

err := c.Cassandra.Query(&persons, `SELECT id, name, age, location FROM persons`)
err := c.Cassandra.QueryWithCtx(c, &persons, `SELECT id, name, age, location FROM persons`)

return persons, err
})
Expand Down
15 changes: 8 additions & 7 deletions examples/http-server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
FROM golang:1.22
# Build stage
FROM golang:1.22 AS build

RUN mkdir /src/
WORKDIR /src/
WORKDIR /src
COPY . .
RUN go get ./...
RUN go build -ldflags "-linkmode external -extldflags -static" -a main.go
RUN go build -ldflags "-linkmode external -extldflags -static" -a -o /app/main main.go

FROM alpine:latest
# Final stage
FROM alpine:3.14
RUN apk add --no-cache tzdata ca-certificates
COPY --from=0 /src/main /main
COPY --from=0 /src/configs /configs
COPY --from=build /app/main /main
COPY --from=build /src/configs /configs
EXPOSE 9000

CMD ["/main"]
17 changes: 7 additions & 10 deletions examples/http-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@ This GoFr example demonstrates a simple HTTP server which supports Redis and MyS

### To run the example follow the steps below:

- Run the docker image of Redis
- Run the docker image of the application
```console
docker run --name gofr-redis -p 2002:6379 -d redis:7.0.5
docker-compose up -d
```

- Run the docker image of MySQL
```console
docker run --name gofr-mysql -e MYSQL_ROOT_PASSWORD=password -e MYSQL_DATABASE=test -p 2001:3306 -d mysql:8.0.30
```
To test the example, follow these steps:

1. Open your browser and navigate to `http://localhost:9000/hello`.
2. To view the trace Gofr trce, open `https://tracer.gofr.dev` and paste the traceid.
3. To view the Grafana Dashboard open `http://localhost:3000`

- Now run the example
```console
go run main.go
```
69 changes: 69 additions & 0 deletions examples/http-server/docker/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
version: '3.8'

services:
gofr-http-server:
build:
context: ../.
dockerfile: Dockerfile
environment:
- TRACE_EXPORTER=gofr
- TRACER_RATIO=0.1
- REDIS_HOST=redisdb
- REDIS_PORT=6379
- DB_HOST=mysqldb
- DB_USER=root
- DB_PASSWORD=password
- DB_NAME=test
- DB_PORT=3306
- DB_DIALECT=mysql
ports:
- "9000:9000"
- "2121:2121"
depends_on:
- redisdb
- mysqldb
- grafana
- prometheus
networks:
- gofr-network

redisdb:
image: redis:7.0.5
ports:
- "2002:6379"
networks:
- gofr-network

mysqldb:
image: mysql:8.0.30
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: test
ports:
- "2001:3306"
networks:
- gofr-network

grafana:
image: grafana/grafana:latest
ports:
- "3000:3000"
environment:
- GF_SECURITY_ADMIN_USER=admin
- GF_SECURITY_ADMIN_PASSWORD=password
volumes:
- ./provisioning:/etc/grafana/provisioning
networks:
- gofr-network

prometheus:
image: prom/prometheus:latest
ports:
- "9090:9090"
volumes:
- ./prometheus:/etc/prometheus
networks:
- gofr-network

networks:
gofr-network:
11 changes: 11 additions & 0 deletions examples/http-server/docker/prometheus/prometheus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).

scrape_configs:
- job_name: 'prometheus'
scrape_interval: 5s
metrics_path: '/metrics'
static_configs:
- targets: ['host.docker.internal:2121']
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: 1

providers:
- name: 'Gofr Dashboard'
orgId: 1
folder: ''
type: file
disableDeletion: false
updateIntervalSeconds: 10
options:
path: /etc/grafana/provisioning/dashboards/gofr-dashboard
Loading

0 comments on commit 371c49a

Please sign in to comment.