MCPcopy Create free account
hub / github.com/devaccuracy/ledgerforge / getResourceFromPath

Function getResourceFromPath

api/middleware/auth.go:76–103  ·  view source on GitHub ↗

getResourceFromPath determines the resource type from the URL path. Parameters: - path: The URL path to analyze. Returns: - Resource: The determined resource type, or empty string if not found.

(path string)

Source from the content-addressed store, hash-verified

74// Returns:
75// - Resource: The determined resource type, or empty string if not found.
76func getResourceFromPath(path string) Resource {
77 // Remove leading slash and get first path segment
78 parts := strings.Split(strings.TrimPrefix(path, "/"), "/")
79 if len(parts) == 0 {
80 return ""
81 }
82
83 // Special case for mocked-account
84 if parts[0] == "mocked-account" {
85 return ResourceAccounts
86 }
87
88 // Special case for multi-search
89 if parts[0] == "multi-search" {
90 return ResourceSearch
91 }
92
93 if parts[0] == "refund-transaction" {
94 return ResourceTransactions
95 }
96
97 // Check if the path segment maps to a known resource
98 if resource, ok := pathToResource[parts[0]]; ok {
99 return resource
100 }
101
102 return ""
103}
104
105// injectAPIKeyToMetadata modifies the request body to include the API key ID in the meta_data.
106// This function reads the request body, adds or updates the meta_data field, and sets the modified

Callers 2

AuthenticateMethod · 0.85
TestGetResourceFromPathFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestGetResourceFromPathFunction · 0.68