1
0
Fork 0
mirror of https://github.com/vbatts/imgsrv.git synced 2024-11-27 02:25:41 +00:00

minio: WIP

This commit is contained in:
Vincent Batts 2019-03-12 16:08:25 -04:00
parent 7fac419675
commit 8fb892c5a9
2 changed files with 102 additions and 1 deletions

98
dbutil/minio/minio.go Normal file
View file

@ -0,0 +1,98 @@
package minio
import (
"encoding/json"
"fmt"
"github.com/hashicorp/errwrap"
"github.com/minio/minio-go"
"github.com/vbatts/imgsrv/dbutil"
"github.com/vbatts/imgsrv/types"
)
type minioConfig struct {
Endpoint string
AccessKeyID string
SecretAccessKey string
Secure bool
Region string
Bucket string
}
func init() {
dbutil.Handles["minio"] = &minioHandle{}
}
type minioHandle struct {
Config minioConfig
Client *minio.Client
}
func (mh *minioHandle) Init(config []byte, err error) error {
if err != nil {
return errwrap.Wrapf("minio Init: {{er}}", err)
}
mh.Config = minioConfig{}
if err := json.Unmarshal(config, &mh.Config); err != nil {
return err
}
mh.Client, err = minio.NewWithRegion(mh.Config.Endpoint, mh.Config.AccessKeyID, mh.Config.SecretAccessKey, mh.Config.Secure, mh.Config.Region)
if err != nil {
return errwrap.Wrapf("minio Client: {{er}}", err)
}
if buc, err := mh.Client.BucketExists(mh.Config.Bucket); err != nil || !buc {
return fmt.Errorf("can not access bucket %q", mh.Config.Bucket)
}
return nil
}
// ErrNotImplemented for functions as the stubs are being written
var ErrNotImplemented = fmt.Errorf("function not implemented")
func (mh *minioHandle) Close() error {
return nil
}
func (mh *minioHandle) Open(filename string) (dbutil.File, error) {
return nil, ErrNotImplemented
}
func (mh *minioHandle) Create(filename string) (dbutil.File, error) {
return nil, ErrNotImplemented
}
func (mh *minioHandle) Remove(filename string) error {
return mh.Client.RemoveObject(mh.Config.Bucket, filename)
}
func (mh *minioHandle) HasFileByFilename(filename string) (exists bool, err error) {
return false, ErrNotImplemented
}
func (mh *minioHandle) FindFilesByKeyword(keyword string) (files []types.File, err error) {
return nil, ErrNotImplemented
}
func (mh *minioHandle) FindFilesByMd5(md5 string) (files []types.File, err error) {
return nil, ErrNotImplemented
}
func (mh *minioHandle) FindFilesByPatt(filenamePat string) (files []types.File, err error) {
return nil, ErrNotImplemented
}
func (mh *minioHandle) CountFiles(filename string) (int, error) {
return -1, ErrNotImplemented
}
func (mh *minioHandle) GetFiles(limit int) (files []types.File, err error) {
return nil, ErrNotImplemented
}
func (mh *minioHandle) GetFileByFilename(filename string) (types.File, error) {
return types.File{}, ErrNotImplemented
}
func (mh *minioHandle) GetExtensions() (kp []types.IdCount, err error) {
return nil, ErrNotImplemented
}
func (mh *minioHandle) GetKeywords() (kp []types.IdCount, err error) {
return nil, ErrNotImplemented
}

View file

@ -16,6 +16,7 @@ import (
"github.com/vbatts/imgsrv/assets"
"github.com/vbatts/imgsrv/config"
"github.com/vbatts/imgsrv/dbutil"
_ "github.com/vbatts/imgsrv/dbutil/minio"
_ "github.com/vbatts/imgsrv/dbutil/mongo"
"github.com/vbatts/imgsrv/hash"
"github.com/vbatts/imgsrv/types"
@ -39,7 +40,8 @@ func runServer(c *config.Config) {
log.Fatalf("DbHandler %q not found", serverConfig.DbHandler)
}
if serverConfig.DbHandler == "mongo" {
switch {
case serverConfig.DbHandler == "mongo":
duConfig = struct {
Seed string
User string
@ -51,6 +53,7 @@ func runServer(c *config.Config) {
serverConfig.MongoPassword,
serverConfig.MongoDbName,
}
case serverConfig.DbHandler == "minio":
}
if err := du.Init(json.Marshal(duConfig)); err != nil {