Documentation
¶
Index ¶
- func DecodeJson(w http.ResponseWriter, r *http.Request, v any) error
- func DeleteAllUserS3Obj(ctx context.Context, s3Client *s3.Client, bucket, prefix string) error
- func GenerateUserIDHash(userID string, secretKey string) string
- func GetJWTToken(userData database.User, jwtSecret string, expiry time.Duration) (string, error)
- func RespondWithError(w http.ResponseWriter, logger *slog.Logger, msgToDev string, err error, ...)
- func RespondWithJSON(w http.ResponseWriter, status int, payload interface{}) error
- func RespondWithWarn(w http.ResponseWriter, logger *slog.Logger, msgToDev, msgToClient string, ...)
- func UserIDFromContext(ctx context.Context) (uuid.UUID, bool)
- type AccessTokenResponse
- type CliVersion
- type FileDetailedData
- type FileHash
- type FileIDConflictMatches
- type FileUploadMetadata
- type FileUploadRequest
- type FileUploadSuccessResponse
- type FilesMetadata
- type PassphraseSaltRes
- type PresignResponse
- type RefreshToken
- type Server
- func (s *Server) Auth(next http.Handler) http.Handler
- func (s *Server) HandlerCliVersion(w http.ResponseWriter, r *http.Request)
- func (s *Server) HandlerCompleteFileUpload(w http.ResponseWriter, r *http.Request)
- func (s *Server) HandlerCreateUser(w http.ResponseWriter, r *http.Request)
- func (s *Server) HandlerDeleteFile(w http.ResponseWriter, r *http.Request)
- func (s *Server) HandlerDeleteUser(w http.ResponseWriter, r *http.Request)
- func (s *Server) HandlerGenerateDownloadLink(w http.ResponseWriter, r *http.Request)
- func (s *Server) HandlerGeneratePresignLink(w http.ResponseWriter, r *http.Request)
- func (s *Server) HandlerGetAllFiles(w http.ResponseWriter, r *http.Request)
- func (s *Server) HandlerGetDetailedFile(w http.ResponseWriter, r *http.Request)
- func (s *Server) HandlerGetFileHash(w http.ResponseWriter, r *http.Request)
- func (s *Server) HandlerGetPassphraseSalt(w http.ResponseWriter, r *http.Request)
- func (s *Server) HandlerLogin(w http.ResponseWriter, r *http.Request)
- func (s *Server) HandlerReadiness(w http.ResponseWriter, r *http.Request)
- func (s *Server) HandlerRefreshToken(w http.ResponseWriter, r *http.Request)
- func (s *Server) HandlerReset(w http.ResponseWriter, r *http.Request)
- func (s *Server) HandlerResolveFileMatches(w http.ResponseWriter, r *http.Request)
- func (s *Server) HandlerRevokeToken(w http.ResponseWriter, r *http.Request)
- func (s *Server) HandlerVerifyUser(w http.ResponseWriter, r *http.Request)
- type UserIncoming
- type UserLoginIncoming
- type UserLoginOutgoing
- type UserOutgoing
- type VerifyRequest
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeleteAllUserS3Obj ¶
func GenerateUserIDHash ¶
Generate hash from UserID to use it as prefix of s3key
func GetJWTToken ¶
func RespondWithError ¶
func RespondWithError(w http.ResponseWriter, logger *slog.Logger, msgToDev string, err error, code int)
Helper function to log error and also give appropriate response to the client To be used when the user needs an error but something in our code broke that needs to be fixed ASAP
func RespondWithJSON ¶
func RespondWithJSON(w http.ResponseWriter, status int, payload interface{}) error
func RespondWithWarn ¶
func RespondWithWarn(w http.ResponseWriter, logger *slog.Logger, msgToDev, msgToClient string, err error, code int)
Helper function to log warnings and also give appropirate response to the client To be used when the user needs an error message but our backend code is intact
Types ¶
type AccessTokenResponse ¶
type AccessTokenResponse struct {
AccessToken string `json:"access_token"`
}
Outgoing: new access token
type CliVersion ¶
type CliVersion struct {
CompatibleVersion string `json:"compatible_version"`
}
Outgoing: CLI version response
type FileDetailedData ¶
type FileDetailedData struct {
FileName string `json:"file_name"`
ID uuid.UUID `json:"file_id"`
Status string `json:"status"`
PlaintextSizeBytes int64 `json:"plaintext_size_bytes"`
EncryptedSizeBytes int64 `json:"encrypted_size_bytes"`
S3Key string `json:"s3_key"`
KeyManagementMode string `json:"key_management_mode"`
PlaintextHash string `json:"plaintext_hash"`
}
Outgoing: Send deatils of one file
type FileIDConflictMatches ¶
type FileIDConflictMatches struct {
FileName string `json:"file_name"`
FileID uuid.UUID `json:"file_id"`
}
Outgoing: send multiple file matches to resolve file id conflict
type FileUploadMetadata ¶
type FileUploadMetadata struct {
FileID uuid.UUID `json:"file_id"`
PlaintextHash string `json:"plaintext_hash"`
PlaintextSizeBytes int64 `json:"plaintext_size_bytes"`
PassphraseSalt string `json:"passphrase_salt"`
}
Incoming: send by the client after successful file upload
type FileUploadRequest ¶
type FileUploadRequest struct {
FileName string `json:"file_name"`
MimeType string `json:"mime_type"`
}
Incoming: sent by the client before we generate a presigned S3 POST URL. It carries basic metadata for the upload.
type FileUploadSuccessResponse ¶
type FileUploadSuccessResponse struct {
S3ObjectKey string `json:"s3_object_key"`
UploadedFileSize int64 `json:"uploaded_file_size"`
}
Outgoing: Send status if file upload is successfull
type FilesMetadata ¶
type FilesMetadata struct {
FileName string `json:"file_name"`
EncryptedSizeBytes int64 `json:"encrypted_size_bytes"`
Status string `json:"status"`
KeyManagementMode string `json:"key_management_mode"`
CreatedAt time.Time `json:"created_at"`
ID uuid.UUID `json:"file_id"`
}
Outgoing: Send all files of a user
type PassphraseSaltRes ¶
type PassphraseSaltRes struct {
Salt string `json:"salt"`
}
Outgoing: Send passphrase salt
type PresignResponse ¶
type PresignResponse struct {
FileID uuid.UUID `json:"file_id"`
UploadResource aws.S3PutResponse `json:"upload_resource"`
}
Outgoing: presigned url response to the client
type RefreshToken ¶
type RefreshToken struct {
RefreshToken string `json:"refresh_token"`
}
Incoming: refresh token
type Server ¶
type Server struct {
Store *store.Store
Logger *slog.Logger
Cfg *config.Config
AwsConfig aws.Config
S3Client *s3.Client
SESClient *sesv2.Client
}
Server struct to give access of store and logger to each handler as a method
func (*Server) HandlerCliVersion ¶
func (s *Server) HandlerCliVersion(w http.ResponseWriter, r *http.Request)
Sends the current cli version compatible with the server
func (*Server) HandlerCompleteFileUpload ¶
func (s *Server) HandlerCompleteFileUpload(w http.ResponseWriter, r *http.Request)
func (*Server) HandlerCreateUser ¶
func (s *Server) HandlerCreateUser(w http.ResponseWriter, r *http.Request)
func (*Server) HandlerDeleteFile ¶
func (s *Server) HandlerDeleteFile(w http.ResponseWriter, r *http.Request)
func (*Server) HandlerDeleteUser ¶
func (s *Server) HandlerDeleteUser(w http.ResponseWriter, r *http.Request)
func (*Server) HandlerGenerateDownloadLink ¶
func (s *Server) HandlerGenerateDownloadLink(w http.ResponseWriter, r *http.Request)
Generates a signed cloudfront link and redirects to it after validating if the daily downloads limit is not hit
func (*Server) HandlerGeneratePresignLink ¶
func (s *Server) HandlerGeneratePresignLink(w http.ResponseWriter, r *http.Request)
func (*Server) HandlerGetAllFiles ¶
func (s *Server) HandlerGetAllFiles(w http.ResponseWriter, r *http.Request)
func (*Server) HandlerGetDetailedFile ¶
func (s *Server) HandlerGetDetailedFile(w http.ResponseWriter, r *http.Request)
func (*Server) HandlerGetFileHash ¶
func (s *Server) HandlerGetFileHash(w http.ResponseWriter, r *http.Request)
func (*Server) HandlerGetPassphraseSalt ¶
func (s *Server) HandlerGetPassphraseSalt(w http.ResponseWriter, r *http.Request)
func (*Server) HandlerLogin ¶
func (s *Server) HandlerLogin(w http.ResponseWriter, r *http.Request)
func (*Server) HandlerReadiness ¶
func (s *Server) HandlerReadiness(w http.ResponseWriter, r *http.Request)
HandlerReadiness reports whether the API is healthy and ready to serve requests
func (*Server) HandlerRefreshToken ¶
func (s *Server) HandlerRefreshToken(w http.ResponseWriter, r *http.Request)
func (*Server) HandlerReset ¶
func (s *Server) HandlerReset(w http.ResponseWriter, r *http.Request)
func (*Server) HandlerResolveFileMatches ¶
func (s *Server) HandlerResolveFileMatches(w http.ResponseWriter, r *http.Request)
func (*Server) HandlerRevokeToken ¶
func (s *Server) HandlerRevokeToken(w http.ResponseWriter, r *http.Request)
func (*Server) HandlerVerifyUser ¶
func (s *Server) HandlerVerifyUser(w http.ResponseWriter, r *http.Request)
type UserIncoming ¶
Incoming: struct to receive from the user
type UserLoginIncoming ¶
Incoming: Login struct to receive from the user
type UserLoginOutgoing ¶
type UserLoginOutgoing struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
}
Outgoing: struct to send the user once they are logged in
type UserOutgoing ¶
type UserOutgoing struct {
ID any `json:"id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Email string `json:"email"`
}
Outgoing: User struct to send a response after creation
type VerifyRequest ¶
Incoming: receive account verification data
Source Files
¶
- handler_cli_version.go
- handler_complete_file_upload.go
- handler_create_user.go
- handler_delete_file.go
- handler_delete_user.go
- handler_generate_download_link.go
- handler_generate_presign_link.go
- handler_get_all_files.go
- handler_get_detailed_file.go
- handler_get_file_hash.go
- handler_get_passphrase_salt.go
- handler_login.go
- handler_readiness.go
- handler_refresh_token.go
- handler_reset.go
- handler_resolve_file_matches.go
- handler_revoke_token.go
- handler_verify_user.go
- helper_decode_json.go
- helper_delete_all_s3_objects_of_user.go
- helper_generate_user_id_hash.go
- helper_get_jwt_token.go
- helper_respond_with_error.go
- helper_respond_with_json.go
- helper_user_id_from_context.go
- middleware_auth.go
- models.go
- server.go