GOLF(2gg)
okay so you just opened the GOLF(2gg) manual page, and the section is Development, and bestie it is LONG, so this is part 1 of 2 β grab a snack π and let's lock in.
β¨ NAME β¨
gg β (golf-compiler-and-utility)
π― PURPOSE π―
Golf general purpose utility: build, test, run, miscellaneous. and it's pronounced "gigi", no cap π
π SYNTAX π
gg <options>
πΈ DESCRIPTION πΈ
π« COMMAND-LINE OPTIONS π«
-k<app name>β creates a Golf application called<app name>with the default settings. (if you want non-default settings, go look atmgrgand its-ioption, that's the one for that.) and what even are the defaults, you ask? well: your app gets owned by the Operating System user who's currently logged on (peep the-uoption inmgrgfor that), and the Unix socket that connects to your application server isn't restricted by any group at all (that's the-roption inmgrg). you must have sudo privilege to create an application β and this is literally the only option that needs it, iconic. if the application already exists, this option does absolutely nothing, so don't stress. oh and you can combine it with-qto create and build an application in one single step, chef's kiss π₯-qβ builds a Golf application from the source code sitting in the current directory. heads up:mgrghas to run first in this directory with the-ioption to actually create the application. you need at least one Golf source file (a.golffile), and each one of those files implements a single request handler. all application source files have to live in a flat directory β but don't worry, each request handler can still handle any hierarchical path you want, so your API can be fully hierarchical. slay.
the following options can be used when building an application:
--db="<database vendor>:<db config file> ..."β tells Golf which databases your application uses. every element of the list is<database vendor>(which has to be'mariadb','postgres'or'sqlite'), then a colon (:), then<db config file>β and that config file is what you use to refer to a database in statements likerun-query. each<database vendor>:<db config file>pair is separated by a space, and you can list any number of databases for your app. a file in the current directory with the name<db config file>must exist and must contain the connection parameters for database access β it gets copied into Golf's database configuration directory (see directories). for more on what goes inside that file, checkdatabase-config-file. ποΈ--lflag=<linker flags>β if you wanna add any extra linker flags (like, say, any non-Golf libraries), put them in here, quoted. π--cflag=<C flags>β if you wanna add any extra C compiler (gcc) flags, drop them here, quoted.--traceβ if you pass this, tracing information code gets generated. (without it, tracing isn't available at all and thetrace-runstatement is just ignored, rip.) and lowkey important: tracing only works when debugging mode is enabled, so you have to use--debugas well. both or neither.--path=<application path>β lets you set the application path for your request URLs. it's the leading path of a URL, before the request name and any parameters. if it's empty, the default is the application name with a forward slash in front of it:
/<app name>
--maxupload=<max upload size>β sets the maximum upload size for a file, in bytes. the default is approximately 25MB.--max-errors=<max errors>β while building C code precompiled from.golfsource code,gccwill emit a maximum of<max errors>diagnostic messages per.golfsource file. the default is 5. note though that the Golf precompiler stops after the first error in most cases, and this setting does not apply to it.--debugβ debugging information is always included in Golf executables, even when it lives in separate.dbg(or.debug) files. so what's the--debugflag even for? it's only necessary if you're using tracing (seetrace-run), plus it's how you include additional run-time checks. > β οΈ do not use--debugunless you're a Golf upstream developer or maintainer, because it may significantly lower the run-time performance. you've been warned bestie π--c-linesβ skips generating line information when compiling.golffiles. by default line info is included, which is what lets errors get reported with line numbers in your.golffiles. if you'd rather only use generated C code line numbers, use this option. just know the output will omit certain color-coded and other details that are normally there without it. π¨--publicβ flips the default behavior of request handler safety, so that request handlers without a"public"or"private"clause are"public"by default. seebegin-handlerfor the full tea.--single-fileβ normally a request handler is written in a source file whose path matches fully or partially that of the request, and such a file can hold any number of matching request handlers (seerequest). but if you use--single-file, then every request has to be in its own file whose path matches the request path fully, and no other request can be implemented in that file. for example, with--single-file, request"/myreq"has to be in file"myreq.golf"in the source directory, while request"/other/newreq"has to be in file"other/newreq.golf"β meaning file"newreq.golf"inside subdirectory"other"in the source directory. one file, one request, periodt.--exclude-dirβ by default, all.golffiles get picked up for compilation, including ones in all subdirectories no matter how many levels deep they go. if you use--exclude-dir, then you can specify any number of subdirectories to exclude, separated by commas.--ignore-warnβ doesn't display any warnings during compilation of a Golf application. silence is golden β¨--parallel=<threads>β uses<threads>number of threads to compile the application. by default the number of threads equals the number of CPUs (including virtual ones), which lets each CPU compile one source file at a time β and that's usually the fastest way. you can serialize the compilation with--parallel=1, or set<threads>to any number between 1 and three times the number of CPUs to hit your own performance and CPU utilization goals. go off, multitasking queen π--posix-regexβ uses the ERE (Extended Regular Expression) POSIX regex library built into Linux instead of the default PCRE2, seematch-regex. the two are largely compatible, so you can use either one depending on your needs.--plain-diagβ don't use color-coded and more detailed Golf diagnostic output. it's rare, but you might need this in cases where there's a Golf or underlying compiler bug, or for some other reason. π-c,--cleanβ cleans all object and other intermediate files, so that the next application build is a full recompilation. use it alone and prior to rebuilding the application. π§Ό
π note that when anyggcompilation options change, the application is rebuilt (i.e. the change has the effect of--clean).
-iβ displays both include and linking flags for an application that uses Client-API to connect to Golf service. these flags are for the C compiler (gcc). if--includeis used in addition, then only include flags get displayed. if--linkis used in addition, then only linking flags get displayed. use this to automate building of client applications with tools likeMakefile. π€-vβ displays the Golf version as well as the Operating System version. β-sβ traces the execution of theggutility and displays all the steps in making your application. π-e<num of errors>β shows the last<num of errors>from the backtrace file, which receives the error message and stack trace whenever a program crashes orreport-erroris issued. it also displays the path to the backtrace file that contains the stack details. π-t<num of trace files>β shows the last<num of trace files>most recent trace files for the application. this is useful when tracing (seetrace-run) to quickly find the trace files where Golf writes to. it also displays the path to the backtrace file which contains the stack details.-oβ shows the documentation directory β the web page documentation lives here in the form of agolfdoc.htmlfile. π-gβ shows the Golf root directory (i.e. where Golf is installed, see directories).-lβ shows the library directory β Golf's libraries and the v1 code processor are located there.-rβ run a command-line program, or make a service request, or display bash code to do the same for use in scripts. here's the whole shape of it:
-r [ --req="/<request name>[<url parameters>]"
[ --app="application path" ]
[ --service [ --remote="server:port" ] [ --socket="socket path" ] ]
[ --method="<request method>" ]
[ --content="<input file>" --content-type="<content type>" ]
[ --silent-header ]
[ --arg="<arguments>" ]
[ --exec ]
if you're not in the application's source code directory, then you must specify the --app option to supply the application path (typically "/<application name>", see request). you can use the --req option to specify the request name and optional URL parameters (see request) β for example it may be:
gg -r --req="/encrypt" --exec
to execute request "encrypt", or:
gg -r --req="/encrypt/data=somedata?method=aes256" --exec
where "/encrypt" is the request name, and "/data=somedata?method=aes256" represents the URL parameters. π¦
use --method to specify the HTTP request method, for instance:
gg -r --req="/encrypt/data=somedata?method=aes256" --method=POST --exec
if it's not specified, the default method is "GET".
if --service is not used, then the command-line program will execute, and you can specify program arguments with the --arg option β in which case <arguments> is a string (double or single quoted) that contains any number of program arguments. to specify arguments for a service, see the -a option in mgrg.
If --service is on, then the application server gets pinged to run a service π« β and in that case, if --remote isn't specified, it's a local Unix socket doing the contacting; otherwise the server:port you put in --remote is the IP/name and port of the server to call, separated by a colon (:). For a local Unix socket, the socket path defaults to /var/lib/gg/<app name>/sock/sock, where /<app name> comes from the last path segment in the --app option, or β if you didn't set that β it's derived from the name of a Golf application built in the current directory; otherwise the socket path is whatever --socket says. π§
By default, the output is gonna have the HTTP headers, always. If you do NOT want those showing up, use --silent-header. π
If --content is used, then file <input file> is either piped to the standard input of a command-line program (when --service is not used), or sent as a content to the application server (when --service is used). You can also specify content type with --content-type. For example:
gg -r -app="/my_app" --req="/some_request?par1=val1&par2=20&par3=4" --method=PATCH --content=something.json --content-type=application/json --exec
Examples of using -r option to execute command-line program or to call a service:
#Execute current application as a command-line program, request "json"
gg -r --req="/json" --exec
#Execute application "app_name", service "json" by calling the application server running with a Unix socket
gg -r --req="/json" --app="/app_name" --service --exec
#Execute application "app_name", service "json" by calling the application server running with a Unix socket (specified explicitly)
#Request has input parameter "act" with value "perf"
gg -r --req="/json?act=perf" --app="/app_name" --service --socket="/sock_path/sock" --exec
#Execute application "app_name", service "json" by calling the application server running with a TCP socket on port 2301
#Request has input parameter "act" with value "perf"
gg -r --req="/json/act=perf" --app="/app_name" --service --remote="192.168.0.21:2301" --exec
π₯ Performance π₯
gg -r can be used both for testing and in production, but bestie, for maximum performance, skip the --exec option so it displays direct bash code that you can copy and paste to use in production. That direct code is about 300% faster than using gg -r β keep this in mind if performance of using gg -r is important. When --exec is not used, the output may look like this:
export CONTENT_TYPE=
export CONTENT_LENGTH=
unset GG_SILENT_HEADER
export GG_SILENT_HEADER
export REQUEST_METHOD=GET
export SCRIPT_NAME="/enc"
export PATH_INFO="/encrypt/data/somedata"
export QUERY_STRING="method=aes256"
/var/lib/gg/bld/enc/enc
If you copy the above and paste into bash shell, it will execute the command line program which handles the request specified (which gg would do when --exec is specified, but not as fast). Note that SCRIPT_NAME will be set to whatever application path you use (i.e. the default, or if set with --path option when making the application; or with --app option here), see request.
If you need to have run-time parameter(s) to gg -r, escape them when displaying the direct bash code and run with eval, for instance:
COMM=$(gg -r --req="/func_test/update-data/key=\$i/value=d_\$i" --service --remote="127.0.0.1:2301")
...
for i in {1..1000}; do
...
RES=$(eval "$COMM")
...
echo "Result is $RES"
done
In this example, the code with $i variable is created, and then evaluated in a bash loop of 1000 iterations, with each execution of your service using dynamic run-time input parameter $i, but without executing gg -r 1000 times. Obsessed, honestly. π
-uβ Read stdin (standard input) and substitute any environment variables in the form of${<var name>}with their values, and output to stdout (stdout). This is useful in processing configuration files that do not have parameter values hardcoded, but rather take them from the environment. π-mβ Add Golf syntax and keyword highlighting rules for files with.golfextension to Vim editor for the currently logged on user. Note that you must have Vim installed;vialone will not work. π--manβ Display list of all man pages for Golf, along with the section that each belongs to (i.e."string","web","program-flow"etc).-hβ Display help. π«Ά
π EXAMPLES π
- Make application (
-q), use three databases (--db) namedmdb(MariaDB database),pdb(PostgreSQL) andsdb(SQLite), produce debugging information (--debug), produce tracing information (--trace):
gg -q --db="mariadb:mdb postgres:pdb sqlite:sdb" --debug --trace
- make application, use MariaDB database
db(--db), specify linker and C compilation flags, specify maximum upload size of about 18M:
gg -q --db="mariadb:db" --lflag "-Wl,-z,defs" --cflag "-DXYZ123" --maxupload 18000000
- Make application that doesn't use any databases:
gg -q
π¦ SEE ALSO π¦
- Golf compiler and utility
ggSee all documentation
That's the whole thing, bestie β this page is from the $DATE era and it's rocking version $VERSION π no cap, go build something iconic with it β¨π
π¦ 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