weiro/models/ctx.go
Leon Mika 199ff9feb9 More changes to uploads:
- Have got upload images appearing in the post list
- Allowed for deleting uploads
- Allowed for seeing the upload progress
- Fixed the setting of upload properties like the MIME type
- Removed the stripe exif logic with just re-encoding PNGs and JPEGs by loading them and saving them
2026-03-04 22:33:39 +11:00

33 lines
671 B
Go

package models
import "context"
type userKeyType struct{}
type siteKeyType struct{}
var userKey = userKeyType{}
var siteKey = siteKeyType{}
func WithUser(ctx context.Context, user User) context.Context {
return context.WithValue(ctx, userKey, user)
}
func GetUser(ctx context.Context) (User, bool) {
user, ok := ctx.Value(userKey).(User)
return user, ok
}
func WithSite(ctx context.Context, site Site) context.Context {
return context.WithValue(ctx, siteKey, site)
}
func GetSite(ctx context.Context) (Site, bool) {
site, ok := ctx.Value(siteKey).(Site)
return site, ok
}
func MustGetSite(ctx context.Context) Site {
site, _ := GetSite(ctx)
return site
}