Skip to content

Commit 8c79d6a

Browse files
committed
fix lint issue
1 parent bca08c2 commit 8c79d6a

File tree

3 files changed

+86
-62
lines changed

3 files changed

+86
-62
lines changed

CONTRIBUTING.md

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
## Contribution Guidelines
2-
* Minor changes can be done directly by editing code on GitHub. GitHub automatically creates a temporary branch and
2+
3+
- Minor changes can be done directly by editing code on GitHub. GitHub automatically creates a temporary branch and
34
files a PR. This is only suitable for really small changes like: spelling fixes, variable name changes or error string
45
change etc. For larger commits, following steps are recommended.
5-
* (Optional) If you want to discuss your implementation with the users of GoFr, use the GitHub discussions of this repo.
6-
* Configure your editor to use goimport and golangci-lint on file changes. Any code which is not formatted using these
6+
- (Optional) If you want to discuss your implementation with the users of GoFr, use the GitHub discussions of this repo.
7+
- Configure your editor to use goimport and golangci-lint on file changes. Any code which is not formatted using these
78
tools, will fail on the pipeline.
8-
* Contributors should begin working on an issue only after it has been assigned to them. To get an issue assigned, please comment on the GitHub thread
9+
- Contributors should begin working on an issue only after it has been assigned to them. To get an issue assigned, please comment on the GitHub thread
910
and request assignment from a maintainer. This helps avoid duplicate or conflicting pull requests from multiple contributors.
10-
* Issues labeled triage are not open for direct contributions. If you're interested in working on a triage issue, please reach out to the maintainers
11-
to discuss it before proceeding in the Github thread.
11+
- Issues labeled triage are not open for direct contributions. If you're interested in working on a triage issue, please reach out to the maintainers
12+
to discuss it before proceeding in the Github thread.
1213
<!-- spellchecker:off "favour" have to be ignored here -->
13-
* We follow **American English** conventions in this project (e.g., *"favor"* instead of *"favour"*). Please keep this consistent across all code comments, documentation, etc.
14+
- We follow **American English** conventions in this project (e.g., _"favor"_ instead of _"favour"_). Please keep this consistent across all code comments, documentation, etc.
1415
<!-- spellchecker:on -->
15-
* All code contributions should have associated tests and all new line additions should be covered in those testcases.
16+
- All code contributions should have associated tests and all new line additions should be covered in those testcases.
1617
No PR should ever decrease the overall code coverage.
17-
* Once your code changes are done along with the testcases, submit a PR to development branch. Please note that all PRs
18+
- Once your code changes are done along with the testcases, submit a PR to development branch. Please note that all PRs
1819
are merged from feature branches to development first.
20+
1921
* 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.
2022
* All PRs need to be reviewed by at least 2 GoFr developers. They might reach out to you for any clarification.
2123
* Thank you for your contribution. :)
@@ -28,32 +30,28 @@ Testing is a crucial aspect of software development, and adherence to these guid
2830

2931
1. **Test Types:**
3032

31-
- Write unit tests for every new function or method.
32-
- Include integration tests for any major feature added.
33-
34-
35-
2. **Test Coverage:**
36-
37-
- No new code should decrease the existing code coverage for the packages and files.
38-
> The `code-climate` coverage check will not pass if there is any decrease in the test-coverage before and after any new PR is submitted.
33+
- Write unit tests for every new function or method.
34+
- Include integration tests for any major feature added.
3935

36+
2. **Test Coverage:**
4037

38+
- No new code should decrease the existing code coverage for the packages and files.
39+
> The `code-climate` coverage check will not pass if there is any decrease in the test-coverage before and after any new PR is submitted.
4140
4241
3. **Naming Conventions:**
4342

44-
- Prefix unit test functions with `Test`.
45-
- Use clear and descriptive names.
43+
- Prefix unit test functions with `Test`.
44+
- Use clear and descriptive names.
45+
4646
```go
4747
func TestFunctionName(t *testing.T) {
4848
// Test logic
4949
}
5050
```
5151

52-
53-
5452
4. **Table-Driven Tests:**
5553

56-
- Consider using table-driven tests for testing multiple scenarios.
54+
- Consider using table-driven tests for testing multiple scenarios.
5755

