Skip to content

Commit a174b7e

Browse files
committed
refactor: update NewLocalFileService to use unified LocalFileServiceConfig
- Introduce `LocalFileServiceConfig` struct to consolidate `RootDir` and `PublicBase` configurations. - Simplify `NewLocalFileService` by replacing individual parameters with a single configuration struct. - Adjust fileserver adapter initialization to align with the updated configuration structure. Signed-off-by: tbxark <tbxark@outlook.com>
1 parent ebf82d7 commit a174b7e

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

server/service/file/web.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,24 @@ func NewWebServer(engine httpx.Engine, storage *fileserver.FileServer) *Web {
2323
}
2424
}
2525

26+
type LocalFileServiceConfig struct {
27+
RootDir string `json:"root_dir" yaml:"root_dir"`
28+
PublicBase string `json:"public_base" yaml:"public_base"`
29+
}
30+
2631
// NewLocalFileService creates a new CDN adapter configured for local file storage.
2732
// It sets up the local storage client and wraps it with caching and S3-compatible interface.
28-
func NewLocalFileService(conf local.Config, publicBase string) (*fileserver.FileServer, error) {
29-
client, err := local.NewClient(conf)
33+
func NewLocalFileService(conf LocalFileServiceConfig) (*fileserver.FileServer, error) {
34+
client, err := local.NewClient(local.Config{
35+
RootDir: conf.RootDir,
36+
})
3037
if err != nil {
3138
return nil, err
3239
}
3340
adapter, err := fileserver.NewCDNAdapter(
3441
fileserver.Config{
35-
PutBase: publicBase,
36-
GetBase: publicBase,
42+
PutBase: conf.PublicBase,
43+
GetBase: conf.PublicBase,
3744
},
3845
memory.NewByteCache(),
3946
client,

0 commit comments

Comments
 (0)