mdw

package
v0.7.55 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ULogEmpty UserLoggerFn = func(u *service.UserLogData, w http.ResponseWriter, r *http.Request) error {
		return nil
	}

	ULogLoginedUserId = func(u *service.UserLogData, w http.ResponseWriter, r *http.Request) error {
		username := chi.URLParam(r, "username")
		if username == "" {
			return errors.New("username is empty")
		}
		u.TargetId = username
		return nil
	}

	ULogRoleId = func(u *service.UserLogData, w http.ResponseWriter, r *http.Request) error {
		id, err := strconv.Atoi(chi.URLParam(r, "roleId"))
		if err != nil {
			return err
		}
		u.TargetId = id
		return nil
	}

	ULogNewArticleId = func(u *service.UserLogData, w http.ResponseWriter, r *http.Request) error {
		articleIdStr := r.Context().Value("article_id")
		id, ok := articleIdStr.(int)
		if !ok {
			return errors.New("get article id failed")
		}

		u.TargetId = id
		return nil
	}

	ULogURLArticleId = func(u *service.UserLogData, w http.ResponseWriter, r *http.Request) error {
		id, err := strconv.Atoi(chi.URLParam(r, "articleId"))
		if err != nil {
			return err
		}
		u.TargetId = id
		return nil
	}
)

Functions

func AuthCheck

func AuthCheck(sessStore *sessions.CookieStore) func(http.Handler) http.Handler

func CreateGeoDetect

func CreateGeoDetect(geoDB *geoip2.Reader) func(http.Handler) http.Handler

func CreateUISettingsMiddleware

func CreateUISettingsMiddleware(sessStore *sessions.CookieStore, sm *service.SettingsManager, ic *i18nc.I18nCustom) func(http.Handler) http.Handler

func FetchUserData

func FetchUserData(store *store.Store, sessStore *sessions.CookieStore, permissionSrv *service.Permission, renderer any) func(http.Handler) http.Handler

func PermitCheck

func PermitCheck(permissionSrv *service.Permission, needPermissionIds []string, renderer Renderer) func(http.Handler) http.Handler

User must have at least one permisison id in needPermissionIds

func RequestDuration

func RequestDuration(next http.Handler) http.Handler

func UserLogger

func UserLogger(uLogger *service.UserLogger, actType model.AcType, action model.AcAction, targetModel model.AcModel, uHandlers ...UserLoggerFn) func(http.Handler) http.Handler

Types

type Renderer

type Renderer interface {
	ServerErrorp(msg string, err error, w http.ResponseWriter, r *http.Request)
	Forbidden(err error, w http.ResponseWriter, r *http.Request)
	GetLoginedUserData(r *http.Request) *model.User
}

type UserLoggerFn

type UserLoggerFn func(uLogData *service.UserLogData, w http.ResponseWriter, r *http.Request) error

Jump to

Keyboard shortcuts

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