GOLF(2gg)

πŸ“¦ version 601.4.41, in ubuntu questing

🌸 GOLF(2gg) β€” aka the begin-handler page, bestie edition 🌸

hey so this is a page from the GOLF(2gg) manual, section Development, and it's literally all about begin-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-handler
  • before-handler
  • begin-handler
  • call-handler
  • See all documentation

and that's the whole page!! ✨ version $VERSION, dated $DATE, and yeah the manual name is GOLF(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