client version
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package entities
|
||||
|
||||
import "fmt"
|
||||
|
||||
const SERVER_VERSION = 1
|
||||
|
||||
type Client interface {
|
||||
GetClientVersion() int
|
||||
}
|
||||
|
||||
func NewClient(clientVersion int) (error, Client) {
|
||||
|
||||
isCompatible := ServerClientIsCompatibleWithClient(clientVersion)
|
||||
|
||||
if !isCompatible {
|
||||
return fmt.Errorf("You client version %n is not compatible with the server verison %n", clientVersion, SERVER_VERSION), nil
|
||||
}
|
||||
|
||||
client := ClientVerisonOne{
|
||||
Version: clientVersion,
|
||||
}
|
||||
|
||||
return nil, &client
|
||||
|
||||
}
|
||||
|
||||
func ServerClientIsCompatibleWithClient(clientVersion int) bool {
|
||||
|
||||
switch clientVersion {
|
||||
case 1:
|
||||
|
||||
serverCompatibleVersion := []int{1}
|
||||
|
||||
for _, serverVersion := range serverCompatibleVersion {
|
||||
if serverVersion == clientVersion {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
default:
|
||||
return false
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
type ClientVerisonOne struct {
|
||||
Version int
|
||||
}
|
||||
|
||||
func (c *ClientVerisonOne) GetClientVersion() int {
|
||||
return c.Version
|
||||
}
|
||||
@@ -5,10 +5,11 @@ import (
|
||||
)
|
||||
|
||||
type Document struct {
|
||||
DocumentUUID *string
|
||||
DocumentType int
|
||||
DocumentName *string
|
||||
DocumentOriginalName string
|
||||
UUID *string
|
||||
Type int
|
||||
Name *string
|
||||
OriginalName string
|
||||
Version int
|
||||
}
|
||||
|
||||
const (
|
||||
@@ -36,7 +37,7 @@ func IsDirectory(documentType int) bool {
|
||||
return DIRECTORY == documentType
|
||||
}
|
||||
|
||||
func NewDocument(documentName string, documentType int) (error, *Document) {
|
||||
func NewDocument(documentName string, documentType int, documentVersion int) (error, *Document) {
|
||||
|
||||
documentTypeIsValid := IsDocumentTypeValid(documentType)
|
||||
|
||||
@@ -45,24 +46,25 @@ func NewDocument(documentName string, documentType int) (error, *Document) {
|
||||
}
|
||||
|
||||
return nil, &Document{
|
||||
DocumentName: &documentName,
|
||||
DocumentType: documentType,
|
||||
Name: &documentName,
|
||||
Type: documentType,
|
||||
Version: documentVersion,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (d *Document) GetOriginalName() *string {
|
||||
|
||||
return &d.DocumentOriginalName
|
||||
return &d.OriginalName
|
||||
|
||||
}
|
||||
|
||||
func (d *Document) GetName() *string {
|
||||
|
||||
if d.DocumentName == nil {
|
||||
if d.Name == nil {
|
||||
return d.GetOriginalName()
|
||||
}
|
||||
|
||||
return d.DocumentName
|
||||
return d.Name
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user