Git Product home page Git Product logo

storage's Introduction

title description sidebar_position
๐Ÿ‘‹ Welcome
๐Ÿ“ฆ Premade storage drivers for ๐Ÿš€ Fiber.
1

Fiber Fiber

Premade storage drivers that implement the Storage interface, designed to be used with various Fiber middlewares.

// Storage interface for communicating with different database/key-value
// providers. Visit https://github.com/gofiber/storage for more info.
type Storage interface {
	// Get gets the value for the given key.
	// `nil, nil` is returned when the key does not exist
	Get(key string) ([]byte, error)

	// Set stores the given value for the given key along
	// with an expiration value, 0 means no expiration.
	// Empty key or value will be ignored without an error.
	Set(key string, val []byte, exp time.Duration) error

	// Delete deletes the value for the given key.
	// It returns no error if the storage does not contain the key,
	Delete(key string) error

	// Reset resets the storage and delete all keys.
	Reset() error

	// Close closes the storage and will stop any running garbage
	// collectors and open connections.
	Close() error
}

๐Ÿ“‘ Storage Implementations

storage's People

Contributors

1k-off avatar berkantay avatar chris-basson-grundling avatar chris-grundling-vaimo avatar codemicro avatar cr1cr1 avatar dependabot[bot] avatar dgivney avatar efectn avatar erkanzsy avatar fenny avatar foraeons avatar gaby avatar gandaldf avatar hi019 avatar iredmail avatar jictyvoo avatar kalissaac avatar kiyonlin avatar leonklingele avatar mstgnz avatar mstryoda avatar r-52 avatar rbo13 avatar renewerner87 avatar sixcolors avatar technerder avatar tmiddlet2666 avatar wlun001 avatar yashkumarverma avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

storage's Issues

[Question] about mongo db storage key index

hello, while examining mongodb storage, I noticed that it is querying with the key field, but this field is not indexed.

Is this just something that was overlooked? Or is it not needed?

Thanks.

[badger] - Add support to newer badger versions (2.0 or above)

Badger in version 1.6 has some errors under Windows WSL (Linux Subsystem).

So, when trying to running badger on WSL, a panic message is given:

panic: Mmap value log file. Path=./database/fiber.badger/000000.vlog. Error=exec format error

This error, has been fixed in newer versions of badger (2.0 and above), but new versions has no data compability with badger 1.6 versions.

To test this to make sure is a WSL compatibility problem, I run my code in a docker for production, and it has no problems

๐Ÿค— [Question]: Panic when using Redis with TLS endpoint

Question Description

I have an existing remote redis connection on a upstash account, but when I tried to create a new redis connection with the same connection string I get

panic: EOF

My code looks like this:

	storage := redis.New(redis.Config{
		URL:     "redis://xxx:[email protected]:12345",
		Reset:    false,
	})

when I switch to using only redis.New() on localhost it seems to work properly. Does this package only run on localhost?

(I also tried to comment out my other redis connection but the above error still exits.)

Thanks a lot!

Code Snippet (optional)

No response

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my questions prior to opening this one.
  • I understand that improperly formatted questions may be closed without explanation.

๐Ÿค— [Question]: what is the way ot use mysql connection in handler function

Question Description

Hi guys,
I may be wrong, please help me to understand !

In the docs there are example code of how we can setup a mysql connection but i can't find any docs of how should i use those connection in the handler function.

Although i find this text "Premade storage drivers that implement the Storage interface, designed to be used with various Fiber middlewares."

So is it only to used in middleware ? If i can use those in middleware then why not in handler as i understand middleware is nothing but stack of handler function.

Thanks

Code Snippet (optional)

No response

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my questions prior to opening this one.
  • I understand that improperly formatted questions may be closed without explanation.

[postgres] Panic after first database ping

Description: Panic occurs when creating a db for sessions - it occurs when trying to ping the db.

// Ping database
if err := db.Ping(); err != nil {
panic(err)
}

Error: panic: pq: database "fiber" does not exist

Example

package main

import (
	"github.com/gofiber/fiber/v2/middleware/session"
	"github.com/gofiber/storage/postgres"
)

var GlobalSessionStore *session.Store

