superkit/view/view.go

32 lines
667 B
Go
Raw Normal View History

2024-06-06 10:04:51 +02:00
package view
import (
"context"
"net/url"
2024-06-06 16:02:04 +02:00
"github.com/anthdm/gothkit/kit"
"github.com/anthdm/gothkit/kit/middleware"
2024-06-06 10:04:51 +02:00
)
2024-06-06 16:15:35 +02:00
// Auth is a view helper function that returns the current Auth.
2024-06-06 10:04:51 +02:00
// If Auth is not set a default auth will be returned
func Auth(ctx context.Context) kit.Auth {
value, ok := ctx.Value(kit.AuthKey{}).(kit.Auth)
if !ok {
return kit.DefaultAuth{}
}
return value
}
// URL is a view helper that returns the current URL.
// The request path can be acccessed with:
// view.URL(ctx).Path
func URL(ctx context.Context) *url.URL {
value, ok := ctx.Value(middleware.RequestURLKey{}).(*url.URL)
if !ok {
return &url.URL{}
}
return value
}