mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 12:54:01 +03:00
Refactor firehol
This commit is contained in:
@@ -22,7 +22,7 @@ func (h httpFile) Open(ctx context.Context) (io.ReadCloser, error) {
|
||||
response, err := h.http.Do(request)
|
||||
if err != nil {
|
||||
if response != nil {
|
||||
io.Copy(io.Discard, response.Body)
|
||||
io.Copy(io.Discard, response.Body) // nolint: errcheck
|
||||
response.Body.Close()
|
||||
}
|
||||
|
||||
@@ -36,6 +36,10 @@ func (h httpFile) Open(ctx context.Context) (io.ReadCloser, error) {
|
||||
return response.Body, nil
|
||||
}
|
||||
|
||||
func (h httpFile) String() string {
|
||||
return h.url
|
||||
}
|
||||
|
||||
func NewHTTP(client *http.Client, endpoint string) (File, error) {
|
||||
if client == nil {
|
||||
return nil, ErrBadHTTPClient
|
||||
|
||||
@@ -22,7 +22,7 @@ type HTTPTestSuite struct {
|
||||
}
|
||||
|
||||
func (suite *HTTPTestSuite) makeFile(path string) (files.File, error) {
|
||||
return files.NewHTTP(suite.httpClient, suite.httpServer.URL+"/"+path)
|
||||
return files.NewHTTP(suite.httpClient, suite.httpServer.URL+"/"+path) // nolint: wrapcheck
|
||||
}
|
||||
|
||||
func (suite *HTTPTestSuite) SetupSuite() {
|
||||
|
||||
@@ -10,4 +10,5 @@ var ErrBadHTTPClient = errors.New("incorrect http client")
|
||||
|
||||
type File interface {
|
||||
Open(context.Context) (io.ReadCloser, error)
|
||||
String() string
|
||||
}
|
||||
|
||||
@@ -4,18 +4,19 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
type localFile struct {
|
||||
root fs.FS
|
||||
name string
|
||||
path string
|
||||
}
|
||||
|
||||
func (l localFile) Open(ctx context.Context) (io.ReadCloser, error) {
|
||||
return l.root.Open(l.name)
|
||||
return os.Open(l.path) // nolint: wrapcheck
|
||||
}
|
||||
|
||||
func (l localFile) String() string {
|
||||
return l.path
|
||||
}
|
||||
|
||||
func NewLocal(path string) (File, error) {
|
||||
@@ -24,7 +25,6 @@ func NewLocal(path string) (File, error) {
|
||||
}
|
||||
|
||||
return localFile{
|
||||
root: os.DirFS(filepath.Dir(path)),
|
||||
name: filepath.Base(path),
|
||||
path: path,
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user