client version

This commit is contained in:
m
2026-09-05 11:28:21 +02:00
parent 8982e96197
commit c7467ea8f9
4 changed files with 94 additions and 11 deletions
+53
View File
@@ -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
}
+12 -10
View File
@@ -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
}