GOLF(2gg)
π GOLF(2gg) π
okay bestie, this is the GOLF manual, section 2gg, under Development. pull up a chair, grab a strawberry π, and let's get into it.
β¨ NAME β¨
get-req β (request-information)
π― PURPOSE π―
Obtain data that describes the input request. literally that's the whole job, and she does it flawlessly π
π SYNTAX π
get-req \
errno | error | cookie-count | cookie <cookie index> \
| arg-count | arg-value <arg index> \
| header <header> | referring-url | method \
| content-type | trace-file | process-id | name \
| external-call | directory | source-file
to <variable>
π¦ DESCRIPTION π¦
So the tea is: you can grab all sorts of info about an input request with the get-req statement, and the result goes straight into <variable> (that's the to clause, bestie, don't forget it π«Ά). here's everything you can pull (all of these are strings except where it says otherwise, no cap):
errnoβ gets you the integer value of the operating system'serrno, tied to the last Golf statement that can return a status code. theerrnovalue gets saved internally and restored here, which means even iferrnochanged for literally any reason since that Golf statement (like, say, viacall-extended), you'll still get the correct value. checkerror-codefor an example π heads up though: theerrnovalue is undefined if there's no error, and it can be0if the error was reported by Golf itself and not by the operating system. πerrorβ returns the error message that correlates to theerrnovalue.cookie-countβ returns the number of cookies. and by "number of cookies" we mean: any cookies received from the client, plus any cookies added (withset-cookie) in the application, minus any cookies deleted (withdelete-cookie). math is mathing, slay.cookieβ returns the cookie value specified by<cookie index>, which is a sequential number starting with1up to the number of cookies. for instance:
get-req cookie-count to cookie_c
start-loop repeat cookie_c use i
get-req cookie i to cookie_val
print-format "cookie %s\n", cookie_val web-encode
@<br/>
end-loop
in this example, we get the number of cookies, and then print out each cookie value. iconic behaviour, honestly. β¨
arg-countβ the number of input arguments to your application (passed from a program caller, see the-aoption inmgrgand--argingg).arg-valueβ the string value of a single element from the array of input arguments, specified by<arg_index>. this array is indexed from1to the value you get fromarg-count. here's an example usingarg-countandarg-valuetogether:
get-req arg-count to ac
print-format "Total args [%ld]", ac
start-loop repeat ac use i
get-req arg-value i to av
print-format "%s\n", av
end-loop
this code displays the number of input arguments (as passed to the main() function of your program, excluding the first argument which is the name of the program), and then all the arguments. if there are no arguments, then variable 'ac' would be 0. simple as π
headerβ the value of the HTTP request header<header>that's set by the client. for example, if the HTTP request contains header"My-Header:30", thenhvalwould be"30":
get-req header "My-Header" to hval
ngl, not all HTTP request headers are set by the caller. for example,SERVER_NAMEorQUERY_STRINGare set by the web server, and to get such headers, useget-sys. π§
methodβ the request method. it's a number with values ofGG_GET,GG_POST,GG_PUT,GG_PATCHorGG_DELETEfor GET, POST, PUT, PATCH or DELETE requests, respectively. if it's not any of those commonly used ones, then the value isGG_OTHER, and you can useget-syswith theenvironmentclause to obtain theREQUEST_METHODvariable. periodt. π₯content-typeβ the request content type. it's a string and generally denotes the content type of a request-body, if one is included in the request. common examples are"application/x-www-form-urlencoded","multipart/form-data"or"application/json".referring-urlβ the referring URL (i.e. the page from which this request was called, for example by clicking a link). the origin story, if you will πdirectoryβ the current working directory, which by default is the application home directory (seedirectories) and can be changed withchange-dir. > lowkey important: the maximum length of a directory path should not exceed1024bytes. don't test her.trace-fileβ the full path of the trace file for this request (if enabled, seetrace-run).process-idβ the"PID"(process ID) number of the currently executing process, as a number.external-callβ a boolean that istrueif the call to the current request handler is from an external caller, orfalseif called from another handler.source-fileβ the name of the current source file (a string).nameβ the request name as specified in the request URL.
π EXAMPLES π
get the name of the current trace file:
get-req trace-file to trace_file
look at her go. chef's kiss π
π SEE ALSO π
- Request information
get-reqSee all documentation
that's the whole page, bestie! this was GOLF(2gg), version $VERSION, dated $DATE. go forth and get-req responsibly πβ¨ππ¦πΈπ π«Ά
π¦ 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