func NewSession() {
	// Initialize default config
	store := postgres.New()
	GlobalSessionStore = session.New(session.Config{Storage: store})
}

func main() {
	NewSession()
}

cannot import memory v2 package

I've tried importing the github.com/gofiber/storage/memory/v2, but I'm encountering an error the message below.

$ go get github.com/gofiber/storage/memory/v2
   [STDOUT]
    go: module github.com/gofiber/storage/memory@upgrade found (v1.3.4), but does not contain package github.com/gofiber/storage/memory/v2

My Golang version is go version go1.20.2

Am I doing something wrong?

go get github.com/gofiber/storage/memory/v2

Consider tagging submodule?

I found that package github.com/gofiber/storage/redis is placed in submodule github.com/gofiber/storage/redis instead of root module.

However, it seems that submodule github.com/gofiber/storage/redis is not tagged. According to Go Modules wiki, submodule should be tagged like relative-path-to-root/vX.X.X.
At now, when trying to import package github.com/gofiber/storage/redis, downstream would depends on pseudo-version of module github.com/gofiber/storage/redis.

github.com/gofiber/storage/redis v0.0.0-20220523092334-6d96fb56afb5

I think it is not very readable and difficult to upgrade. This is not conductive to version control either.
So, I propose whether it is possible to tag submodule properly. For example, redis/v0.0.1, redis/v1.3.3etc, so that other project can use tag to import this module in go.mod.

[Improvement]: ๐Ÿš€๐Ÿ“’ Sync documentation with our docs repository

Currently in fiber we have a mechanism that synchronizes the documentation into the docs repository.
https://github.com/gofiber/fiber/blob/master/.github/workflows/sync-docs.yml ->
https://github.com/gofiber/fiber/tree/master/docs ->
https://github.com/gofiber/docs

The idea is to have a similar process that provides further versioned documentation for the other packages and extends the documentation page, besides the core documentation with the documentation about these packages.
https://github.com/gofiber/storage ->
https://docusaurus.io/docs/next/docs-multi-instance#versioned-and-unversioned-doc

After that we can link the usages from the core
https://docs.gofiber.io/search?q=storages&version=next%2F

This will also make them more present and more enhancements, bugfixes or similar improvements can be expected

[Bug] Database password not URL-encoded

Characters such as # and % in my password cause issues. url.QueryEscape-ing my password solves this issue. I don't find this expected behavior because I am not providing a ConnectionURI. When entering a password, I do not expect to be in an environment where I need to manually URL-encode my data.

๐Ÿ› [Bug]: redis: client is closed error

Bug Description

I am using RedisStore in my application and this error comes from nowhere. On my pc when i try to get some key from Redis "redis: client is closed" comes sometimes. But on the server its always disconnected.

// Redis Client
var RedisStore = redis.New()

// When accessing redis
var redis = database.RedisStore.Conn()
var state = redis.Get(ctx, fmt.Sprintf("state.user.%d", user.ID))
if state.Err() != nil {}

How to Reproduce

Steps to reproduce the behavior:

  1. Create new RedisStore
  2. Try to access some key from store

Expected Behavior

It gives the value from store without error

Storage package Version

v1.3.4

Code Snippet (optional)

package database

import "github.com/gofiber/storage/redis"

var RedisStore = redis.New()

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my problem prior to opening this one.
  • I understand that improperly formatted bug reports may be closed without explanation.

๐Ÿš€ [Feature]: Add benchmarks for storage drivers

Feature Description

We have to add benchmarks to check performance changes in PRs and commits. Otherwise we won't have an information about performance issues.

Additional Context (optional)

No response

Code Snippet (optional)

package main

import "github.com/gofiber/storage/%package%"

func main() {
  // Steps to reproduce
}

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my suggestion prior to opening this one.
  • I understand that improperly formatted feature requests may be closed without explanation.

๐Ÿ› memcache utils.Trim undefined latest release

Using go.mod with:

github.com/gofiber/fiber/v2 v2.38.1
github.com/gofiber/storage/memcache v0.0.0-20221005114327-4e6f1c95ff26

When trying to run I get

# github.com/gofiber/storage/memcache
../go/pkg/mod/github.com/gofiber/storage/[email protected]/memcache.go:24:36: undefined: utils.Trim

