Skip to content

Commit

Permalink
Merge branch 'main' into use-go-redis-session
Browse files Browse the repository at this point in the history
  • Loading branch information
mstmdev authored Nov 8, 2023
2 parents f4db5bb + 920b40a commit e86f44d
Show file tree
Hide file tree
Showing 160 changed files with 1,752 additions and 3,819 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Docker

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:

build:
strategy:
matrix:
os: [ 'ubuntu-latest' ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4

- name: Build Docker
run: chmod +x ./scripts/build-docker.sh && ./scripts/build-docker.sh

- name: Test Print Version
run: chmod +x ./scripts/docker-example/run-gofs-docker-print-version.sh && ./scripts/docker-example/run-gofs-docker-print-version.sh

- name: Test Checksum
run: chmod +x ./scripts/docker-example/run-gofs-docker-checksum.sh && ./scripts/docker-example/run-gofs-docker-checksum.sh
15 changes: 6 additions & 9 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,21 @@ jobs:
build:
strategy:
matrix:
go: [ '1.20','1.21' ]
go: [ '1.20', '1.21' ]
os: [ 'ubuntu-latest', 'windows-latest', 'macos-latest' ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go }}

- name: Init Env
run: chmod +x ./scripts/init-env.sh && ./scripts/init-env.sh
if: matrix.os != 'windows-latest'

- name: Build
run: go build -v ./...

Expand All @@ -34,9 +38,6 @@ jobs:
- name: Test Encrypt
run: go test -v -race -tags=encrypt_test ./encrypt

- name: Test HttpUtil
run: go test -v -race -tags=httputil_test ./util/httputil

- name: Test Integration
run: go test -v -race -tags=integration_test ./integration

Expand All @@ -61,8 +62,4 @@ jobs:

- name: Codecov
uses: codecov/codecov-action@v3
if: matrix.os == 'ubuntu-latest'

- name: Test Release
run: chmod +x ./scripts/build-release.sh && ./scripts/build-release.sh
if: matrix.os == 'ubuntu-latest'
29 changes: 29 additions & 0 deletions .github/workflows/govulncheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: Govulncheck

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:

build:
strategy:
matrix:
go: [ 'stable' ]
os: [ 'ubuntu-latest' ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go }}

- name: Scan Vulnerabilities
run: chmod +x ./scripts/govulncheck.sh && ./scripts/govulncheck.sh
29 changes: 29 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: Release

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:

build:
strategy:
matrix:
go: [ 'stable' ]
os: [ 'ubuntu-latest' ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go }}

- name: Test Release
run: chmod +x ./scripts/build-release.sh && ./scripts/build-release.sh
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ARG CGO_ENABLED=0

COPY . .

RUN echo $(git rev-parse main) >internal/version/commit
RUN echo $(git rev-parse HEAD) >internal/version/commit

RUN go build -v -o . ./...

Expand Down
30 changes: 29 additions & 1 deletion README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -661,4 +661,32 @@ $ gofs -about
### Web UI

