mirror of
https://github.com/gofiber/storage.git
synced 2025-09-27 21:02:20 +08:00
change requests applied
This commit is contained in:
@@ -1,21 +0,0 @@
|
|||||||
package internal
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
)
|
|
||||||
|
|
||||||
func IsValid(fp string) bool {
|
|
||||||
// Check if file already exists
|
|
||||||
if _, err := os.Stat(fp); err == nil {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
// Attempt to create it
|
|
||||||
var d []byte
|
|
||||||
if err := os.WriteFile(fp, d, 0644); err == nil {
|
|
||||||
os.Remove(fp) // And delete it
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
@@ -4,10 +4,10 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/cockroachdb/pebble"
|
"github.com/cockroachdb/pebble"
|
||||||
"github.com/gofiber/storage/pebble/internal"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Storage struct {
|
type Storage struct {
|
||||||
@@ -24,7 +24,7 @@ type CacheType struct {
|
|||||||
func New(config ...Config) *Storage {
|
func New(config ...Config) *Storage {
|
||||||
cfg := configDefault(config...)
|
cfg := configDefault(config...)
|
||||||
|
|
||||||
if !internal.IsValid(cfg.Path) {
|
if !isValid(cfg.Path) {
|
||||||
panic(errors.New("invalid filepath"))
|
panic(errors.New("invalid filepath"))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,3 +117,19 @@ func (s *Storage) Close() error {
|
|||||||
func (s *Storage) Conn() *pebble.DB {
|
func (s *Storage) Conn() *pebble.DB {
|
||||||
return s.db
|
return s.db
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isValid(fp string) bool {
|
||||||
|
// Check if file already exists
|
||||||
|
if _, err := os.Stat(fp); err == nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Attempt to create it
|
||||||
|
var d []byte
|
||||||
|
if err := os.WriteFile(fp, d, 0644); err == nil {
|
||||||
|
os.Remove(fp) // And delete it
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user