storage

package module
v1.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 23, 2024 License: MIT Imports: 30 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Storage

專案提供檔案存取library,支援google storage及本地檔案存取

Example

本地檔案存

func main() {
	hdstorage := storage.NewHdStorage("./test")
	key, err := hdstorage.Save("hello.txt", []byte("hello world"))
	fmt.Println(key, err)
}

gcp檔案存取

func main() {
	gcpConf := &storage.GcpConf{
		CredentialsFile: "./serviceAccountKey.json",
	}
	ctx := context.Background()
	ctx, cancel := context.WithTimeout(ctx, time.Second*10)
	defer cancel()
	sto, err := gcpConf.NewStorage(ctx, "private_in_volunteer")
	if err != nil {
		fmt.Println(err)
		return
	}
	path, err := sto.Save("product/hello.txt", []byte("hello world"))
	fmt.Println(path, err)

	list, err := sto.List("product/")
	fmt.Println(list, err)

	exist, err := sto.FileExist("product/hello.txt")
	fmt.Println(exist, err)

	exist, err = sto.FileExist("product/not_exist.txt")
	fmt.Println(exist, err)

	data, err := sto.Get("product/hello.txt")
	fmt.Println(string(data), err)

	err = sto.Delete("product/hello.txt")
	fmt.Println(err)

	fmt.Println(sto.GetDownloadUrl("product/hello.txt"))
}

container服務

README

Documentation

Index

Constants

View Source
const (
	PermPublic  = Perm("public")
	PermPrivate = Perm("private")
	PermTmp     = Perm("tmp")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config added in v1.2.0

type Config struct {
	ConfMapPath string `env:"GCP_CONF_MAP_PATH"`

	ModelDI

	ConfMap GcpConfigMap
	Log     log.Logger
}

func GetConfigFromEnv added in v1.2.0

func GetConfigFromEnv() (*Config, error)

func (*Config) Close added in v1.2.0

func (c *Config) Close() error

func (*Config) Copy added in v1.2.0

func (c *Config) Copy() cfg.ModelCfg

func (*Config) Init added in v1.2.0

func (c *Config) Init(uuid string, di di.DI) error

type DownloadUrl added in v1.2.0

type DownloadUrl struct {
	IsPublic    bool
	Url         string
	AccessToken *oauth2.Token
}

type GcpConf

type GcpConf struct {
	CredentialsFile string `yaml:"credentailsFile"`
	CredentailsUrl  string `yaml:"credentailsUrl"`
	Bucket          string `yaml:"bucket"`
}

func (*GcpConf) NewStorage

func (gcp *GcpConf) NewStorage(ctx context.Context) (GcpStorage, error)

type GcpConfigMap added in v1.1.0

type GcpConfigMap interface {
	GetConfig(key string) *GcpConf
}

func LoadGcpConfigMap added in v1.1.0

func LoadGcpConfigMap(file string) (GcpConfigMap, error)

type GcpDI

type GcpDI interface {
	NewStorage(ctx context.Context, bucket string) (GcpStorage, error)
}

type GcpStorage

type GcpStorage interface {
	Storage
	GetAttr(key string) (*googstorage.ObjectAttrs, error)
	GetDownloadUrl(key string) (myurl *DownloadUrl, err error)
	Write(key string, writeData func(w io.Writer) error) (path string, err error)
	OpenFile(key string) (io.Reader, error)
	SignedURL(key string, contentType string, expDuration time.Duration) (url string, err error)
	GetAccessToken() (*oauth2.Token, error)
}

type GrpcGcpStorage added in v1.1.0

type GrpcGcpStorage interface {
	GcpStorage
	Close()
}

func NewGrpcGcpStorage added in v1.1.0

func NewGrpcGcpStorage(ctx context.Context, address string, channel string) (GrpcGcpStorage, error)

type HdStorage added in v1.2.2

type HdStorage interface {
	Storage
	FullPath(key string) string
}

func NewHdStorage

func NewHdStorage(path string) HdStorage

type ModelDI added in v1.2.0

type ModelDI interface {
	log.LoggerDI
}

type Perm

type Perm string

type Storage

type Storage interface {
	Save(filePath string, file []byte) (string, error)
	SaveByReader(fp string, reader io.Reader) (string, error)
	Delete(filePath string) error
	Get(filePath string) ([]byte, error)
	FileExist(fp string) (bool, error)
	List(dir string) ([]string, error)
}

Directories

Path Synopsis
_example
gcp command
grpc command
hd command
grpc
pb

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL