Skip to content

Go package for scopie, not prod ready

License

Notifications You must be signed in to change notification settings

miniscruff/scopie-go

Repository files navigation

Scopie

not production ready

Go implementation of scopie.

Basic Example

import (
    "log/slog"
    scopie "github.com/miniscruff/scopie-go"
)

func main() {
    allowed, err := scopie.IsAllowed(
        // optional variable values if we used any @vars
        map[string]string{},
        // an example user scope
        "allow/blog/post/create",
        // what our request requires
        "blog/post/create",
    )
    // If there was an error parsing a scope or rule.
    if err != nil {
        slog.Error("processing scopes", "error", err.Error())
        return
    }

    // Check the result to see if we can do this action.
    if !allowed {
        slog.Error("unauthorized")
        return
    }

    // User is allowed to create a blog post
}