if I change memcache.go line 23 from serverList := strings.Split(utils.Trim(cfg.Servers, ' '), ",") to serverList := strings.Split(strings.Trim(cfg.Servers, " "), ",") it works.

@efectn mentioned utils.Trim was used for performance on older go versions. It seems that this is broken with the latest goofier release when using go 1.19 in my package however.

Redis cache always miss?

I'm running a simple webserver and trying to setup redis based cache for it -- as in-memory one would fail in prod use-cases.

This is the attachment of the middleware

// using redis to cache HTTP requests
	redisStoage := fiber_redis.New(fiber_redis.Config{
		Host: "localhost",
		Port: 6379,
	})

	app.Use(cache.New(cache.Config{
		Expiration: 15 * time.Second,
		Storage:    redisStoage,
		Methods:    []string{fiber.MethodGet, fiber.MethodHead, fiber.MethodPost},
	}))
  • has the cache always miss

I was initially trying to use the connection URL based method

// using redis to cache HTTP requests
	redisStoage := fiber_redis.New(fiber_redis.Config{
		URL: config.REDIS_CLUSTER_URL,
		Reset:    false,
	})
	app.Use(cache.New(cache.Config{
		Expiration: 15 * time.Second,
		Storage:    redisStoage,
		Methods:    []string{fiber.MethodGet, fiber.MethodHead, fiber.MethodPost},
	}))

I am confident that

  • redis is working -- as other caching methods are working
  • the connection string is working -- as app cache layer uses the same

session fails when the server restarts or shuts down

When I create a new session, it writes it to the database, but it gives me an error when I want to use the same session when the server is shut down or restarted.

//custom config for session
var store = session.New(session.Config{
	Expiration:   24 * time.Hour,
	CookieName:   "session_id",
	KeyGenerator: func() string {
		return "makrube"
	},
	Storage: postgres.New(postgres.Config{
		Host:       "localhost",
		Port:       5432,
		Username:   "postgres",
		Password:   "123",
		Database:   "blog",
		Table:      "fiber_storage",
		GCInterval: 10 * time.Hour,
	}),
})

login control and session area

func LogControl(c *fiber.Ctx) error {
	var request models.RequestBody
	var temp models.User

	err := c.BodyParser(&request)
	if err != nil {
		fmt.Println(err)
	}
	err = database.DB().Where("mail = ? and password = ?", request.Email, request.Password).First(&temp).Error
	if err != nil {
		return c.SendStatus(fiber.StatusUnauthorized)
	}

	sess, err := store.Get(c)
	if err != nil {
		fmt.Println(err)
	}
	defer sess.Save()

	fmt.Println(sess)
	sess.Set("temp", temp.Fullname)
	name := sess.Get("temp")
	sess.Get("temp")



	return c.SendString(fmt.Sprintf("Welcome %v", name))
}

There is no problem so far.
Session database is written and session is used until the machine is shut down.

Whenever I shut down the machine, the code explodes even though the database has sessionID.

[session] Register this type first with the `RegisterType` method.
panic: reflect: New(nil)

goroutine 66 [running]:
reflect.New(0x0, 0x0, 0x16, 0x16fb1c0, 0xc0002cd120)
	C:/Go/src/reflect/value.go:2382 +0xc9
github.com/gofiber/fiber/v2/internal/gotiny.buildDecEngine.func7(0xc0000a1220, 0xc0002cd120)
	C:/Users/omer/go/pkg/mod/github.com/gofiber/fiber/[email protected]/internal/gotiny/decEngine.go:188 +0x289
github.com/gofiber/fiber/v2/internal/gotiny.buildDecEngine.func4(0xc0000a1220, 0xc00008b798)
	C:/Users/omer/go/pkg/mod/github.com/gofiber/fiber/[email protected]/internal/gotiny/decEngine.go:154 +0x25c
github.com/gofiber/fiber/v2/internal/gotiny.buildDecEngine.func6(0xc0000a1220, 0xc00008b780)
	C:/Users/omer/go/pkg/mod/github.com/gofiber/fiber/[email protected]/internal/gotiny/decEngine.go:172 +0x55
