common

package
v0.0.0-...-6c8972c Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SessionCookieName          = "restora-session"
	SessionCookieState         = "state"
	AuthCodeURL                = "somerandomstring"
	GenericErrMsg              = "Please contact the administrator."
	SessionCookieLoginRedirect = "loginRedirect"
	SessionCookieToken         = "token"

	SessionUserID       = "user-id"
	SessionEmail        = "email"
	SessionProfileImage = "profile-image"
	SessionFirstName    = "first-name"
	SessionLastName     = "last-name"
	SessionEmpFirstName = "emp-first-name"
	SessionEmpLastName  = "emp-last-name"
	SessionDesignation  = "designation"
	SessionRoleID       = "roleID"
	SessionUserName     = "userName"

	SUPERADMIN       = "Super Admin"
	FromName         = "restora-session"
	LimitPerPage     = 10
	InvitationStatus = 3
)
View Source
const (
	HomePath  = "/"
	ErrorPath = "/error"

	RegistrationPath = "/registration"
	LoginPath        = "/login"

	ProfilePath            = "/profile"
	ProfileEditPath        = "/profile/edit"
	ResendOtpPath          = "/resend-otp"
	ChangePasswordPath     = "/password"
	ChangePasswordEditPath = "/change/password"
	OTPPasswordPath        = "/otp/password"
	UploadProfileImagePath = "/profile/update/image"
	LoginCallBackPath      = "/oauth2/callback"
	RedirectURLPath        = "/redirect-url"
	ConsentPath            = "/consent"
	LogoutPath             = "/logout"

	DashboardPath = "/dashboard"

	UserListPath = "/user/list"

	CategoryCreatePath = "/category/create"
	CategoryEditPath   = "/category/edit/{id}"
	CategoryListPath   = "/category/list"
	CategoryDeletePath = "/category/delete/{id}"

	BrandCreatePath = "/brand/create"
	BrandEditPath   = "/brand/edit/{id}"
	BrandListPath   = "/brand/list"
	BrandDeletePath = "/brand/delete/{id}"
)
View Source
const TextValidation = `^[A-Za-z.-]+(\s*[A-Za-z.-]+)*$`

regex validation only text, space is allowed but no number is not allowed

Variables

View Source
var (
	// NotFound is returned when the requested resource does not exist.
	NotFound = status.Error(codes.NotFound, "not found")
	// Conflict is returned when trying to create the same resource twice.
	Conflict = status.Error(codes.AlreadyExists, "conflict")
	// UsernameExists is returned when the username already exists in storage.
	UsernameExists = errors.New("username already exists")
	// EmailExists is returned when signup email already exists in storage.
	EmailExists = errors.New("email already exists")
	// InvCodeExists is returned when invitation code already exists in storage.
	InvCodeExists = errors.New("invitation code already exists")
)
View Source
var (
	IgnorePath = []string{LoginPath, RegistrationPath}
)

Functions

func CacheStaticFiles

func CacheStaticFiles(h http.Handler) http.Handler

func DynamicUrlSwitch

func DynamicUrlSwitch(url string, params map[string]string) string

func HashPassword

func HashPassword(password string) (string, error)

func IsPartialTemplate

func IsPartialTemplate(name string) bool

Types

type Authenticator

type Authenticator struct {
	BaseURL   string
	LogoutURL string
}

type DynamicQueryString

type DynamicQueryString struct {
	SearchTerm   string
	StartDate    string
	SortBy       string
	SortByColumn string
	EndDate      string
	PageNumber   int32
	CurrentPage  int32
	Offset       int32
	OthersValue  map[string]string
}

func GetQueryStringData

func GetQueryStringData(r *http.Request, keys []string, isNotDefault bool) *DynamicQueryString

type JsonErrorFormat

type JsonErrorFormat struct {
	Status   bool   `Json:"status"`
	Code     int32  `Json:"code"`
	Message  string `Json:"message"`
	ErrorMas map[string]string
}

type PublicTemplateData

type PublicTemplateData struct {
	UserInfo *SessionUser
}

type Server

type Server struct {
	Env       string
	Config    *viper.Viper
	Logger    *logrus.Entry
	Assets    *hashfs.FS
	Decoder   *schema.Decoder
	Auth      *Authenticator
	Cookies   *sessions.CookieStore
	Templates *template.Template
	Sess      *sessions.Session
	User      user.UserServiceClient
	Login     auth.LoginServiceClient
	Category  category.CategoryServiceClient
	Brand     brand.BrandServiceClient
}

func (*Server) DoTemplate

func (s *Server) DoTemplate(w http.ResponseWriter, r *http.Request, name string, status int) error

func (*Server) GetAuthMiddleware

func (s *Server) GetAuthMiddleware(next http.Handler) http.Handler

func (*Server) GetErrorHandler

func (s *Server) GetErrorHandler() http.Handler

func (*Server) GetSessionUser

func (s *Server) GetSessionUser(r *http.Request) *SessionUser

func (*Server) LookupTemplate

func (s *Server) LookupTemplate(name string) *template.Template

func (*Server) ParseTemplates

func (s *Server) ParseTemplates() error

func (*Server) StringToDate

func (s *Server) StringToDate(date string) time.Time

func (*Server) TemplateData

func (s *Server) TemplateData(r *http.Request) TemplateData

type SessionUser

type SessionUser struct {
	ID              string
	Email           string
	Image           string
	RoleID          string
	RoleName        string
	UserName        string
	FirstName       string
	LastName        string
	DesignationName string
}

type Status

type Status struct {
	ID   int32
	Name string
}

func GetStatus

func GetStatus(st map[int32]string) []Status

type TemplateData

type TemplateData struct {
	Env       string
	CSRFField template.HTML
	Form      TemplateForm
}

type TemplateForm

type TemplateForm struct {
	ErrorCode    string
	ErrorDetails string
}

Jump to

Keyboard shortcuts

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