Skip to content

Instantly share code, notes, and snippets.

@dheeraj-326
dheeraj-326 / authorize_mw.go
Created October 3, 2025 09:43
Validation logic of a custom authorization solution (middleware function)
package middleware
import (
"encoding/json"
"errors"
"fmt"
"net/http"
"portal-api/domain"
"portal-api/internal/logger/repository/log"
"portal-api/internal/utils"
func (u workspaceUsecase) filterAuthorizedWorkspaces(
workspaceRows []domain.WorkspaceItem,
permissions domain.PermItem,
accessPath []string,
) (
[]domain.WorkspaceItem,
error,
) {
var workspaces []domain.WorkspaceItem
for _, ws := range workspaceRows {
/*
GenerateEffectivePermission
Recursively traverses user permissions and UI feature hierarchy to generate
effective user permissions for UI screen(s)
*/
func (a authUsecase) GenerateEffectivePermission(
ctx context.Context,
permRoot domain.PermItem,
featureRoot domain.PermItem,
uiPermRoot domain.PermItem,
func MatchPermission(
permission string,
pathPart string,
) (
bool,
error,
) {
permission = strings.ReplaceAll(permission, ".", "\\.")
permission = strings.ReplaceAll(permission, "*", ".*")
regex := "^" + permission + "$"
func CheckPermission(
permRoot domain.PermItem,
pathParts []string,
) (
bool,
error,
) {
if permRoot == nil || len(pathParts) == 0 {
return true, nil
}
@dheeraj-326
dheeraj-326 / authorize_mw.go
Last active December 1, 2022 04:19
Authorize middleware
package middleware
import (
"encoding/json"
"errors"
"fmt"
"net/http"
"portal-api/domain"
"portal-api/internal/utils"
"strconv"
@dheeraj-326
dheeraj-326 / README.txt
Created February 2, 2022 08:57
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.11+commit.d7f03943.js&optimize=false&runs=200&gist=
REMIX EXAMPLE PROJECT
Remix example project is present when Remix loads very first time or there are no files existing in the File Explorer.
It contains 3 directories:
1. 'contracts': Holds three contracts with different complexity level, denoted with number prefix in file name.
2. 'scripts': Holds two scripts to deploy a contract. It is explained below.
3. 'tests': Contains one test file for 'Ballot' contract with unit tests in Solidity.
SCRIPTS