5856
> [!NOTE]
5957
> Some services will be required to pass the entire test suite. We recommend using docker for running those services.
@@ -96,46 +94,48 @@ docker run -d --name arangodb \
9694
-e ARANGO_ROOT_PASSWORD=rootpassword \
9795
--pull always \
9896
arangodb:latest
97+
docker run -it --rm -p 4443:4443 -e STORAGE_EMULATOR_HOST=0.0.0.0:4443 fsouza/fake-gcs-server:latest
9998
```
10099

101100
> [!NOTE]
102101
> Please note that the recommended local port for the services are different from the actual ports. This is done to avoid conflict with the local installation on developer machines. This method also allows a developer to work on multiple projects which uses the same services but bound on different ports. One can choose to change the port for these services. Just remember to add the same in configs/.local.env, if you decide to do that.
103102
104-
105103
### Coding Guidelines
106-
* Use only what is given to you as part of function parameter or receiver. No globals. Inject all dependencies including
104+
105+
- Use only what is given to you as part of function parameter or receiver. No globals. Inject all dependencies including
107106
DB, Logger etc.
108-
* No magic. So, no init. In a large project, it becomes difficult to track which package is doing what at the
107+
- No magic. So, no init. In a large project, it becomes difficult to track which package is doing what at the
109108
initialization step.
110-
* Exported functions must have an associated godoc.
111-
* Sensitive data(username, password, keys) should not be pushed. Always use environment variables.
112-
* Take interfaces and return concrete types.
113-
- Lean interfaces - take 'exactly' what you need, not more. Onus of interface definition is on the package who is
114-
using it. so, it should be as lean as possible. This makes it easier to test.
115-
- Be careful of type assertions in this context. If you take an interface and type assert to a type - then it's
116-
similar to taking concrete type.
117-
* Uses of context:
118-
- We should use context as a first parameter.
119-
- Can not use string as a key for the context. Define your own type and provide context accessor method to avoid
120-
conflict.
121-
* External Library uses:
122-
- A little copying is better than a little dependency.
123-
- All external dependencies should go through the same careful consideration, we would have done to our own written
124-
code. We need to test the functionality we are going to use from an external library, as sometimes library
125-
implementation may change.
126-
- All dependencies must be abstracted as an interface. This will make it easier to switch libraries at later point
127-
of time.
128-
* Version tagging as per Semantic versioning (https://semver.org/)
109+
- Exported functions must have an associated godoc.
110+
- Sensitive data(username, password, keys) should not be pushed. Always use environment variables.
111+
- Take interfaces and return concrete types.
112+
- Lean interfaces - take 'exactly' what you need, not more. Onus of interface definition is on the package who is
113+
using it. so, it should be as lean as possible. This makes it easier to test.
114+
- Be careful of type assertions in this context. If you take an interface and type assert to a type - then it's
115+
similar to taking concrete type.
116+
- Uses of context:
117+
- We should use context as a first parameter.
118+
- Can not use string as a key for the context. Define your own type and provide context accessor method to avoid
119+
conflict.
120+
- External Library uses:
121+
- A little copying is better than a little dependency.
122+
- All external dependencies should go through the same careful consideration, we would have done to our own written
123+
code. We need to test the functionality we are going to use from an external library, as sometimes library
124+
implementation may change.
125+
- All dependencies must be abstracted as an interface. This will make it easier to switch libraries at later point
126+
of time.
127+
- Version tagging as per Semantic versioning (https://semver.org/)
129128

130129
### Documentation
131-
* After adding or modifying existing code, update the documentation too - [development/docs](https://github.com/gofr-dev/gofr/tree/development/docs).
132-
* When you consider a new documentation page is needed, start by adding a new file and writing your new documentation. Then - add a reference to it in [navigation.js](https://gofr.dev/docs/navigation.js).
133-
* If needed, update or add proper code examples for your changes.
134-
* In case images are needed, add it to [docs/public](./docs/public) folder.
135-
* Make sure you don't break existing links and references.
136-
* Maintain Markdown standards, you can read more [here](https://www.markdownguide.org/basic-syntax/), this includes:
137-
- Headings (`#`, `##`, etc.) should be placed in order.
138-
- Use trailing white space or the <br> HTML tag at the end of the line.
139-
- Use "`" sign to add single line code and "```" to add multi-line code block.
140-
- Use relative references to images (in `public` folder as mentioned above.)
141-
* The [gofr.dev documentation](https://gofr.dev/docs) site is updated upon push to `/docs` path in the repo. Verify your changes are live after next GoFr version.
130+
131+
- After adding or modifying existing code, update the documentation too - [development/docs](https://github.com/gofr-dev/gofr/tree/development/docs).
132+
- When you consider a new documentation page is needed, start by adding a new file and writing your new documentation. Then - add a reference to it in [navigation.js](https://gofr.dev/docs/navigation.js).
133+
- If needed, update or add proper code examples for your changes.
134+
- In case images are needed, add it to [docs/public](./docs/public) folder.
135+
- Make sure you don't break existing links and references.
136+
- Maintain Markdown standards, you can read more [here](https://www.markdownguide.org/basic-syntax/), this includes:
137+
- Headings (`#`, `##`, etc.) should be placed in order.
138+
- Use trailing white space or the <br> HTML tag at the end of the line.
139+
- Use "`" sign to add single line code and "```" to add multi-line code block.
140+
- Use relative references to images (in `public` folder as mentioned above.)
141+
- The [gofr.dev documentation](https://gofr.dev/docs) site is updated upon push to `/docs` path in the repo. Verify your changes are live after next GoFr version.

pkg/gofr/datasource/file/gcs/fs.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type FileSystem struct {
2828

2929
// Config represents the gcs configuration.
3030
type Config struct {
31+
EndPoint string
3132
BucketName string
3233
CredentialsJSON string
3334
ProjectID string
@@ -54,7 +55,30 @@ func (f *FileSystem) Connect() {
5455

5556
ctx := context.TODO()
5657

57-
client, err := storage.NewClient(ctx, option.WithCredentialsJSON([]byte(f.config.CredentialsJSON)))
58+
var client *storage.Client
59+
60+
var err error
61+
62+
switch {
63+
case f.config.EndPoint != "":
64+
// Local emulator mode
65+
client, err = storage.NewClient(
66+
ctx,
67+
option.WithEndpoint(f.config.EndPoint),
68+
option.WithoutAuthentication(),
69+
)
70+
71+
case f.config.CredentialsJSON != "":
72+
// Direct JSON mode
73+
client, err = storage.NewClient(
74+
ctx,
75+
option.WithCredentialsJSON([]byte(f.config.CredentialsJSON)),
76+
)
77+
78+
default:
79+
// Env var mode (GOOGLE_APPLICATION_CREDENTIALS)
80+
client, err = storage.NewClient(ctx)
81+
}
5882

5983
if err != nil {
6084
f.logger.Errorf("Failed to connect to GCS: %v", err)

pkg/gofr/datasource/file/gcs/fs_dir.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ func (f *FileSystem) Mkdir(name string, _ os.FileMode) error {
7373
return err
7474
}
7575

76-
func (f *FileSystem) MkdirAll(path string, perm os.FileMode) error {
77-
cleaned := strings.Trim(path, "/")
76+
func (f *FileSystem) MkdirAll(dirPath string, perm os.FileMode) error {
77+
cleaned := strings.Trim(dirPath, "/")
7878
if cleaned == "" {
7979
return nil
8080
}
@@ -108,7 +108,7 @@ func isAlreadyExistsError(err error) bool {
108108
return strings.Contains(err.Error(), "already exists")
109109
}
110110

111-
func (f *FileSystem) RemoveAll(path string) error {
111+
func (f *FileSystem) RemoveAll(dirPath string) error {
112112
var msg string
113113

114114
st := statusErr
@@ -121,7 +121,7 @@ func (f *FileSystem) RemoveAll(path string) error {
121121
}, time.Now())
122122

123123
ctx := context.TODO()
124-
objects, err := f.conn.ListObjects(ctx, path)
124+
objects, err := f.conn.ListObjects(ctx, dirPath)
125125

126126
if err != nil {
127127
msg = fmt.Sprintf("Error retrieving objects: %v", err)
@@ -137,9 +137,9 @@ func (f *FileSystem) RemoveAll(path string) error {
137137

138138
st = statusSuccess
139139

140-
msg = fmt.Sprintf("Directory with path %q, deleted successfully", path)
140+
msg = fmt.Sprintf("Directory with path %q, deleted successfully", dirPath)
141141

142-
f.logger.Logf("Directory %s deleted.", path)
142+
f.logger.Logf("Directory %s deleted.", dirPath)
143143

144144
return nil
145145
}

0 commit comments

Comments
 (0)