GOLF(2gg)
πΈ GOLF(2gg) β aka the begin-handler page, bestie edition πΈ
hey so this is a page from theGOLF(2gg)manual, section Development, and it's literally all aboutbegin-handler. let's get into it π
β¨ NAME β¨
begin-handler β (service-processing) π«Ά
π PURPOSE π
Define a request handler. that's it. that's the whole job. iconic honestly β¨
π¦ SYNTAX π¦
begin-handler <request path> [ private | public ]
<any code>
end-handler
like... that's the shape of it. <request path>, then optionally private or public, then whatever code you want, then you close it out with end-handler. periodt. π
π DESCRIPTION π
begin-handler starts the implementation of a request handler for <request path> (peep request for that one), and the handler is <any code> all the way up until end-handler. and bestie, listen β <request path> is not quoted. no quotes. none. don't do it. π«
A <request path> is a path made of any number of path segments. it can have alphanumeric characters, hyphens and forward slashes, and it can only start with a forward slash. that's the rule, no cap.
so for example, a <request path> can be "/wine-items" or "/items/wine" etc. in general it represents the nature of a request β like an action on an object, a resource path handled by it, that kind of thing. there's no specific way to interpret a request path, so you can construct it however works for you. it's giving "you do you" energy fr fr. π
okay so here's the cute part: the source ".golf" file name that implements a given begin-handler matches its path and name, fully or partially (again, see request). so for example, <request path> of "/items/wine" might be implemented in the "items/wine.golf" file β which means the file "wine.golf" sitting in the subdirectory "items". see how that lines up? obsessed. π§
also note that you can use "%%" instead of either begin-handler or end-handler or both. and heads up: a <request path> cannot be a C reserved word β like for instance "main" or "typedef" etc. so don't try it. π
π SECURITY OF REQUEST CALLS π
if the "public" clause is used, then a handler can be called from an outside caller β be it a web browser, some web service, service call or command-line program. it's out there, it's social, it's main character energy. π
if the "private" clause is used, then a handler cannot be called from an outside caller. it can only be called from another handler by using the call-handler statement. no randos allowed. π
if neither "public" nor "private" is used, then the default is "private". and this default mechanism automatically guards direct execution by outside callers of all handlers not marked "public" β it provides an automatic safety guard. so like, your stuff is safe by default, you don't even have to think about it. slay. π‘οΈ
you can change this default behavior with the "--public" option in gg, in which case the default becomes "public". this is useful if either all request handlers should be public, or if only a handful fixed ones are private. your call, bestie. π
π₯ EXAMPLES π₯
the following begin-handler is implemented in the file "items/wines/red-wine.golf":
begin-handler /items/wines/red-wine public
@This is a request handler to display a list of red wines!
end-handler
another way to write this is:
%% /items/wines/red-wine public
@This is a request handler to display a list of red wines!
%%
same thing, different flavor. both ate. π·β¨
π SEE ALSO π
- Service processing
after-handlerbefore-handlerbegin-handlercall-handler- See all documentation
and that's the whole page!! β¨ version$VERSION, dated$DATE, and yeah the manual name isGOLF(2gg)in case you forgot β it's in the Development section. go forth and define some request handlers, bestie, you got this πππ¦
π¦ 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