Skip to content
/ cos Public

A cos disk for filesystem module of Goravel

License

Notifications You must be signed in to change notification settings

goravel/cos

Repository files navigation

COS

A COS disk driver for facades.Storage() of Goravel.

Version

goravel/cos goravel/framework
v1.2.* v1.14.*
v1.1.* v1.13.*
v1.0.* v1.12.*

Install

  1. Add package
go get -u github.com/goravel/cos
  1. Register service provider
// config/app.go
import "github.com/goravel/cos"

"providers": []foundation.ServiceProvider{
    ...
    &cos.ServiceProvider{},
}
  1. Add cos disk to config/filesystems.go file
// config/filesystems.go
import (
    "github.com/goravel/framework/contracts/filesystem"
    cosfacades "github.com/goravel/cos/facades"
)

"disks": map[string]any{
    ...
    "cos": map[string]any{
        "driver": "custom",
        "key":    config.Env("TENCENT_ACCESS_KEY_ID"),
        "secret": config.Env("TENCENT_ACCESS_KEY_SECRET"),
        "url":    config.Env("TENCENT_URL"),
        "via": func() (filesystem.Driver, error) {
            return cosfacades.Cos("cos"), nil // The `cos` value is the `disks` key
        },
    },
}

Testing

Run command below to run test(fill your owner cos configuration):

TENCENT_ACCESS_KEY_ID= TENCENT_ACCESS_KEY_SECRET= TENCENT_BUCKET= TENCENT_URL= go test ./...