github.com/gofiber/fiber/v2/internal/gotiny.buildDecEngine.func1(0xc0000a1220, 0xc000446f88)
	C:/Users/omer/go/pkg/mod/github.com/gofiber/fiber/[email protected]/internal/gotiny/decEngine.go:100 +0xa8
github.com/gofiber/fiber/v2/internal/gotiny.(*Decoder).Decode(0xc0000a1220, 0xc000098ee0, 0x19, 0x20, 0xc00045f828, 0x1, 0x1, 0xc00009b6a8)
	C:/Users/omer/go/pkg/mod/github.com/gofiber/fiber/[email protected]/internal/gotiny/decoder.go:75 +0x98
github.com/gofiber/fiber/v2/internal/gotiny.Unmarshal(0xc000098ee0, 0x19, 0x20, 0xc00045f828, 0x1, 0x1, 0x0)
	C:/Users/omer/go/pkg/mod/github.com/gofiber/fiber/[email protected]/internal/gotiny/decoder.go:19 +0x94
github.com/gofiber/fiber/v2/middleware/session.(*Store).Get(0xc0002b6fc0, 0xc00012e000, 0xc000224000, 0x0, 0x0)
	C:/Users/omer/go/pkg/mod/github.com/gofiber/fiber/[email protected]/middleware/session/store.go:62 +0x20b
github.com/omerfruk/my-blog/handlers.LogControl(0xc00012e000, 0x0, 0x0)
	C:/Go/src/github.com/omerfruk/my-blog/handlers/researcher.go:124 +0x25a
github.com/gofiber/fiber/v2.(*App).next(0xc00029fcc0, 0xc00012e000, 0xc00009b0b0, 0x1, 0x8)
	C:/Users/omer/go/pkg/mod/github.com/gofiber/fiber/[email protected]/router.go:126 +0x1c2
github.com/gofiber/fiber/v2.(*Ctx).Next(0xc00012e000, 0x17c29a9, 0x1b)
	C:/Users/omer/go/pkg/mod/github.com/gofiber/fiber/[email protected]/ctx.go:637 +0x92
github.com/gofiber/fiber/v2/middleware/cors.New.func1(0xc00012e000, 0xc00009b098, 0x6)
	C:/Users/omer/go/pkg/mod/github.com/gofiber/fiber/[email protected]/middleware/cors/cors.go:141 +0x325
github.com/gofiber/fiber/v2.(*App).next(0xc00029fcc0, 0xc00012e000, 0xc00012e000, 0xf, 0x10)
	C:/Users/omer/go/pkg/mod/github.com/gofiber/fiber/[email protected]/router.go:126 +0x1c2
github.com/gofiber/fiber/v2.(*App).handler(0xc00029fcc0, 0xc0002a6000)
	C:/Users/omer/go/pkg/mod/github.com/gofiber/fiber/[email protected]/router.go:154 +0x125
github.com/valyala/fasthttp.(*Server).serveConn(0xc0003a0240, 0x1899220, 0xc00050e1b0, 0x0, 0x0)
	C:/Users/omer/go/pkg/mod/github.com/valyala/[email protected]/server.go:2193 +0x128c
github.com/valyala/fasthttp.(*workerPool).workerFunc(0xc000246d20, 0xc0002d0060)
	C:/Users/omer/go/pkg/mod/github.com/valyala/[email protected]/workerpool.go:223 +0xcd
github.com/valyala/fasthttp.(*workerPool).getCh.func1(0xc000246d20, 0xc0002d0060, 0x16cbea0, 0xc0002d0060)
	C:/Users/omer/go/pkg/mod/github.com/valyala/[email protected]/workerpool.go:195 +0x3c
created by github.com/valyala/fasthttp.(*workerPool).getCh
	C:/Users/omer/go/pkg/mod/github.com/valyala/[email protected]/workerpool.go:194 +0x115

Process finished with exit code 2

๐Ÿ› [Bug]: Redis secure connection not working properly

Bug Description

When trying to connect to a rediss (redis secure) it fails.

I'm supposing that is a problem with the storage/redis, since go-redis is handling it here and returning options with tls, but storage/redis is not handling it as we can see it here, it's not setting the TLS config.

How to Reproduce

