util

package
v0.0.0-...-a5025f8 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UserContextKey    = ContextType("user")
	ProblemContextKey = ContextType("problem")
	TestContextKey    = ContextType("test")

	SubmissionContextKey     = ContextType("submission")
	SubmissionTestContextKey = ContextType("submissionTest")
)

Variables

This section is empty.

Functions

func CompareHashAndPassword

func CompareHashAndPassword(password, hashedPassword string) bool

func DataResponse

func DataResponse(w http.ResponseWriter, statusCode int, retData interface{}, logger *log.Logger)

func EmptyResponse

func EmptyResponse(w http.ResponseWriter, statusCode int)

func ErrorResponse

func ErrorResponse(w http.ResponseWriter, statusCode int, retData interface{}, logger *log.Logger)

func GenerateJwtToken

func GenerateJwtToken(jwtSecret string, expires time.Duration, user *models.User) (string, error)

func GeneratePasswordHash

func GeneratePasswordHash(password string) (string, error)

func IsRAdmin

func IsRAdmin(r *http.Request) bool

IsRAdmin returns true if the user creating the request is an admin

func IsRAuthed

func IsRAuthed(r *http.Request) bool

IsRAuthed returns true if the user creating the request is authenticated

func IsRProposer

func IsRProposer(r *http.Request) bool

IsRProposer returns true if the user creating the request is a proposer

func IsTokenValid

func IsTokenValid(tokenString, jwtSecret string) error

IsTokenValid returns nil if the jwt token is valid and an error otherwise.

func ProblemFromRequestContext

func ProblemFromRequestContext(r *http.Request) *models.Problem

ProblemFromRequestContext returns a pointer to the problem from request context

func SubmissionFromRequestContext

func SubmissionFromRequestContext(r *http.Request) *models.Submission

SubmissionFromRequestContext returns a pointer to the file-managers from request context

func SubmissionTestFromRequestContext

func SubmissionTestFromRequestContext(r *http.Request) *models.SubmissionTest

func TestFromRequestContext

func TestFromRequestContext(r *http.Request) *models.Test

TestFromRequestContext returns a pointer to the test from request context

func UserFromRequestContext

func UserFromRequestContext(r *http.Request) *models.User

UserFromRequestContext returns a pointer to the user from request context

func VerifyToken

func VerifyToken(tokenString, jwtSecret string) (*jwt.Token, error)

Types

type ContextType

type ContextType string

Jump to

Keyboard shortcuts

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