mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 21:04:02 +03:00
Update docs
This commit is contained in:
@@ -40,6 +40,8 @@ func (h httpFile) String() string {
|
||||
return h.url
|
||||
}
|
||||
|
||||
// NewHTTP returns a file abstraction for HTTP/HTTPS endpoint. You also need to
|
||||
// provide a valid instance of [http.Client] to access it.
|
||||
func NewHTTP(client *http.Client, endpoint string) (File, error) {
|
||||
if client == nil {
|
||||
return nil, ErrBadHTTPClient
|
||||
|
||||
@@ -6,9 +6,16 @@ import (
|
||||
"io"
|
||||
)
|
||||
|
||||
// ErrBadHTTPClient is returned if given HTTP client is initialized
|
||||
// incorrectly.
|
||||
var ErrBadHTTPClient = errors.New("incorrect http client")
|
||||
|
||||
// File is an abstraction for a entity that can be opened in some context.
|
||||
type File interface {
|
||||
// Open returns an readable entity for a file. It is important to not forget
|
||||
// to close it after the usage.
|
||||
Open(context.Context) (io.ReadCloser, error)
|
||||
|
||||
// String returns a short text description for the file
|
||||
String() string
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ func (l localFile) String() string {
|
||||
return l.path
|
||||
}
|
||||
|
||||
// NewLocal returns an openable File for a path on a local file system.
|
||||
func NewLocal(path string) (File, error) {
|
||||
if stat, err := os.Stat(path); os.IsNotExist(err) || stat.IsDir() || stat.Mode().Perm()&0o400 == 0 {
|
||||
return nil, fmt.Errorf("%s is not a readable file", path)
|
||||
|
||||
@@ -19,6 +19,7 @@ func (m memFile) String() string {
|
||||
return "mem"
|
||||
}
|
||||
|
||||
// NewMem returns an openable file that is kept in RAM.
|
||||
func NewMem(networks []*net.IPNet) File {
|
||||
builder := strings.Builder{}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user