Go4lage logo

Go4lage Documentation

Guide


In this guide, we explain general aspects of Go4lage. The main idea is that classic documentation is unnecessary as the code is so simple. Just read the source code and see how this documentation is made as well.

Lightning-Fast In-Memory Processing with Smart Goroutine Communication

Go4lage leverages a powerful feature that sets it apart from traditional web backends: smart communication between concurrent processes (goroutines). While most frameworks process requests in isolation, our goroutines work together through a sophisticated shared memory system.

How it works:

When requests come in, they're processed concurrently in separate goroutines - a core feature of Go. What makes go4lage special is that these goroutines maintain constant communication with each other. This creates a natural, built-in caching layer that lives in memory, dramatically reducing database load.

Benefits:

  • Even without caching, go4lage outperforms Java, JavaScript, PHP, and Python
  • With our shared memory system, the performance gap widens significantly
  • Database queries are minimized through intelligent caching
  • Zero configuration needed - it works out of the box

Real-World Application:

We've implemented this system for user management and permissions, demonstrating its simplicity and effectiveness. Developers can easily extend this pattern to other parts of their application, gaining immediate performance benefits.

Technical Consideration:

This feature is optimized for monolithic applications, as the inter-goroutine communication requires processes to run on the same instance. While horizontal scaling isn't supported at the application layer, you maintain full flexibility to scale your database layer, including compatibility with managed database services.

Ideal Use Case:

Choose go4lage when you need exceptional performance in a monolithic architecture. The built-in memory sharing system provides a powerful advantage for applications that prioritize speed and efficient resource usage.

Think of it like this: In your frontend or app you want to reduce backend calls. In go4lage you want to reduce db calls.

Go4lage as Static File Server

In the directory, there is a 'root' folder. Go4lage will copy the content from this folder into the cache. It will replace components with a Jinja-like syntax and will replace API endpoints accordingly.

  • index.html is the default entry point for the plain URL.
  • The admin/ folder is the default folder for the admin dashboard.

The files are also cache-busted - they are renamed at startup, and a random string is added so you can cache aggressively with your main reverse proxy.

The main goal of the static file server is to be able to serve the complete project from one package. A landing page and the main app as well. see React Vite Integration

Groups and Permissions

Go4lage comes with a group and permission system.

In go4lage the groups and permissions are simple strings.

Users have groups and groups have permissions. A group is also a permission.

If you have a simple app then using only groups might be good enough.

AuthMiddleware comes with two string options. groups and permissions.

go
      r.Use(app.AuthMiddleware("staff", "")) 
    

In this example every user that has the group "staff" can use the endpoint.

go
      r.Use(app.AuthMiddleware("controller", "can_do_something")) 
    

In this example every user with the group "controller" can access the endpoint, AND every user with the permission "can_do_something"

Also normal users have to be set to active. Superusers can always access everything.

If you need to go more complex you can add the permissions also to groups. For this you can code this in setup.go there is an example provided. see func SetupGroupsAndPermissions() Or you can manage this manually later via the admin dashboard gui.

If you need to implement permissions on specific db objects you need to implement your own checks

Go4lage serving react vite

Go4lage can serve a react vite pwa directly. But this it not a must as a pwa can be served from another url as well.

For this to happen, simply adjust the vite config to build in the root folder and disable vite's cache busting and use an app name instead. Go4lage has it's own cache busting.

#vites.config.ts
export default defineConfig({
  plugins: [react()],
  build: {
    outDir: '../root',
    emptyOutDir: false,
    rollupOptions: {
      output: {
        entryFileNames: 'assets/[name]-app.js',
        chunkFileNames: 'assets/[name]-app.js',
        assetFileNames: 'assets/[name]-app.[ext]',
      },
    },
  },
})

In the API class or function you need to have the const apiUrlstring = '{ % Apiurl % }' without space. This will be automatically replaced in production code with the Api url and still work in dev mode.

#api.tsx
class API {
  apiUrl: string
  constructor() {
    const apiUrlstring = '{ %A piurl % }' // without space

    const trimmedString = apiUrlstring.slice(2, -2).trim()

    if (trimmedString === 'Apiurl') {
      this.apiUrl = 'http://127.0.0.1:8080/adminapi'
    } else {
      this.apiUrl = apiUrlstring + '/adminapi'
    }
  }

Go4lage build in commands

Go4Lage comes with CLI commands that are powered by cobra. That help you to develop or to get things done. They are defined in the main.go file.

startserver

./go4lage startserverThis starts the server. It is often used straight after build: go build && ./go4lage startserver

createsuperuser

./go4lage createsuperuserThis creates a superuser. Use this at least one time, then you can use the /admin dashboard

createfakeusers

./go4lage createfakeusers 100This creates 100 fakeusers for testing.

setupgp

./go4lage setupgpThis creates hard coded groups and permissions. It is only aditive and will not delete anything.

rungoose

This is your wrapper on the database. you can very simple reset your data or remigrate with this. Those are the most important, and even faster than switching a sqlLite db.:

  • ./go4lage rungoose up
  • ./go4lage rungoose down This runs one downmigration, you have to confirm this with y.

Nginx config

Go4lage can run with any reverse proxy or even without one. However I recommend using nginx for SSL and as a balancer if you want to run more than just one instance of Go4lage on a server.

We warmly recommend certbot https://certbot.eff.org/ for SSL.

This is Go4lages Nginx config, you can probably cache for longer...:

#nginx config
server {
    listen 80;
    server_name go4lage.com www.go4lage.com;
    return 301 https://go4lage.com$request_uri;
}

server {
    listen 443 ssl;
    server_name www.go4lage.com;
    ssl_certificate /etc/letsencrypt/live/go4lage.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/go4lage.com/privkey.pem;
    return 301 https://go4lage.com$request_uri;
}

server {
    listen 443 ssl;
    server_name go4lage.com;
    client_max_body_size 10M;
    ssl_certificate /etc/letsencrypt/live/go4lage.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/go4lage.com/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    add_header Cache-Control "public, max-age=3600";

    location / {
        proxy_pass http://127.0.0.1:8088;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}