Steps to reproduce the behavior:

  1. Create a new redis storage
  2. Pass the URL as rediss (redis secure) protocol
  3. Try to use the store

Expected Behavior

Connection established with TLS.

Storage package Version

v2.0.3

Code Snippet (optional)

package main

import "fmt"

func main() {

	store = redis.New(redis.Config{
		URL: "rediss://<user>:<pass>@127.0.0.1:6379/<db>",
	})

	fmt.Println(store.Get(key))

}

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my problem prior to opening this one.
  • I understand that improperly formatted bug reports may be closed without explanation.

๐Ÿค— [feature]: Add support for Keys() to Redis and Memory drivers

Question Description

Is there a plan to extend this interface to support fetching all keys?

Code Snippet (optional)

package main

import "github.com/gofiber/storage/%package%"

func main() {
  // Steps to reproduce
}

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my questions prior to opening this one.
  • I understand that improperly formatted questions may be closed without explanation.

[Question] support for redis cluster client

the integration of the middleware for redis is assuming that i'm using a regular client, is it even possible to define a ClusterClient with a set of addresses? am i missing something?

EDIT:
nevermind, i made an interface adapter for the *redisClusterClient type,
maybe i will make a PR after some proper tests.

๐Ÿค— [Question]: Release schedule for SQLIte3?

Question Description

Hello! I was just wondering if the release process is automated for particular packages, or if there's somewhere I can watch? I noticed SQLite3 hasn't had a release in awhile, and so this commit isn't included: 3c0019a

It fixes a build-time bug I ran into, so I updated to v2@main, but just wanted to know how to watch for the official release!

Thanks so much,

NIck

Code Snippet (optional)

package main

import "github.com/gofiber/storage/%package%"

func main() {
  // Steps to reproduce
}

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my questions prior to opening this one.
  • I understand that improperly formatted questions may be closed without explanation.

[Question] Storing meta data to list all a users sessions

Hi, is it possible to store meta data such as the user id into a new column. I am looking to list all a users sessions when you are logged in to view and delete them. Other info might be useful for me such as ip or user agent but i can probably get that from the value column. However i try this, it requires changing the interface signature which is obviously a problem. Can it be done?

Thanks.

๐Ÿš€ [Feature]: Adding a deletion function with wildcard for the redis package

Feature Description

In the project I developed, there are multiple users, and we store users on the Redis side based on prefixes. And sometimes we need to delete the information we store in Redis.

You can think of an example key like this;
user:{user.guid}:info
user:{user.guid}:preferences
user:{user.guid}:addresses
etc.

I know that this can be done with redis.Keys() and redis.Del(), but it works quite slow in terms of performance. Therefore, I think it would be better to use a function like this based on the package I previously used in NodeJS.

E.g npm pkg:
https://github.com/galanonym/redis-delete-wildcard/blob/master/index.js

The example usage of the function I mentioned would be as follows:

count, err := redis.DelWild("user:6e7c5b62-1d4d-4f6e-bb6d-2e1a2c3d4e5f")
if err != nil {
   fmt.Print(err)
}

fmt.Sprintf("%d records were deleted.", count)

Additional Context (optional)

No response

Code Snippet (optional)

// for redis pkg

func (s *Storage) DelWild(key string) (int64, error) {
	if len(key) <= 0 {
		return 0, nil
	}

	res, err := s.db.Eval(ctx, `
		local keysToDelete = redis.call('keys', ARGV[1])
		if #keysToDelete > 0 then
			return redis.call('del', unpack(keysToDelete))
		else
			return 0
		end
	`, []string{key}).Result()

	if err != nil {
		return 0, err
	}

	return res.(int64), nil
}

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my suggestion prior to opening this one.
  • I understand that improperly formatted feature requests may be closed without explanation.

๐Ÿ› [Bug]: "redis: client is closed" error periodically

Bug Description

I am using RedisStore in my application and this error comes from nowhere. On my pc when i try to get some key from Redis "redis: client is closed" comes sometimes. But on the server its always disconnected.

// Redis Client
var RedisStore = redis.New()

// When accessing redis
var redis = database.RedisStore.Conn()
var state = redis.Get(ctx, fmt.Sprintf("state.user.%d", user.ID))
if state.Err() != nil {}