[gofs-webui](https://github.com/no-src/gofs-webui)`gofs`的Web用户界面工具,它允许你通过Web用户界面来生成`gofs`
的配置文件,让使用`gofs`变得更加简单
的配置文件,让使用`gofs`变得更加简单

## 贡献

### 如何参与贡献

```mermaid
%%{init: { "flowchart": {"htmlLabels": false}} }%%
flowchart TD
PR[pull request]
MainRepo[github.com/no-src/gofs.git] -- 1.fork --> ForkRepo[github.com/yourname/gofs.git]
ForkRepo -- 2.git clone --> LocalRepo[local repository]
LocalRepo -- 3.commit changes --> NewBranch[new branch]
NewBranch -- 4.git push --> ForkRepo
ForkRepo -- 5.create pull request --> PR
PR -- 6.merge to --> MainRepo
```

### 云开发环境

利用云开发环境快速参与贡献

#### Github Codespaces

[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/no-src/gofs)

#### Gitpod

[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/no-src/gofs)
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -691,4 +691,32 @@ $ gofs -about
### Web UI

The [gofs-webui](https://github.com/no-src/gofs-webui) is a web UI tool for `gofs`, and it allows you to generate the
config file of `gofs` through the web UI, making the use of gofs easier.
config file of `gofs` through the web UI, making the use of gofs easier.

## Contributing

### How To Contribute

```mermaid
%%{init: { "flowchart": {"htmlLabels": false}} }%%
flowchart TD
PR[pull request]
MainRepo[github.com/no-src/gofs.git] -- 1.fork --> ForkRepo[github.com/yourname/gofs.git]
ForkRepo -- 2.git clone --> LocalRepo[local repository]
LocalRepo -- 3.commit changes --> NewBranch[new branch]
NewBranch -- 4.git push --> ForkRepo
ForkRepo -- 5.create pull request --> PR
PR -- 6.merge to --> MainRepo
```

### Cloud Development Environments

Quick to contribute using cloud development environments.

#### Github Codespaces

[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/no-src/gofs)

#### Gitpod

[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/no-src/gofs)
12 changes: 6 additions & 6 deletions api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import (
"github.com/no-src/gofs/api/task"
"github.com/no-src/gofs/auth"
"github.com/no-src/gofs/conf"
"github.com/no-src/gofs/logger"
"github.com/no-src/gofs/report"
"github.com/no-src/log"
)

const (
certFile = "../util/httputil/testdata/cert.pem"
keyFile = "../util/httputil/testdata/key.pem"
certFile = "../integration/testdata/cert/cert.pem"
keyFile = "../integration/testdata/cert/key.pem"
serverAddr = "https://127.0.0.1"
apiServerHost = "127.0.0.1"
apiServerPort = 8128
Expand Down Expand Up @@ -55,7 +55,7 @@ func runApiServer(t *testing.T, user *auth.User) (apiserver.Server, error) {
if user != nil {
users = append(users, user)
}
srv, err := apiserver.New(apiServerHost, apiServerPort, true, certFile, keyFile, tokenSecret, users, report.NewReporter(), serverAddr, log.DefaultLogger(), taskConfFile)
srv, err := apiserver.New(apiServerHost, apiServerPort, true, certFile, keyFile, tokenSecret, users, report.NewReporter(), serverAddr, logger.NewTestLogger(), taskConfFile)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -131,10 +131,10 @@ func runApiClient(user *auth.User) (err error) {
if err != nil {
return err
}
if i == 0 && (!c.SyncOnce || c.Source.Path() != "source" || c.Dest.Path() != "dest") {
if i == 0 && (!c.SyncOnce || c.Source.Path().Base() != "source" || c.Dest.Path().Base() != "dest") {
return errors.New("unexpect arguments")
}
if i == 1 && (c.SyncOnce || c.Source.Path() != "source" || c.Dest.Path() != "dest") {
if i == 1 && (c.SyncOnce || c.Source.Path().Base() != "source" || c.Dest.Path().Base() != "dest") {
return errors.New("unexpect arguments")
}
}
Expand Down
6 changes: 3 additions & 3 deletions api/apiserver/grpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"github.com/no-src/gofs/api/task"
"github.com/no-src/gofs/auth"
"github.com/no-src/gofs/internal/clist"
"github.com/no-src/gofs/logger"
"github.com/no-src/gofs/report"
"github.com/no-src/log"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
Expand All @@ -32,12 +32,12 @@ type grpcServer struct {
server *grpc.Server
monitors *sync.Map
monitorMessages *clist.CList
logger log.Logger
logger *logger.Logger
taskConf string
}

// New create the instance of the Server
func New(ip string, port int, enableTLS bool, certFile string, keyFile string, tokenSecret string, users []*auth.User, reporter report.Reporter, httpServerAddr string, logger log.Logger, taskConf string) (Server, error) {
func New(ip string, port int, enableTLS bool, certFile string, keyFile string, tokenSecret string, users []*auth.User, reporter report.Reporter, httpServerAddr string, logger *logger.Logger, taskConf string) (Server, error) {
if len(users) == 0 {
logger.Warn("the grpc server allows anonymous access, you should set some server users by the -users or -rand_user_count flag for security reasons")
users = append(users, auth.GetAnonymousUser())
Expand Down
2 changes: 1 addition & 1 deletion api/auth/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"time"

"github.com/no-src/gofs/auth"
"github.com/no-src/gofs/util/jsonutil"
"github.com/no-src/nsgo/jsonutil"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"
Expand Down
2 changes: 1 addition & 1 deletion api/monitor/hash_value.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package monitor

import "github.com/no-src/gofs/util/hashutil"
import "github.com/no-src/nsgo/hashutil"

// ToHashValueMessageList convert the hashutil.HashValues to a HashValue array
func ToHashValueMessageList(hvs hashutil.HashValues) []*HashValue {
Expand Down
2 changes: 1 addition & 1 deletion auth/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"strings"

"github.com/no-src/gofs/util/randutil"
"github.com/no-src/nsgo/randutil"
)

// User a login user info
Expand Down
14 changes: 7 additions & 7 deletions checksum/checksum.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
package checksum

import (
"github.com/no-src/gofs/util/hashutil"
"github.com/no-src/gofs/util/jsonutil"
"github.com/no-src/log"
"github.com/no-src/gofs/logger"
"github.com/no-src/nsgo/hashutil"
"github.com/no-src/nsgo/jsonutil"
)

// PrintChecksum calculate and print the checksum for file
func PrintChecksum(path string, chunkSize int64, checkpointCount int, algorithm string) error {
func PrintChecksum(path string, chunkSize int64, checkpointCount int, algorithm string, logger *logger.Logger) error {
hash, err := hashutil.NewHash(algorithm)
if err != nil {
log.Error(err, "init hash component error")
logger.Error(err, "init hash component error")
return err
}
hvs, err := hash.CheckpointsHashFromFileName(path, chunkSize, checkpointCount)
if err != nil {
log.Error(err, "calculate file checksum error")
logger.Error(err, "calculate file checksum error")
return err
}

hvsJson, _ := jsonutil.MarshalIndent(hvs)
log.Log(string(hvsJson))
logger.Log(string(hvsJson))
return err
}
15 changes: 11 additions & 4 deletions checksum/checksum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,35 @@ package checksum
import (
"testing"

"github.com/no-src/gofs/util/hashutil"
"github.com/no-src/gofs/logger"
"github.com/no-src/nsgo/hashutil"
)

func TestPrintChecksum(t *testing.T) {
logger := logger.NewTestLogger()
defer logger.Close()
path := "./checksum_test.go"
err := PrintChecksum(path, 1024*1024, 10, hashutil.DefaultHash)
err := PrintChecksum(path, 1024*1024, 10, hashutil.DefaultHash, logger)
if err != nil {
t.Errorf("test PrintChecksum error => %v", err)
}
}

func TestPrintChecksum_ReturnError(t *testing.T) {
logger := logger.NewTestLogger()
defer logger.Close()
path := "./"
err := PrintChecksum(path, 1024*1024, 10, hashutil.DefaultHash)
err := PrintChecksum(path, 1024*1024, 10, hashutil.DefaultHash, logger)
if err == nil {
t.Errorf("test PrintChecksum expect to get an error but get nil")
}
}

func TestPrintChecksum_InvalidAlgorithm(t *testing.T) {
logger := logger.NewTestLogger()
defer logger.Close()
path := "./checksum_test.go"
err := PrintChecksum(path, 1024*1024, 10, "")
err := PrintChecksum(path, 1024*1024, 10, "", logger)
if err == nil {
t.Errorf("test PrintChecksum expect to get an error but get nil")
}
Expand Down
Loading

0 comments on commit e86f44d

Please sign in to comment.