Skip to content

Commit

Permalink
Merge pull request #1273 from gofr-dev/release/v1.28.1
Browse files Browse the repository at this point in the history
Release/v1.28.1
  • Loading branch information
Umang01-hash authored Dec 6, 2024
2 parents 4df66c5 + c6564ae commit f8639d4
Show file tree
Hide file tree
Showing 74 changed files with 2,668 additions and 2,648 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,7 @@ Help us make GoFr even better:
### 🎁 **Get a GoFr T-Shirt & Stickers!**

If your PR is merged, or if you contribute by writing articles or promoting GoFr, we invite you to fill out [this form](https://forms.gle/R1Yz7ZzY3U5WWTgy5) to claim your GoFr merchandise as a token of our appreciation!

### Partners

<img src="https://resources.jetbrains.com/storage/products/company/brand/logos/jetbrains.png" alt="JetBrains logo" width="200">
19 changes: 9 additions & 10 deletions docs/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ghcr.io/gofr-dev/website:latest
FROM ghcr.io/gofr-dev/website:latest AS builder

WORKDIR /app

Expand All @@ -9,20 +9,19 @@ COPY docs/references /app/src/app/docs/references
COPY docs/page.md /app/src/app/docs
COPY docs/navigation.js /app/src/lib


ENV NODE_ENV production

Check warning on line 12 in docs/Dockerfile

View workflow job for this annotation

GitHub Actions / 🔧Build

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/

Check warning on line 12 in docs/Dockerfile

View workflow job for this annotation

GitHub Actions / 🔧Build

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/

Check warning on line 12 in docs/Dockerfile

View workflow job for this annotation

GitHub Actions / 🐳 Dockerize

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/

RUN npm install
RUN npm run build

RUN addgroup -g 1001 -S nodejs
RUN adduser -S nextjs -u 1001

USER nextjs
# Stage 2: Serve with Static Server
FROM zopdev/static-server:v0.0.1

EXPOSE 3000
ENV PORT 3000
# Copy static files from the builder stage
COPY --from=builder /app/out website

ENV NEXT_TELEMETRY_DISABLED 1
# Expose the port server is running on
EXPOSE 8000

CMD ["node_modules/.bin/next", "start"]
# Start go server
CMD ["/main"]
55 changes: 52 additions & 3 deletions docs/advanced-guide/handling-file/page.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ GoFr simplifies the complexity of working with different file stores by offering

By default, local file-store is initialised and user can access it from the context.

GoFr also supports FTP/SFTP file-store. The file-store can be initialised as follows:
GoFr also supports FTP/SFTP file-store. Developers can also connect and use their AWS S3 bucket as a file-store. The file-store can be initialised as follows:

### FTP file-store
```go
Expand Down Expand Up @@ -57,6 +57,43 @@ func main() {
}
```

### AWS S3 Bucket as File-Store

To run S3 File-Store locally we can use localstack,
``docker run --rm -it -p 4566:4566 -p 4510-4559:4510-4559 localstack/localstack``


```go
package main

import (
"gofr.dev/pkg/gofr"

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

func main() {
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.
// Note that locally, AccessKeyID & SecretAccessKey is not checked if we use localstack.
app.AddFileStore(s3.New(&s3.Config{
EndPoint: "http://localhost:4566",
BucketName: "gofr-bucket-2",
Region: "us-east-1",
AccessKeyID: app.Config.Get("AWS_ACCESS_KEY_ID"),
SecretAccessKey: app.Config.Get("AWS_SECRET_ACCESS_KEY"),
}))

app.Run()
}
```
> Note: The current implementation supports handling only one bucket at a time,
> as shown in the example with `gofr-bucket-2`. Bucket switching mid-operation is not supported.
### Creating Directory

Expand Down Expand Up @@ -92,6 +129,8 @@ To switch to a subfolder of the current directory
```go
currentDir, err := ctx.File.Chdir("sub_dir")
```
> Note: This method attempts to change the directory, but S3's flat structure and fixed bucket
> make this operation inapplicable.
### Read a Directory

Expand All @@ -111,6 +150,8 @@ for _, entry := range entries {
fmt.Printf("%v: %v Size: %v Last Modified Time : %v\n" entryType, entry.Name(), entry.Size(), entry.ModTime())
}
```
> Note: In S3, directories are represented as prefixes of file keys. This method retrieves file
> entries only from the immediate level within the specified directory.
### Creating and Save a File with Content

Expand Down Expand Up @@ -178,6 +219,11 @@ 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.
> - Names starting with "0" are interpreted as binary files, with the "0" prefix removed.
>
> For directories, the method calculates the total size of all contained objects and returns the most recent modification time. For files, it directly returns the file's size and last modified time.
### Rename/Move a File

Expand All @@ -191,16 +237,19 @@ err := ctx.File.Rename("old_name.text", "new_name.text")

### Deleting Files

Remove deletes a single file
`Remove` deletes a single file
> Note: Currently, the S3 package supports the deletion of unversioned files from general-purpose buckets only. Directory buckets and versioned files are not supported for deletion by this method.
```go
err := ctx.File.Remove("my_dir")
```

The `RemoveAll` command deletes all subdirectories as well. If you delete the current working directory, such as "../currentDir", the working directory will be reset to its parent directory.
> Note: In S3, RemoveAll only supports deleting directories and will return an error if a file path (as indicated by a file extension) is provided.
```go
err := ctx.File.RemoveAll("my_dir/my_text")
```

> GoFr supports relative paths i.e. a location relative to the current working directory. The resolution of this path depends on the current directory from which the path is being referenced.
> GoFr supports relative paths, allowing locations to be referenced relative to the current working directory. However, since S3 uses
> a flat file structure, all methods require a full path relative to the S3 bucket.
> Errors have been skipped in the example to focus on the core logic, it is recommended to handle all the errors.
4 changes: 2 additions & 2 deletions docs/advanced-guide/injecting-databases-drivers/page.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ type Person struct {
func main() {
app := gofr.New()

db := mongo.New(Config{URI: "mongodb://localhost:27017", Database: "test",ConnectionTimeout: 4*time.Second})
db := mongo.New(mongo.Config{URI: "mongodb://localhost:27017", Database: "test",ConnectionTimeout: 4*time.Second})

// inject the mongo into gofr to use mongoDB across the application
// using gofr context
Expand Down Expand Up @@ -619,7 +619,7 @@ func main() {
app := gofr.New()

// Initialize OpenTSDB connection
app.AddOpenTSDB(opentsdb.New(&opentsdb.Config{
app.AddOpenTSDB(opentsdb.New(opentsdb.Config{
Host: "localhost:4242",
MaxContentLength: 4096,
MaxPutPointsNum: 1000,
Expand Down
5 changes: 5 additions & 0 deletions docs/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ export const navigation = [
title: 'WebSockets',
href: '/docs/advanced-guide/websocket',
desc: "Explore how gofr eases the process of WebSocket communication in your Golang application for real-time data exchange."
},
{
title: 'Serving-Static Files',
href: '/docs/advanced-guide/serving-static-files',
desc: "Know how GoFr automatically serves static content from a static folder in the application directory."
}
],
},
Expand Down
21 changes: 11 additions & 10 deletions docs/references/testing/page.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ import (
func TestAdd(t *testing.T) {
type gofrResponse struct {
result interface{}
err error
err error
}

// NewMockContainer provides mock implementations for various databases including:
Expand Down Expand Up @@ -122,9 +122,9 @@ func TestAdd(t *testing.T) {
requestBody: `{"title":"Book Title","isbn":12345}`,
mockExpect: func() {
mock.SQL.
EXPECT().
ExecContext(ctx, `INSERT INTO books (title, isbn) VALUES (?, ?)`, "Book Title", 12345).
Return(sqlmock.NewResult(12, 1), nil)
ExpectExec(`INSERT INTO books (title, isbn) VALUES (?, ?)`).
WithArgs("Book Title", 12345).
WillReturnResult(sqlmock.NewResult(12, 1))
},
expectedResponse: gofrResponse{
int64(12),
Expand All @@ -136,9 +136,9 @@ func TestAdd(t *testing.T) {
requestBody: `{"title":"Book Title","isbn":12345}`,
mockExpect: func() {
mock.SQL.
EXPECT().
ExecContext(ctx, `INSERT INTO books (title, isbn) VALUES (?, ?)`, "Book Title", 12345).
Return(nil, sql.ErrConnDone)
ExpectExec(`INSERT INTO books (title, isbn) VALUES (?, ?)`).
WithArgs("Book Title", 12345).
WillReturnError(sql.ErrConnDone)
},
expectedResponse: gofrResponse{
nil,
Expand All @@ -149,9 +149,9 @@ func TestAdd(t *testing.T) {
requestBody: `{"title":"Book Title","isbn":12345}`,
mockExpect: func() {
mock.SQL.
EXPECT().
ExecContext(ctx, `INSERT INTO books (title, isbn) VALUES (?, ?)`, "Book Title", 12345).
Return(sqlmock.NewErrorResult(errors.New("mocked result error")), nil)
ExpectExec(`INSERT INTO books (title, isbn) VALUES (?, ?)`).
WithArgs("Book Title", 12345).
WillReturnError(errors.New("mocked result error"))
},
expectedResponse: gofrResponse{
nil,
Expand Down Expand Up @@ -185,6 +185,7 @@ func TestAdd(t *testing.T) {
})
}
}

```
### Summary

Expand Down
100 changes: 0 additions & 100 deletions examples/http-server/go.mod

This file was deleted.

Loading

0 comments on commit f8639d4

Please sign in to comment.