utils

package
v0.0.0-...-9ebb391 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: MIT Imports: 14 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 *ClientsMap   = NewClientsMap()
	Id_Gen         *id_Generator = &id_Generator{
		start_ID: 0,
	}
	ConnUpgrader = websocket.Upgrader{}
)
View Source
var (
	PORT             string
	REQUEST_LOG_PATH string
	SERVER_LOG_PATH  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

	NOTES_DATA_FOLDER      string
	LOCAL_INFO_PATH        string
	LOCAL_RESUME_PATH      string
	LOCAL_RESUME_PNG_PATH  string
	LOCAL_RESUME_HTML_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

func ComparePasswords

func ComparePasswords(hashedPassword string, enteredPassword string) error

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

func HashPassword

func HashPassword(password string) (string, error)

func InitDirs

func InitDirs()

Create the required directories

func InitGlobalVars

func InitGlobalVars()

func InitVars

func InitVars()

Currently only 2 files The resume pdf and png

func LogData

func LogData(data string, logFilePath string)

func S3_DownloadFiles

func S3_DownloadFiles() error

Types

type Client

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

type ClientsMap

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

func NewClientsMap

func NewClientsMap() *ClientsMap

func (*ClientsMap) AddClient

func (c *ClientsMap) AddClient(clientID string, client *Client)

func (*ClientsMap) DeleteClient

func (c *ClientsMap) DeleteClient(clientID string)

func (*ClientsMap) GetClient

func (c *ClientsMap) GetClient(clientID string) (Client, bool)

func (*ClientsMap) GetClientsStr

func (c *ClientsMap) GetClientsStr() string

Returns a string of all the online clients

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 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 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"`
}

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