GOLF(2gg)

NAME
about-golf - Golf documentation (general)

DESCRIPTION

WHAT IS IT

Golf is a memory-safe and high-performance programming language and application server. Golf is a compiled language that creates native executables. It's main purpose is easy and rapid development and deployment of web services and applications on Linux back-end.

Golf is built with industry-standard Free Open Source libraries, extensible with C programming language, and licensed under Apache 2 Free Open Source.

SERVICE ORIENTED

A Golf program works as a service provider, meaning it handles service requests by providing a reply. It can be either a service or a command-line program that processes GET, POST, PUT, PATCH, DELETE or any other HTTP requests.

The URL for a request must state the application name, and a also request name which is the source file handling it. So, "/app-name/my-request" means that application name is "app-name" and that "request_name.golf" file will implement a request handler. A request executes in this order:

    • An optional before-handler handler executes (see before-handler).

    • Golf's request dispatcher executes a request handler.

    • An optional after-handler handler executes (see after-handler).

RUNNING AS A SERVICE

A Golf service is served by either

    • a fixed number of service processes, or

    • a dynamic number based on the request load, from 0 to any maximum number specified.
Each Golf service process handles one request at a time, and all such processes work in parallel. This means you do not need to worry about thread-safety with Golf. Server processes generally stay up across any number of requests, increasing response time. The balance between the number of processes and the memory usage during high request loads can be achieved with adaptive feature of mgrg, Golf's service process manager.

A service can be requested by:

    • reverse proxies, such as Apache, Nginx, HAProxy etc.,

    • programs written in any language using Client-API,

    • Golf's own gg utility (see -r option)

    • another Golf service by means of call-remote (on secure networks) and call-web (on the web via SSL/TSL secure connections).

With call-remote, you can execute remote requests in parallel, and get results, error messages and exit status in a single statement. This makes it easy to distribute and parallelize your application logic and/or build application tiers on a local or any number of remote machines, without having to write any multi-threaded code.

COMMAND-LINE PROGRAM

A command-line program handles a single request before it exits. This may be suitable for batch jobs, for use in shell scripts, for testing/mocking, as well as any other situation where it is more useful or convenient to execute a command-line program. Note that a command-line program can double as CGI (Common Gateway Interface) as well.

USAGE

Golf services and command-line programs can implement most back-end application layers, including

    • presentation (eg. building a web page),

    • application logic,

    • data (eg. database) layers, and any others.

LANGUAGE AND SAFETY

Golf programming language is memory-safe, meaning it will prevent you from accidentally overwriting memory or freeing it when it shouldn't be. Golf's memory-handling is not limited to just memory safety; it also includes automatic freeing of memory at the end of a request, preventing memory leaks which can be fatal to long running processes. Similarly, files open with file-handling statements are automatically closed at the end of each request, serving the same purpose.

Golf goes a step further from memory safety. It also enforces status checking for statements that may cause serious application logic errors. This is done by checking for negative status outcome at run-time, but only if your code does not check for status, and by stopping the application if it happens. This provides for much safer application run-time because it prevents further execution of the program if such outcome happens, and it also forces the developer to add necessary status checks when needed. This feature is automatic and has an extremely low impact on performance.

TYPES

Golf is a strongly-typed language, with only three primitive types (numbers, strings and booleans) and a number of structured types (message, split-string, hash, tree, tree-cursor, fifo, lifo, list, file and service). Golf is a declarative language, with a few lines of code implementing large functionalities. Golf is also very simple - it's near expression-free! That's because it's designed to achieve application goals with less coding.

The number type is a signed 64-bit integer (as a decimal, octal or hexadecimal C notation). The boolean type evaluates to true (non-zero) or false (zero). The string type evaluates to any sequence of bytes (binary or text) that is always trailed with a null character regardless, which is not counted in string's length. All constants follow C rules of formatting.

STATEMENTS

Golf statements are designed for safety, ease of use, and ability to write stable code. Most statements typically perform common complex tasks with options to easily customize them; such options are compile-time whenever possible, increasing run-time performance.

VARIABLES, SCOPE

A variable is created the first time it's encountered in any given scope, and is never created again in the same or inner scopes, which avoids common bugs involving more than one variable with the same name in related scopes. You can still of course create variables with the same name in unrelated scopes.

Some structured types (hash, tree, list) as well as primitive types (numbers, strings and booleans) can be created with process-scope, meaning their value persists throughout any requests served by the same process. This is useful for making services that allow keeping and fast querying of data (such as caches).

Numbers and booleans are assigned by value, while strings are assigned by reference (for obvious reason to avoid unnecessary copying).

INFRASTRUCTURE

Golf includes request-processing and all the necessary infrastructure, such as for process management, files, networking, service protocols, database, string processing etc.

PERFORMANCE

Golf is a compiled language. Golf applications are high-performance native executables by design, hence absolutely no byte-code, interpreters and similar. Since Golf is declarative, just a few statements are needed to implement lots of functionality. These statements are implemented in pure C, and are not slowed down by memory checks as they are safe internally by implementation. Only developer-facing Golf code needs additional logic to enforce memory safety, and that's a very small part of overall run-time cost. This means Golf can truly be memory-safe and high-performance at the same time.

DATABASE ACCESS

Golf provides access to a number of popular databases, such as MariaDB/mySQL, PostgreSQL and SQLite. (see database-config-file):

    • transactional support (begin, commit, rollback),

    • protection against SQL injections for safety,

    • automatic and persistent database connections with unlimited reuse across all SQL queries for high performance,

    • prepared SQL statements for high performance.

PROVEN LIBRARIES

Golf uses well-known and widely used Free Open Source libraries like cURL, OpenSSL, crypto, FastCGI, standard database-connectivity libraries from MariaDB, PostgreSQL, SQLite etc., for compliance, performance and reliability.

WEB FRAMEWORK FOR C PROGRAMMING LANGUAGE

In extended mode, Golf is also a web-framework-for-C-programming-language.

NAMES OF OBJECTS

Do not use object names (such as variables and request names) that start with "_gg_" or "gg_" (including upper-case variations) as those are reserved by Golf.

HISTORY

Golf programming language (or golf-lang) was created by Sergio Mijatovic, formerly Senior Software Engineer with Oracle server engineering group. Golf was originally known as Vely (since 2018), before being redesigned into Golf in late 2024.

SEE ALSO
 General

about-golf directories permissions See all documentation