mirror of
https://github.com/gofiber/storage.git
synced 2025-09-27 04:46:08 +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"
|
||||
"errors"
|
||||
"log"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/cockroachdb/pebble"
|
||||
"github.com/gofiber/storage/pebble/internal"
|
||||
)
|
||||
|
||||
type Storage struct {
|
||||
@@ -24,7 +24,7 @@ type CacheType struct {
|
||||
func New(config ...Config) *Storage {
|
||||
cfg := configDefault(config...)
|
||||
|
||||
if !internal.IsValid(cfg.Path) {
|
||||
if !isValid(cfg.Path) {
|
||||
panic(errors.New("invalid filepath"))
|
||||
}
|
||||
|
||||
@@ -117,3 +117,19 @@ func (s *Storage) Close() error {
|
||||
func (s *Storage) Conn() *pebble.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