Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Test

permissions:
contents: read

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

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
- uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4
with:
path: |
~/go/pkg/mod
~/go/bin
~/.cache
key: livekit-storage

- name: Set up Go
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
with:
go-version-file: "go.mod"

- name: Set up gotestfmt
run: go install github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@9eae5abc81d6d08f73268741ef4a8b97f29b60d8 # v2.4.1

- name: Download Go modules
run: go mod download

- name: Lint
uses: golangci/golangci-lint-action@1e7e51e771db61008b38414a730f564565cf7c20 # v9.2.0
with:
version: v2.11.4

- name: Test
run: |
set -euo pipefail
go test -race -json -v ./... 2>&1 | gotestfmt
16 changes: 16 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: "2"
linters:
default: none
enable:
- staticcheck
settings:
staticcheck:
checks:
- "all"
- "-ST1000"
- "-ST1003"
- "-ST1020"
- "-ST1021"
- "-ST1022"
- "-SA1019"
- "-QF1008"
44 changes: 22 additions & 22 deletions azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,31 +49,27 @@ func NewAzure(conf *AzureConfig) (Storage, error) {
},
})

sUrl := fmt.Sprintf("https://%s.blob.core.windows.net", conf.AccountName)
serviceUrl, err := url.Parse(sUrl)
if err != nil {
return nil, err
}

cUrl := path.Join(sUrl, conf.ContainerName)
containerUrl, err := url.Parse(cUrl)
if err != nil {
return nil, err
}

host := fmt.Sprintf("%s.blob.core.windows.net", conf.AccountName)
return &azureBLOBStorage{
conf: conf,
serviceUrl: azblob.NewServiceURL(*serviceUrl, pipeline),
containerUrl: azblob.NewContainerURL(*containerUrl, pipeline),
conf: conf,
serviceUrl: azblob.NewServiceURL(url.URL{
Scheme: "https",
Host: host,
}, pipeline),
containerUrl: azblob.NewContainerURL(url.URL{
Scheme: "https",
Host: host,
Path: conf.ContainerName,
}, pipeline),
}, nil
}

func (s *azureBLOBStorage) location(storagePath string) *url.URL {
return &url.URL{
func (s *azureBLOBStorage) location(storagePath string) string {
return (&url.URL{
Scheme: "https",
Host: s.conf.AccountName + ".blob.core.windows.net",
Path: path.Join(s.conf.ContainerName, storagePath),
}
}).String()
}

func (s *azureBLOBStorage) UploadData(data []byte, storagePath, contentType string) (string, int64, error) {
Expand All @@ -87,7 +83,7 @@ func (s *azureBLOBStorage) UploadData(data []byte, storagePath, contentType stri
return "", 0, err
}

return s.location(storagePath).String(), int64(len(data)), nil
return s.location(storagePath), int64(len(data)), nil
}

func (s *azureBLOBStorage) UploadFile(filepath, storagePath, contentType string) (string, int64, error) {
Expand Down Expand Up @@ -116,7 +112,7 @@ func (s *azureBLOBStorage) UploadFile(filepath, storagePath, contentType string)
return "", 0, err
}

return s.location(storagePath).String(), stat.Size(), nil
return s.location(storagePath), stat.Size(), nil
}

func (s *azureBLOBStorage) ListObjects(prefix string) ([]string, error) {
Expand Down Expand Up @@ -216,8 +212,12 @@ func (s *azureBLOBStorage) GeneratePresignedUrl(storagePath string, expiration t
return "", err
}

loc := s.location(storagePath)
loc.RawQuery = qp.Encode()
loc := &url.URL{
Scheme: "https",
Host: s.conf.AccountName + ".blob.core.windows.net",
Path: path.Join(s.conf.ContainerName, storagePath),
RawQuery: qp.Encode(),
}
return loc.String(), nil
}

Expand Down
11 changes: 9 additions & 2 deletions gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,15 @@ func (s *gcpStorage) upload(reader io.Reader, storagePath, contentType string) (
return "", 0, err
}

loc := url.URL{Scheme: "https", Host: s.conf.Bucket + ".storage.googleapis.com", Path: storagePath}
return loc.String(), n, nil
return s.location(storagePath), n, nil
}

func (s *gcpStorage) location(storagePath string) string {
return (&url.URL{
Scheme: "https",
Host: s.conf.Bucket + ".storage.googleapis.com",
Path: storagePath,
}).String()
}

func (s *gcpStorage) ListObjects(prefix string) ([]string, error) {
Expand Down
8 changes: 6 additions & 2 deletions local.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func NewLocal(conf *LocalConfig) (Storage, error) {
}

func (u *localUploader) UploadFile(localPath, storagePath string, _ string) (string, int64, error) {
storagePath = path.Join(u.StorageDir, storagePath)
storagePath = u.location(storagePath)

local, err := os.Open(localPath)
if err != nil {
Expand Down Expand Up @@ -69,7 +69,7 @@ func (u *localUploader) UploadFile(localPath, storagePath string, _ string) (str
}

func (u *localUploader) UploadData(data []byte, storagePath, _ string) (string, int64, error) {
storagePath = path.Join(u.StorageDir, storagePath)
storagePath = u.location(storagePath)

if dir, _ := path.Split(storagePath); dir != "" {
if err := os.MkdirAll(dir, 0755); err != nil {
Expand All @@ -91,6 +91,10 @@ func (u *localUploader) UploadData(data []byte, storagePath, _ string) (string,
return storagePath, int64(size), nil
}

func (u *localUploader) location(storagePath string) string {
return path.Join(u.StorageDir, storagePath)
}

func (u *localUploader) ListObjects(prefix string) ([]string, error) {
absPrefix := path.Join(u.StorageDir, prefix)
dir, filenamePrefix := path.Split(absPrefix)
Expand Down
Loading
Loading