File

File represents a file backed by a route, a reader or an opening function.

This API is used in Files.


Symbols

SymbolClassDescription
FileConfigtypeFileConfig defines a public type of API.
FileInfotypeFileInfo defines a public type of API.
FiletypeFile defines a public type of API.
NewFilefuncBuild NewFile.
NewFileWithContentTypefuncBuild NewFileWithContentType.
File.IsZerofuncIndicates the state of IsZero.
File.InfofuncReturns the metadata from the file.
File.NamefuncGive the name back.
File.FilenamefuncReturn the name of the file.
File.LenfuncReturns the declared size.
File.SizefuncReturns the declared size.
File.ContentTypefuncReturn the MIME type.
File.TypefuncReturn the MIME type.
File.SetNamefuncSets SetName.
File.SetMIMETypefuncSets SetMIMEType.
File.OpenfuncIt opens a new source of reading.
File.ReadfuncRead the contents in the indicated buffer.
File.WritefuncWrite content.
File.SeekfuncChange the reading or writing position.
File.ClosefuncClose the open resources.
File.WriteTofuncCopy the content to a io.Writer.
File.ReadFromfuncLee. ReadFrom.

FileConfig

Declaration:

gox
type FileConfig struct {
	Path string
	Name string
	Type string
	Content io.Reader
	Open func() (io.ReadCloser, error)
	Size int64
}

FileConfig defines a public type of API.

Fields

FieldTypeDescription
PathstringRoute used.
NamestringName of the value.
TypestringDeclared type.
Contentio.ReaderAssociated content.
Openfunc() (io.ReadCloser, error)Function that opens a new source.
Sizeint64Size in bytes.

FileInfo

Declaration:

gox
type FileInfo struct {
	Name        string
	ContentType string
	Size        int64
}

FileInfo defines a public type of API.

Fields

FieldTypeDescription
NamestringName of the value.
ContentTypestringHalf type declared.
Sizeint64Size in bytes.

File

Declaration:

gox
type File struct {
	// contiene campos internos
}

File defines a public type of API.


NewFile

Declaration:

gox
func NewFile(config FileConfig) (File, error)

Build NewFile.

Parameters

ParameterTypeDescription
configFileConfigType value FileConfig required by the operation.

Returns

ReturnTypeDescription
valueFileType value File produced by the operation.
errerrornil if the operation ends correctly; otherwise, the error produced.

Behavior

The operation returns an error when it cannot complete the above contract.

Errors

NewFile returns an error when the arguments, the status of the receiver or the underlying operation make it impossible to complete the call.

Usage syntax

gox
value, err := gox.NewFile(gox.FileConfig{})

NewFileWithContentType

Declaration:

gox
func NewFileWithContentType(name string, contentType string, reader io.Reader) (File, error)

Build NewFileWithContentType.

Parameters

ParameterTypeDescription
namestringName assigned.
contentTypestringMIME type of content.
readerio.ReaderReading source.

Returns

ReturnTypeDescription
valueFileType value File produced by the operation.
errerrornil if the operation ends correctly; otherwise, the error produced.

Behavior

The operation returns an error when it cannot complete the above contract.

Errors

NewFileWithContentType returns an error when the arguments, the status of the receiver or the underlying operation make it impossible to complete the call.

Usage syntax

gox
value, err := gox.NewFileWithContentType("name", value, value)

File.IsZero

Declaration:

gox
func (file File) IsZero() bool

Indicates the state of IsZero.

Returns

ReturnTypeDescription
valueboolIt indicates the result of the check.

Behavior

It does not open or consume the content.

Usage syntax

gox
value := file.IsZero()

File.Info

Declaration:

gox
func (file File) Info() FileInfo

Returns the metadata from the file.

Returns

ReturnTypeDescription
valueFileInfoType value FileInfo produced by the operation.

Usage syntax

gox
value := file.Info()

File.Name

Declaration:

gox
func (file File) Name() string

Give the name back.

Returns

ReturnTypeDescription
valuestringTextual value produced by the operation; its zero value is an empty string.

Usage syntax

gox
value := file.Name()

File.Filename

Declaration:

gox
func (file File) Filename() string

Return the name of the file.

Returns

ReturnTypeDescription
valuestringTextual value produced by the operation; its zero value is an empty string.

Usage syntax

gox
value := file.Filename()

File.Len

Declaration:

gox
func (file File) Len() int64

Returns the declared size.

Returns

ReturnTypeDescription
valueint64Type value int64 produced by the operation.

Usage syntax

gox
value := file.Len()

File.Size

Declaration:

gox
func (file File) Size() int64

Returns the declared size.

Returns

ReturnTypeDescription
valueint64Type value int64 produced by the operation.

Usage syntax

gox
value := file.Size()

File.ContentType

Declaration:

gox
func (file File) ContentType() string

Return the MIME type.

Returns

ReturnTypeDescription
valuestringTextual value produced by the operation; its zero value is an empty string.

Usage syntax

gox
value := file.ContentType()

File.Type

Declaration:

gox
func (file File) Type() string

Return the MIME type.

Returns

ReturnTypeDescription
valuestringTextual value produced by the operation; its zero value is an empty string.

Usage syntax

gox
value := file.Type()

File.SetName

Declaration:

gox
func (file File) SetName(name string) error

Sets SetName.

Parameters

ParameterTypeDescription
namestringName assigned.

Returns

ReturnTypeDescription
errerrornil if the operation ends correctly; otherwise, the error produced.

Behavior

The operation returns an error when it cannot complete the above contract.

Errors

SetName returns an error when the arguments, the status of the receiver or the underlying operation make it impossible to complete the call.

Usage syntax

gox
err := file.SetName("name")

File.SetMIMEType

Declaration:

gox
func (file File) SetMIMEType(contentType string) error

Sets SetMIMEType.

Parameters

ParameterTypeDescription
contentTypestringMIME type of content.

Returns

ReturnTypeDescription
errerrornil if the operation ends correctly; otherwise, the error produced.

Behavior

The operation returns an error when it cannot complete the above contract.

Errors

SetMIMEType returns an error when the arguments, the status of the receiver or the underlying operation make it impossible to complete the call.

Usage syntax

gox
err := file.SetMIMEType(value)

File.Open

Declaration:

gox
func (file File) Open() (io.ReadCloser, error)

It opens a new source of reading.

Returns

ReturnTypeDescription
valueio.ReadCloserType value io.ReadCloser produced by the operation.
errerrornil if the operation ends correctly; otherwise, the error produced.

Behavior

Each call requests a new source to the configured backend.

Errors

Open returns an error when the arguments, the status of the receiver or the underlying operation make it impossible to complete the call.

Usage syntax

gox
value, err := file.Open()

File.Read

Declaration:

gox
func (file File) Read(p []byte) (int, error)

Read the contents in the indicated buffer.

Parameters

ParameterTypeDescription
p[]byteType value []byte required by the operation.

Returns

ReturnTypeDescription
valueintType value int produced by the operation.
errerrornil if the operation ends correctly; otherwise, the error produced.

Behavior

The operation returns an error when it cannot complete the above contract.

Errors

Read returns an error when the arguments, the status of the receiver or the underlying operation make it impossible to complete the call.

Usage syntax

gox
value, err := file.Read(value)

File.Write

Declaration:

gox
func (file File) Write(p []byte) (int, error)

Write content.

Parameters

ParameterTypeDescription
p[]byteType value []byte required by the operation.

Returns

ReturnTypeDescription
valueintType value int produced by the operation.
errerrornil if the operation ends correctly; otherwise, the error produced.

Behavior

The operation returns an error when it cannot complete the above contract.

Errors

Write returns an error when the arguments, the status of the receiver or the underlying operation make it impossible to complete the call.

Usage syntax

gox
value, err := file.Write(value)

File.Seek

Declaration:

gox
func (file File) Seek(offset int64, whence int) (int64, error)

Change the reading or writing position.

Parameters

ParameterTypeDescription
offsetint64Type value int64 required by the operation.
whenceintType value int required by the operation.

Returns

ReturnTypeDescription
valueint64Type value int64 produced by the operation.
errerrornil if the operation ends correctly; otherwise, the error produced.

Behavior

The operation returns an error when it cannot complete the above contract.

Errors

Seek returns an error when the arguments, the status of the receiver or the underlying operation make it impossible to complete the call.

Usage syntax

gox
value, err := file.Seek(value, value)

File.Close

Declaration:

gox
func (file File) Close() error

Close the open resources.

Returns

ReturnTypeDescription
errerrornil if the operation ends correctly; otherwise, the error produced.

Behavior

The subsequent calls depend on the state of the appeal.

Errors

Close returns an error when the arguments, the status of the receiver or the underlying operation make it impossible to complete the call.

Usage syntax

gox
err := file.Close()

File.WriteTo

Declaration:

gox
func (file File) WriteTo(writer io.Writer) (int64, error)

Copy the content to a io.Writer.

Parameters

ParameterTypeDescription
writerio.WriterA writing destination.

Returns

ReturnTypeDescription
valueint64Type value int64 produced by the operation.
errerrornil if the operation ends correctly; otherwise, the error produced.

Behavior

The operation returns an error when it cannot complete the above contract.

Errors

WriteTo returns an error when the arguments, the status of the receiver or the underlying operation make it impossible to complete the call.

Usage syntax

gox
value, err := file.WriteTo(value)

File.ReadFrom

Declaration:

gox
func (file File) ReadFrom(reader io.Reader) (int64, error)

Lee. ReadFrom.

Parameters

ParameterTypeDescription
readerio.ReaderReading source.

Returns

ReturnTypeDescription
valueint64Type value int64 produced by the operation.
errerrornil if the operation ends correctly; otherwise, the error produced.

Behavior

The operation returns an error when it cannot complete the above contract.

Errors

ReadFrom returns an error when the arguments, the status of the receiver or the underlying operation make it impossible to complete the call.

Usage syntax

gox
value, err := file.ReadFrom(value)

See also

Next step

Continue with auxiliary values of the gox package.

Values