How to Reproduce

Steps to reproduce the behavior:

  1. Create new RedisStore
  2. Try to access some key from store

Expected Behavior

It gives the value from store without issue

Storage package Version

v1.3.4

Code Snippet (optional)

package database

import "github.com/gofiber/storage/redis"

var RedisStore = redis.New()

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my problem prior to opening this one.
  • I understand that improperly formatted bug reports may be closed without explanation.

๐Ÿค— [Question]: Can we add an option to database storages accept a already initialized connection?

Question Description

For example my app already opens a connection with redis and I'd like to reuse the same connection, since it's simple to create a health check endpoint that's only checks one redis connection instead of 2 or more.

Currently I'm opening 3 connections since my code opens 1 and I call redis.New twice, so I need to get the remaining connections using store.Conn and pass it as dependency to my health check controller to check all connections.

I'd like to know if it's possible to add an option to database driven storages like "Conn" that we can pass a already established connection. Something simillar to GORM/Existing database connection

Code Snippet (optional)

package main

import (
	"github.com/redis/go-redis/v9"

	fiberredis "github.com/gofiber/storage/redis"
)

func main() {
	url := "redis://localhost:6379?password=hello&protocol=3"
	opts, err := redis.ParseURL(url)
	if err != nil {
		panic(err)
	}
	rdb := redis.NewClient(opts) // Already connected

	store1 := fiberredis.New(redis.Config{URL: config.RedisURL + "/1"}) // New Conn
	store2 := fiberredis.New(redis.Config{URL: config.RedisURL + "/2"}) // New Conn

	// I'm thinking something like this:
        // Ref: https://github.com/redis/go-redis/issues/1018#issuecomment-517928987
	// db1 := rdb.Conn()
	// db1.Select(context.Background(), 1)
	// db2 := rdb.Conn()
	// db2.Select(context.Background(), 2)
	// store1 := fiberredis.New(redis.Config{Conn: db1})
	// store2 := fiberredis.New(redis.Config{Conn: db2})
}

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my questions prior to opening this one.
  • I understand that improperly formatted questions may be closed without explanation.

๐Ÿš€ [Feature]: s3: support setting with checksum

Feature Description

I understand current s3 implementation is designed for gofiber Storage interface, but it could be used as a s3 library too.

My question is, do you accept PR to add a new function alternative to Set() to accept checksum (e.g. sha256)? so that S3 server will verify the data integrity on server side.

Current Set() doesn't accept any checksum:

https://github.com/gofiber/storage/blob/main/s3/s3.go#L95C39-L99

The plan is adding new functions to accept checksum like below (since theses functions are not designed for Storage interface, i removed exp time.Duration):

SetWithChecksumCRC32(key string, val []byte, checksum string)
SetWithChecksumCRC32C(key string, val []byte, checksum string)
SetWithChecksumSHA1(key string, val []byte, checksum string)
SetWithChecksumSHA256(key string, val []byte, checksum string)

Or, one function to support all (checksum map[string]string, key is checksum algorithm like CRC32, SHA256, value is the checksum):

SetWithChecksum(key string, val []byte, checksum map[string]string)

Your opinion?

Additional Context (optional)

No response

Code Snippet (optional)

No response

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my suggestion prior to opening this one.
  • I understand that improperly formatted feature requests may be closed without explanation.

๐Ÿค— [Question]: Is there a concurrency safety issue in the Set method implementation of Minio Storage?

Question Description

Please take a look at the code below:

s.cfg.PutObjectOptions.ContentType = http.DetectContentType(val)

Are there any concurrency safety issues here?
Here is a more complete code snippet below.

Code Snippet (optional)

// Set key with value
func (s *Storage) Set(key string, val []byte, exp time.Duration) error {

	if len(key) <= 0 {
		return errors.New("the key value is required")
	}

	// create Reader
	file := bytes.NewReader(val)

	// set content type
        // Note: In general, the Storage object is a global singleton. Is there any issue with modifying its internal properties here? If multiple people concurrently upload files, will there be a problem of ContentType mix-up?
	s.cfg.PutObjectOptions.ContentType = http.DetectContentType(val)

	// put object
	_, err := s.minio.PutObject(s.ctx, s.cfg.Bucket, key, file, file.Size(), s.cfg.PutObjectOptions)

	return err
}

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my questions prior to opening this one.
  • I understand that improperly formatted questions may be closed without explanation.

