1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
.TH GOLF 2gg $VERSION $DATE Development Tools
.SH NAME
command-line \- Golf documentation (running-application)
.SH DESCRIPTION
A Golf application can run as a web application or a command-line program, or both - such as when some requests can be either fulfilled through web interface or executed otherwise (such as on the command line). Note that Golf produces two separate executables: a \fBservice\fP one and a command-line one - they are different because command-line program does not need the service library and thus is smaller.
The name of the command-line executable is the same as the application name, and its path is (assuming <app name> is the application name):
.RS 4
.EX
/var/lib/gg/bld/<app name>/<app name>
.EE
.RE
.LP
.B OUTPUT
.LP
A command-line program works the same way as a service executable, and the output is the same, except that it is directed to stdout (standard output) and stderr (standard error).
.LP
.B EXIT CODE
.LP
To specify the exit code of a command-line program, use \fBexit-status\fP. To exit the program, use \fBexit-handler\fP, or otherwise the program will exit when it reaches the end of a \fBrequest\fP.
.LP
.B EXECUTING A REQUEST
.LP
Here is how to execute a request "add-stock" in application "stock" with parameters "name" having a value of "ABC" and "price" a value of "300":
.RS 4
.EX
gg -r --app="/stock" --req="/add-stock?name=ABC&price=300" --exec
.EE
.RE
Note that you if specify parameters as part of the path, you could write the above the same way as in a URL:
.RS 4
.EX
gg -r --app="/stock" --req="/add-stock/name=ABC/price=300" --exec
.EE
.RE
You can generate the shell code to execute the above without using \fBgg\fP by omitting "--exec" option, for instance:
.RS 4
.EX
gg -r --app="/stock" --req="/add-stock/name=ABC/price=300"
.EE
.RE
.LP
.B INCLUDING A REQUEST BODY
.LP
You can include a request body when executing a singe-run program. It is always included as the standard input (stdin) to the program.
You must provide the length of this input and the type of input, as well as a request method (such as POST, PUT, PATCH, GET, DELETE or any other).
Here is an example of using a request body to make a POST request on the command line - the application name is "json" and request name is "process". File "prices.json" is sent as request body:
.RS 4
.EX
gg -r --app=/json --req='/process?act=get_total&period=YTD' --method=POST --content=prices.json --content-type=application/json --exec
.EE
.RE
You can generate the shell code for the above by omitting "--exec" option of \fBgg\fP utility.
Note that you can also include any other headers as environment variables by using the "HTTP_" convention, where custom headers are capitalized with use of underscore for dashes and prefixed with "HTTP_", for example header "Golf-Header" would be set as:
.RS 4
.EX
export HTTP_GOLF_HEADER="some value"
.EE
.RE
You would set the "HTTP_" variable(s) prior to executing the program.
.LP
.B SUPPRESSING HTTP HEADER OUTPUT FOR THE ENTIRE APPLICATION
.LP
If you wish to suppress the output of HTTP headers for all requests, use "--silent-header" option in "gg -r":
.RS 4
.EX
gg -r --app="/stock" --req="/add-stock/name=ABC/price=300" --exec --silent-header
.EE
.RE
This will suppress the output of HTTP headers (either the default or with \fBout-header\fP), or for any other case where headers are output. This has the same effect as \fBsilent-header\fP, the only difference is that the environment variable applies to the entire application.
.LP
.B URL-ENCODING THE INPUT
.LP
Any data in "--req" option (and consequently in PATH_INFO or QUERY_STRING environment vairables if calling directly from shell) must be formatted to be a valid URL; for example, data that contains special characters (like "&" or "?") must be URL-encoded, for instance:
.RS 4
.EX
gg -r --app="/stock" --req="/add-stock/name=ABC%3F/price=300"
.EE
.RE
In this case, parameter "name" has value of "ABC?", where special character "?" is encoded as "%3F".
To make sure all your input parameters are properly URL-encoded, you can use Golf's v1 code processor:
.RS 4
.EX
$($(gg -l)/v1 -urlencode '<your data>')
.EE
.RE
For instance, to encode "a?=b" as a parameter:
.RS 4
.EX
gg -r --app="/stock" --req="/add-stock/name=$($(gg -l)/v1 -urlencode 'AB?')/price=300"
.EE
.RE
If your parameters do not contain characters that need URL encoding, then you can skip this.
.LP
.B CGI
.LP
You can also use a command-line program with \fBCGI\fP (Common Gateway Interface).
.SH SEE ALSO
Running application
\fBapplication-setup\fP
\fBCGI\fP
\fBcommand-line\fP
\fBservice\fP
See all
\fBdocumentation\fP
|