Friday, November 29, 2024

Golf 117 released

  • Added external-call clause to get-req statement. It returns true if the current request handler is called directly from an external entity (web browser, an outside API call, curl call, command line etc.), or false if called from another handler. This allows for greater flexibility in formulating web service's response and its output parameters. 

Tuesday, November 26, 2024

Golf 114 released

  • call-handler statement is now 2.1 times faster. Only the very first call to a local request uses hash table to find it; all subsequent ones use a cached request address. Note that this is true only if the request name is a string constant and not a variable (in which case it's resolved via hash table every time still). However, in most applications request name is a constant string nearly 100% of the time. 

Friday, November 22, 2024

Golf 109 released

  •  New "-k" option in gg utility will create a new Golf application, if it didn't already exist. You can still use mgrg utility to create new applications. This option makes it easier to create one with all the default settings. You can also use "-q" flag to compile and make the executable in a single step.

How to create Golf application

To create Golf application with default settings use an option of gg utility:

gg -k my-app

where "my-app" is your application name. If you already have an application with that name, nothing is done, so this is an idempotent operation.

If you already have source code, you can create and compile your application in one step:

gg -k my-app -q

which is a neat shortcut.

What's default settings? Well, it means your application directory (in "/var/lib/gg/my-app") will be owned by the currently logged on user (and other users can't access it), and any Unix socket can connect to your application server. This is a typical setup you'd probably use in most cases, so it's a useful one.

If you'd like to have more options in creating a Golf application, see service manager).

Thursday, November 21, 2024

Getting help for Golf with man pages

Golf installation will create Linux "man" pages (or manual pages). 

They contain the same information as the web documentation, and you can use them for a quick help on syntax even when you're working offline.

For instance to get help on "call-web" statement, you would enter in command line:

man call-web

The result would be something like:


Note that the man section for Golf is "2gg".


Tuesday, November 12, 2024

Multi-tenant SaaS (Notes web application) in 200 lines of code

This is a complete SaaS example (Software-as-a-Service) using PostgreSQL as a database, and Golf as a web service engine; it includes user signup/login/logout with an email and password, separate user accounts and data, and a notes application. All in about 200 lines of code!

First create a directory for your application, where the source code will be:
mkdir -p notes
cd notes

Setup Postgres database
Create PostgreSQL user (with the same name as your logged on Linux user, so no password needed), and the database "db_app":
echo "create user $(whoami);
create database db_app with owner=$(whoami);
grant all on database db_app to $(whoami);
\q"  | sudo -u postgres psql

Create a database configuration file to describe your PostgreSQL database above:
echo "user=$(whoami) dbname=db_app" > db_app

Create database objects we'll need - users table for application users, and notes table to hold their notes:
echo "create table if not exists notes (dateOf timestamp, noteId bigserial primary key, userId bigint, note varchar(1000));
create table if not exists users (userId bigserial primary key, email varchar(100), hashed_pwd varchar(100), verified smallint, verify_token varchar(30), session varchar(100));
create unique index if not exists users1 on users (email);" | psql -d db_app

Create Golf application
Create application "notes" owned by your Linux user:
sudo mgrg -i -u $(whoami) notes

Source code
This executes before any other handler in an application, making sure all requests are authorized, file "before-handler.golf":
vi before-handler.golf

Copy and paste:
 before-handler
     set-param displayed_logout = false, is_logged_in = false
     call-handler "/session/check"
 end-before-handler


- Signup users, login, logout

This is a generic session management web service that handles user creation, verification, login and logout. Create file "session.golf":
vi session.golf

Copy and paste:

Sunday, November 10, 2024

Golf 91 released

  • Fixed SELinux installation bug for Fedora-like distros.
  • Minimum number of CPUs available is 1 in case there's an issue in determining the number of them.
  • Fixed issue with highlighting call-handler statement in vim.

Tuesday, November 5, 2024

Golf 87 released

  • Added --exclude option to gg in order to exclude sub-directories from compilation.
  • Added p-source-line and p-source-file statements to aid in debugging.
  • A request handler can now be defined in any source file whose path matches, partially or fully, the request path of the handler. For instance /session/login request handler can be defined either in file "session.golf" or "session/login.golf". A source file can also have multiple request handlers that match path.
  • Added --single-file option to gg to force each source code file to have just a single request handler.
  • set-param and get-param statements now work with multiple parameters separated by a comma.
  • set-cookie and get-cookie statements now work with multiple cookies separated by a comma.
  • Fixed bug in end-write-string statement where junk text at the end would be ignored without an error message.
  • Fixed error in parallel compilation.
  • Fixed bug in get-param where parameter name wouldn't be correct.
  • Fixed bug where a function in call-extended statement wouldn't work without any parameters.