feat: initial commit

This commit is contained in:
2025-02-21 18:42:56 +01:00
commit ee4a65b345
81 changed files with 3441 additions and 0 deletions

View File

@ -0,0 +1,28 @@
package context
import (
"context"
"net/url"
"github.com/pkg/errors"
)
const keyBaseURL = "baseURL"
func BaseURL(ctx context.Context) *url.URL {
rawBaseURL, ok := ctx.Value(keyBaseURL).(string)
if !ok {
panic(errors.New("no base url in context"))
}
baseURL, err := url.Parse(rawBaseURL)
if err != nil {
panic(errors.WithStack(err))
}
return baseURL
}
func SetBaseURL(ctx context.Context, baseURL string) context.Context {
return context.WithValue(ctx, keyBaseURL, baseURL)
}

View File

@ -0,0 +1,3 @@
package context
type key string

View File

@ -0,0 +1,23 @@
package context
import (
"context"
"net/url"
"github.com/pkg/errors"
)
const keyCurrentURL = "currentURL"
func CurrentURL(ctx context.Context) *url.URL {
currentURL, ok := ctx.Value(keyCurrentURL).(*url.URL)
if !ok {
panic(errors.New("no current url in context"))
}
return currentURL
}
func SetCurrentURL(ctx context.Context, u *url.URL) context.Context {
return context.WithValue(ctx, keyCurrentURL, u)
}

View File

@ -0,0 +1,23 @@
package context
import (
"context"
"github.com/markbates/goth"
"github.com/pkg/errors"
)
const keyUser = "user"
func User(ctx context.Context) *goth.User {
user, ok := ctx.Value(keyUser).(*goth.User)
if !ok {
panic(errors.New("no user in context"))
}
return user
}
func SetUser(ctx context.Context, user *goth.User) context.Context {
return context.WithValue(ctx, keyUser, user)
}