feat(module,auth): auth based on jwt
This commit is contained in:
28
pkg/module/util/assert.go
Normal file
28
pkg/module/util/assert.go
Normal file
@ -0,0 +1,28 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/dop251/goja"
|
||||
)
|
||||
|
||||
func AssertType[T any](v goja.Value, rt *goja.Runtime) T {
|
||||
if c, ok := v.Export().(T); ok {
|
||||
return c
|
||||
}
|
||||
|
||||
panic(rt.NewTypeError(fmt.Sprintf("expected value to be a '%T', got '%T'", new(T), v.Export())))
|
||||
}
|
||||
|
||||
func AssertContext(v goja.Value, r *goja.Runtime) context.Context {
|
||||
return AssertType[context.Context](v, r)
|
||||
}
|
||||
|
||||
func AssertObject(v goja.Value, r *goja.Runtime) map[string]any {
|
||||
return AssertType[map[string]any](v, r)
|
||||
}
|
||||
|
||||
func AssertString(v goja.Value, r *goja.Runtime) string {
|
||||
return AssertType[string](v, r)
|
||||
}
|
Reference in New Issue
Block a user