๐Ÿค— [Question]: minio client upload file error

Question Description

I want to upload a multipart form data file into minio but the problem is that when i upload it i got net/http: HTTP/1.x transport connection broken: http: ContentLength=104130 with Body length 0 error. how can i resolve it? where's it's comming from?

i use github.com/minio/minio-go/v7 v7.0.63 & github.com/gofiber/storage/minio v0.1.0 drivers to connect to minio

Code Snippet (optional)

func UploadIdentityVideo(ctx *fiber.Ctx) error {
	form, err := ctx.MultipartForm()
	if err != nil {
		return err
	}

	file := form.File["file"][0]
	//if err != nil {
	//	return ctx.Status(422).JSON(models.GenericResponse{
	//		Result:  false,
	//		Message: "We were not able upload your attachment",
	//	})
	//}

	if file.Size > utils.MaxFileSize || file.Size < utils.MinFileSize {
		return ctx.Status(422).JSON(models.GenericResponse{
			Result:  false,
			Message: "File Size Error",
		})
	}

	src, err := file.Open()
	defer src.Close()
	if err != nil {
		return ctx.Status(500).JSON(models.GenericResponse{
			Result:  false,
			Message: err.Error(),
		})
	}

	format, err := utils.GetFileFormatFromFile(src)
	if err != nil {
		return ctx.Status(500).JSON(models.GenericResponse{
			Result:  false,
			Message: "Failed to read file format",
		})
	}

	if !utils.VideoAllowedFormats[file.Header.Get("Content-Type")] || !utils.VideoAllowedFormats[format] {
		return ctx.Status(400).JSON(models.GenericResponse{
			Result:  false,
			Message: "Video Format Not Allowed",
		})
	}

	user := ctx.Locals("user").(*jwt.Token)
	claims := user.Claims.(jwt.MapClaims)

	userId := claims["userId"]
	if userId == nil {
		return ctx.Status(412).JSON(models.GenericResponse{
			Result:  false,
			Message: "JWT ERROR",
		})
	}
	userIdString := strconv.FormatFloat(userId.(float64), 'f', 0, 64)

	fileId, err := utils.CreateFileID(src, userIdString)
	if err != nil {
		return ctx.Status(500).JSON(models.GenericResponse{
			Result:  false,
			Message: err.Error(),
		})
	}

	minioClient := ctx.Locals("minio").(*config.MinIOClients)
	filename := utils.CreateFileName(userIdString, hex.EncodeToString(fileId), utils.GetFileExtension(file.Filename))
	_, err = utils.UploadIntoMinIO(minioClient.VideoStorage.Conn(), filename, file.Size, src, config.VideoBucketName)
	if err != nil {
		return ctx.Status(500).JSON(models.GenericResponse{
			Result:  false,
			Message: err.Error(),
		})
	}

	return ctx.Status(200).JSON(models.UploadedResponse{
		Result: true,
		FileId: hex.EncodeToString(fileId),
	})
}


func UploadIntoMinIO(client *minio.Client, fileId string, fileSize int64, file multipart.File, bucket string) (minio.UploadInfo, error) {
	return client.PutObject(
		context.Background(),
		bucket,
		fileId,
		file,
		fileSize,
		minio.PutObjectOptions{},
	)
}

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my questions prior to opening this one.
  • I understand that improperly formatted questions may be closed without explanation.

๐Ÿš€ [Feature]: ClickHouse Implementation

Feature Description

I'd like to use Clickhouse as storage layer and having control over the table engine being used so I could store into different places effortless.

Additional Context (optional)

No response

Code Snippet (optional)

package main

import "github.com/gofiber/storage/clickhouse"

func main() {
  store := clickhouse.New(clickhouse.Config{
	Host:      "127.0.0.1",
	Port:      9000,
	Username:  "",
	Password:  "",
	Engine: clickhouse.Memory
  })
}

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my suggestion prior to opening this one.
  • I understand that improperly formatted feature requests may be closed without explanation.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.