utils

package
v0.0.0-...-48cb40f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 24, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	C2A = "client-to-all"
	C2S = "client-to-server"
	S2C = "server-to-client" // Server to single client broadcast
	S2A = "server-to-all"    // Global client broadcast
)
View Source
const (
	SERVER_ERR = 500
	CLIENT_ERR = 400
)
View Source
const (
	METADATA   = "metadata"
	RECEIV_URL = "receiverURL"
)

Variables

View Source
var (
	ChatClientsMap               = NewClientsMap[Client]()
	Id_Gen         *id_Generator = &id_Generator{
		start_ID: 0,
	}
	ConnUpgrader = websocket.Upgrader{}
)
View Source
var (
	PORT string
	// files
	REQUEST_LOG_PATH string
	SERVER_LOG_PATH  string

	CLIPBOARD_PATH_JSON string
	CLIPBOARD_PATH_TXT  string

	DUMMY_WS_LOG_PATH string

	CHAT_DEBUG string
	CHAT_LOG   string
	// ---
	CHAT_PASS string

	BUCKET_NAME         string
	BUCKET_REGION       string
	OBJ_RESUME_KEY      string
	OBJ_RESUME_PNG_KEY  string
	OBJ_RESUME_HTML_KEY string
	OBJ_RESUME_MD_KEY   string

	NOTES_DATA_FOLDER      string
	LOCAL_INFO_PATH        string
	LOCAL_RESUME_PATH      string
	LOCAL_RESUME_PNG_PATH  string
	LOCAL_RESUME_HTML_PATH string
	LOCAL_RESUME_MD_PATH   string

	QUERY_GENERAL_PASS string
	QUERY_TRIGGER_PASS string

	DB_URL     string
	DB_API_KEY string
)
View Source
var (
	FT_Map = make(map[string]*FT_Transfer)
)
View Source
var (
	S3_Files = []S3_File{}
)

Functions

func AppendLogToFile

func AppendLogToFile(data *Log, filePath string) error

Difference between this and LogData is that this logs to a given file, while the other has a default filepath. Actually nvm idk

func ComparePasswords

func ComparePasswords(hashedPassword string, enteredPassword string) error

func CreateWebClipboardFile

func CreateWebClipboardFile() error

This file needs to be created beforehand unlike others because its json and has a structure.

func DownloadAllObjKeys

func DownloadAllObjKeys(bucketName string, prefix string, region string) ([]string, error)

func DownloadAndWriteNoteData

func DownloadAndWriteNoteData() error

func DownloadFile

func DownloadFile(bucketName string, objPath string, region string) ([]byte, error)

Download the resource file from the given s3 bucket

func FileExists

func FileExists(filePath string) bool

Check if a file exists at the given filepath.

func GetClientsStr

func GetClientsStr(c *ClientsMap[Client]) string

Returns a string of all the online clients

func HashPassword

func HashPassword(password string) (string, error)

func InitDirs

func InitDirs()

Create the required directories

func InitFiles

func InitFiles()

func InitGlobalVars

func InitGlobalVars()

func InitSetupFunc

func InitSetupFunc()

func LogData

func LogData(data ...string)

Log data to the default file

func LogDataToPath

func LogDataToPath(logFilePath string, data ...string)

Log text data to a give filepath. If the file doesnt exist, it is created. Variadic function that can take any number of data.

func S3_DownloadFiles

func S3_DownloadFiles() error

func S3_ObjectInfoArr

func S3_ObjectInfoArr()

Currently only 2 files The resume pdf and png

Types

type Client

type Client struct {
	Id       string
	Username string
	Conn     *websocket.Conn
}

type ClientsMap

type ClientsMap[T any] struct {
	Clients map[string]*T
	// contains filtered or unexported fields
}

Hashmap of a client against their id.

var (
	GamePlayersMap *ClientsMap[PlayerClient] = NewClientsMap[PlayerClient]()
)

func NewClientsMap

func NewClientsMap[T any]() *ClientsMap[T]

func (*ClientsMap[T]) AddClient

func (c *ClientsMap[T]) AddClient(clientID string, client *T)

func (*ClientsMap[T]) DeleteClient

func (c *ClientsMap[T]) DeleteClient(clientID string)

func (*ClientsMap[T]) GetClient

func (c *ClientsMap[T]) GetClient(clientID string) (*T, bool)

func (*ClientsMap[T]) UpdateClient

func (c *ClientsMap[T]) UpdateClient(clientID string, updateFunc func(client *T) *T)

type Code_Generator

type Code_Generator struct {
	Start_ID uint8
}

generate unique code Limited to uint8 for now Easier to work encode in byte code idk

var (
	Tunneling_code_generator Code_Generator = Code_Generator{
		Start_ID: 1,
	}
)

func (*Code_Generator) NewCode

func (idGen *Code_Generator) NewCode() uint8

Just increments the default value

type ErrorMessage

type ErrorMessage struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

func ClientErr

func ClientErr(messageStr ...string) ErrorMessage

func InternalServerErr

func InternalServerErr(messageStr string) ErrorMessage

func (*ErrorMessage) Error

func (e *ErrorMessage) Error() string

type FTPayload

type FTPayload struct {
	SentBy  string
	Command string
	Content interface{}
}

type FT_MetaData_plusCONN

type FT_MetaData_plusCONN struct {
	ReceiverUrl  string
	ConnID       string
	Filename     string
	FileByteSize int64

	ReceiverConn *websocket.Conn
	SenderConn   *websocket.Conn
}

All of the metadata recerverURL, connID, filename, fileByteSize

type FT_Transfer

type FT_Transfer struct {
	ReceiverConn *websocket.Conn
	SenderConn   *websocket.Conn

	ReceiverApproved bool
	TransferID       string

	Filename     string
	FileByteSize int64
}

type FileInfo

type FileInfo struct {
	Filepath  string
	Size      int64
	ObjectKey string
}

type Log

type Log struct {
	ContentLength string
	Error         error
	Host          string
	Latency       time.Duration
	RemoteIP      string
	ResponseSize  int64
	Time          time.Time
	Status        int
	URI           string
	Protocol      string
}

type Message

type Message struct {
	Sender    string
	Direction string
	Config    string
	Content   string
	Password  string
	Timestamp string
}

type MetaDataFmt

type MetaDataFmt struct {
	ConnID       string
	Filename     string
	FileByteSize int64
}

type PlayerClient

type PlayerClient struct {
	Id       string
	Username string
	Conn     *websocket.Conn
	PosX     uint16
	PosY     uint16
}

type S3_File

type S3_File struct {
	LocalFilePath   string
	BucketObjectKey string
}

type ServerError

type ServerError struct {
	Err    error
	Code   int
	Simple string
}

Custom Server Error

func (*ServerError) Error

func (ce *ServerError) Error() string

type SuccessMessage

type SuccessMessage struct {
	Message string `json:"message"`
}

type UserProfile

type UserProfile struct {
	Id       int    `json:"id"`
	Username string `json:"username"`
	Password string `json:"password"`
	Email    string `json:"email"`
}

func GetUserFromEmail

func GetUserFromEmail(email string) ([]UserProfile, error)

Returns user array given the email. If the provided email not in the db, returns an empty array. This allows to check whether the user exists or no. Remember to account for offline db server.

type UserRegister

type UserRegister struct {
	Username string `json:"username"`
	Password string `json:"password"`
	Email    string `json:"email"`
}

The Id in UserProfile defaults to 0 which results in a conflict

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL