banniere legacy + base
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
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package entities
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type Document struct {
|
||||
UUID *string
|
||||
Type int
|
||||
Name *string
|
||||
OriginalName string
|
||||
Version int
|
||||
}
|
||||
|
||||
const (
|
||||
ERROR_DOCUMENT_TYPE = "ERROR_DOCUMENT_TYPE"
|
||||
ERROR_DOCUMENT_MOVE = "ERROR_DOCUMENT_MOVE"
|
||||
ERROR_DOCUMENT_NOT_PERCISTED = "ERROR_DOCUMENT_NOT_PERCISTED"
|
||||
)
|
||||
|
||||
const (
|
||||
FILE = 1
|
||||
DIRECTORY = 2
|
||||
)
|
||||
|
||||
func IsDocumentTypeValid(documentType int) bool {
|
||||
|
||||
return IsFile(documentType) || IsDirectory(documentType)
|
||||
|
||||
}
|
||||
|
||||
func IsFile(documentType int) bool {
|
||||
return FILE == documentType
|
||||
}
|
||||
|
||||
func IsDirectory(documentType int) bool {
|
||||
return DIRECTORY == documentType
|
||||
}
|
||||
|
||||
func NewDocument(documentName string, documentType int, documentVersion int) (error, *Document) {
|
||||
|
||||
documentTypeIsValid := IsDocumentTypeValid(documentType)
|
||||
|
||||
if !documentTypeIsValid {
|
||||
return fmt.Errorf(ERROR_DOCUMENT_TYPE), nil
|
||||
}
|
||||
|
||||
return nil, &Document{
|
||||
Name: &documentName,
|
||||
Type: documentType,
|
||||
Version: documentVersion,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (d *Document) GetOriginalName() *string {
|
||||
|
||||
return &d.OriginalName
|
||||
|
||||
}
|
||||
|
||||
func (d *Document) GetName() *string {
|
||||
|
||||
if d.Name == nil {
|
||||
return d.GetOriginalName()
|
||||
}
|
||||
|
||||
return d.Name
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
package entities
|
||||
@@ -0,0 +1,11 @@
|
||||
package entities
|
||||
|
||||
type User struct {
|
||||
Username string
|
||||
}
|
||||
|
||||
func NewUser(username string) (error, *User) {
|
||||
return nil, &User{
|
||||
Username: username,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user