GOLF(2gg)
GOLF(2gg) β the call-handler page, bestie edition π
okay so you're in the GOLF manual, section 2gg (Development), and this is the glow-up of call-handler. sit down, hydrate, let's get into it β¨
πΈ NAME πΈ
call-handler β (service-processing program-flow)
π PURPOSE π
Call another handler within the same process. that's it, that's the whole vibe. one process, one little handler-to-handler phone call π
β¨ SYNTAX β¨
call-handler <request path> [ return-value <return value> ]
π¦ DESCRIPTION π¦
So here's the tea: call-handler calls another handler, inside the same request, inside the same process. You can call literally any handler within the same application. and when we say "calling a handler," we mean executing it solely within the context of the top handler currently running β so no before-handler and no after-handler will run for the called handler. none. zero. not invited to the party π
<request path> is the request path served by the handler you're calling. It can be a string variable or a constant β your call, bestie.
Wanna pass params between the caller and the callee handlers? Use set-param and get-param. that's the group chat DM channel between them π
You can grab a <return value> from the called handler <request path> by using the return-value clause. and if you're wondering how to return a number value from a <request path> handler, go read return-handler β it's the whole tutorial, no cap.
oh and this part is iconic: call-handler uses the same high-performance hash table that a request uses to route requests by name. so if <request path> is a constant string, the hash table lookup happens only once for the life of the process, and all subsequent calls just use a cached address of the request handler. fast. efficient. main character energy π₯
π EXAMPLES π
The following example demonstrates calling a call-handler twice, and also using its output inline in the caller. An input parameter is passed to it, and an output obtained:
Copy to file "callsub.golf":
%% /callsub public
//
// First call to call-handler
//
// Set input for call-handler
set-param inp = "some string"
(( s
call-handler "/sub/service"
))
// Get output from call-handler
get-param out type string
@<<print-out s>> with output [<<print-out out>>]
//
// Second call to call-handler
//
// Set input for call-handler called as inline code
set-param inp = "new string"
(( s
@Output: <<call-handler "/sub/service">>
))
// Get output from call-handler
get-param out type string
@<<print-out s>> with output [<<print-out out>>]
%%
And in "sub/service.golf" file (meaning file "service.golf" in subdirectory "sub"):
%% /sub/service private
@This is sub!
get-param inp
(( out
@got input: <<print-out inp>>
))
set-param out = out
%%
Create and build an application:
gg -k subhandler
gg -q
Run it:
gg -r --req="/callsub" --exec --silent-header
The output:
This is sub! with output [got input: some string]
Output: This is sub! with output [got input: new string]
π SEE ALSO π
Program flow β go read these too, they're all part of the lore:
break-loopcall-handlercode-blockscontinue-loopdo-onceexit-handlerif-definedif-truequit-processreturn-handlerstart-loop
Service processing:
after-handlerbefore-handlerbegin-handlercall-handler
See all documentation π
okay that's the page!! this one's from $VERSION and dated $DATE β signed, sealed, slayed, and filed under GOLF(2gg) π«Άβ¨
π¦ where this page comes from
- ubuntu questing: golf 601.4.41-1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms