-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #225 from Egorkin-enabled/main
Лабораторная работа №5: Работа со структурами (Вариант №11)
- Loading branch information
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package lab_4 | ||
|
||
// Kozlov Egor 1/278: Variant 11 | ||
|
||
import "fmt" | ||
|
||
type document struct { | ||
documentPath string | ||
documentType string | ||
documentSize int64 | ||
} | ||
|
||
func NewDocument(path, documentType string, documentSize int64) (*document, error) { | ||
document := document{ | ||
documentPath: path, | ||
documentType: documentType, | ||
} | ||
|
||
error := document.SetDocumentSize(documentSize) | ||
|
||
if error != nil { | ||
return nil, error | ||
} | ||
|
||
return &document, error | ||
} | ||
|
||
func (d *document) DocumentPath() string { | ||
return d.documentPath | ||
} | ||
|
||
func (d *document) DocumentType() string { | ||
return d.documentType | ||
} | ||
|
||
func (d *document) DocumentSize() int64 { | ||
return d.documentSize | ||
} | ||
|
||
func (d *document) SetDocumentSize(size int64) error { | ||
if size < 0 { | ||
return fmt.Errorf("Error: size must be >= 0. Current value: %v", size) | ||
} | ||
|
||
d.documentSize = size | ||
return nil | ||
} |