### Download Example Config File Source: https://gotify.net/docs/config Use wget to download the example configuration file from the specified URL. ```bash $ wget -O config.yml https://raw.githubusercontent.com/gotify/server/master/config.example.yml ``` -------------------------------- ### Start Backend Development Server Source: https://gotify.net/docs/dev-server-and-tests Starts the Go backend server in development mode. Ensure the UI is built first. ```bash go run . ``` -------------------------------- ### Start UI Development Server Source: https://gotify.net/docs/dev-server-and-tests Starts the UI development server. This command must be executed inside the ui directory. The UI requires a Gotify server running on localhost:80. ```bash yarn start ``` -------------------------------- ### Start Gotify Server Source: https://gotify.net/docs/plugin-deploy Start the Gotify server after deploying the plugin. The server will automatically load plugins from the configured plugins directory. ```bash gotify ``` -------------------------------- ### Install UI Dependencies with Yarn Source: https://gotify.net/docs/dev-setup Download and install dependencies for the Gotify UI using Yarn. Ensure you are inside the 'ui' directory before running this command. ```bash yarn ``` -------------------------------- ### Run Gotify Server with Docker Source: https://gotify.net/docs/install Start the gotify/server Docker container. Ensure the data directory is mounted for persistence and consider configuring the timezone with the TZ environment variable. ```bash $ docker run -p 80:80 -v /var/gotify/data:/app/data gotify/server ``` ```bash $ docker run -p 80:80 -v /var/gotify/data:/app/data ghcr.io/gotify/server ``` ```bash $ docker run -p 80:80 -e TZ="Europe/Berlin" -v /var/gotify/data:/app/data gotify/server ``` -------------------------------- ### Example Server Environment Variables Source: https://gotify.net/docs/config Save these variables as `gotify-server.env` or export them. Variables already exported in the process environment take precedence. If `$GOTIFY_CONFIG_FILE` is set, only that file is loaded. ```env # Example environment variables for the server. # Save as `gotify-server.env` (or export the variables) when edited. # If $GOTIFY_CONFIG_FILE is set, that file is loaded exclusively and none of # the files below are tried. Otherwise the first existing file from the search # order is loaded. Absent or commented out settings fall back to the default # (shown after the =). Variables already exported in the process environment # always take precedence over the loaded file. # Config file search order (used only when $GOTIFY_CONFIG_FILE is unset): # 1. gotify-server.env (in the working directory) # 2. $XDG_CONFIG_HOME/gotify/gotify-server.env # ($XDG_CONFIG_HOME falls back to $HOME/.config when unset) # 3. /etc/gotify/server.env # Value types used below: # text a plain string value. # number an integer value. # boolean `true` or `false`. # text-list comma-separated list of strings, parsed as a single CSV line. # A comma can be escaped by wrapping the value in quotes. # Example: a,b,c # Example: "a,b",c -> entries: `a,b` and `c` # json-map a JSON object mapping string keys to string values. # Example: {"X-Foo":"bar","X-Baz":"qux"} # Every variable also supports a "_FILE" suffix that reads the value from a # file at the given path (useful for Docker / Kubernetes secrets), e.g.: # GOTIFY_DEFAULTUSER_PASS_FILE=/run/secrets/admin_pass ``` -------------------------------- ### Systemd Commands for Gotify Service Management Source: https://gotify.net/docs/systemd These bash commands are used to set up and manage the Gotify systemd service. They include creating log directories, setting permissions, linking the service file, reloading systemd, enabling the service to start on boot, and starting the service. ```bash sudo mkdir /var/log/gotify sudo chmod -R go-rw /opt/gotify /etc/gotify/config.yml /var/log/gotify sudo ln -s /opt/gotify/gotify.service /etc/systemd/system/gotify.service sudo systemctl daemon-reload sudo systemctl enable gotify ``` ```bash sudo systemctl start gotify sudo systemctl status gotify sudo tail /var/log/gotify/gotify.log ``` -------------------------------- ### Execute Gotify Server Binary Source: https://gotify.net/docs/install Run the Gotify server binary. By default, it starts on port 80, which may require sudo privileges. Refer to the configuration for changing the port or database. ```bash $ sudo ./gotify-{PLATFORM} ``` -------------------------------- ### Install and Run gomod-cap for Dependency Management Source: https://gotify.net/docs/plugin-deploy Use gomod-cap to reconcile dependency versions between Gotify server and your plugin, then tidy up the module dependencies. ```bash go get -u github.com/gotify/plugin-api/cmd/gomod-cap go run github.com/gotify/plugin-api/cmd/gomod-cap \ -from /path/to/gotify/server/source/go.mod -to /path/to/plugin/source/go.mod go mod tidy ``` -------------------------------- ### Push Message with HTTPie Source: https://gotify.net/docs/pushmsg Send a message using HTTPie, a command-line HTTP client. This example includes title, message, and priority. ```bash $ http -f POST "https://push.example.de/message?token=" title="my title" message="my message" priority="5" ``` -------------------------------- ### Configure Database Connection String Source: https://gotify.net/docs/config Set the database connection string. The format varies by dialect (sqlite3, mysql, postgres). Example for postgres without SSL is provided. ```shell # Database connection string. Format depends on the dialect. # Type: text # Example: # sqlite3: path/to/database.db # mysql: gotify:secret@tcp(localhost:3306)/gotifydb?charset=utf8&parseTime=True&loc=Local # postgres: host=localhost port=5432 user=gotify dbname=gotifydb password=secret # When using postgres without SSL, append `sslmode=disable` (see https://github.com/gotify/server/issues/90). # GOTIFY_DATABASE_CONNECTION=data/gotify.db ``` -------------------------------- ### Elevate Session via API Source: https://gotify.net/docs/session-elevation This example shows how to elevate a session using basic authentication with username and password for a protected endpoint. This method is always elevated. ```bash curl -u "user:password" -X DELETE "https://gotify.example.com/client/7" ``` -------------------------------- ### Send Push Message with Python Source: https://gotify.net/docs/more-pushmsg Send a push message using the Python requests library. This example includes a title, message, and priority. Make sure to install the requests library (`pip install requests`). ```python import requests #pip install requests resp = requests.post('http://localhost:8008/message?token=', json={ "message": "Well hello there.", "priority": 2, "title": "This is my title" }) ``` -------------------------------- ### Send Push Message with Wget Source: https://gotify.net/docs/more-pushmsg This command-line example uses `wget` to send a push notification to Gotify. It's a simple way to send messages from shell scripts or the command line. ```sh token="" subject="wget" message="Test push from wget" priority=5 wget "http://localhost:8008/message?token=$token" --post-data "title=$subject&message=$message&priority=$priority" -O /dev/null ``` -------------------------------- ### Gotify Default User Configuration Source: https://gotify.net/docs/config Set the username and password for the initial admin user created when the database is first set up. These values are only used on the first start. ```yaml defaultuser: # on database creation, gotify creates an admin user (these values will only be used for the first start, if you want to edit the user after the first start use the WebUI) name: admin # the username of the default user pass: admin # the password of the default user ``` -------------------------------- ### Systemd Unit File for Gotify Source: https://gotify.net/docs/systemd This systemd unit file configures Gotify to run as a service. It specifies user, working directory, executable path, log file locations, and restart behavior. Adjust paths and user as needed for your installation. ```systemd [Unit] Description=Gotify Requires=network.target After=network.target [Service] Type=simple User=root WorkingDirectory=/opt/gotify ExecStart=/opt/gotify/gotify StandardOutput=append:/var/log/gotify/gotify.log StandardError=append:/var/log/gotify/gotify-error.log Restart=always RestartSec=3 [Install] WantedBy=multi-user.target ``` -------------------------------- ### Caddyfile: Reverse Proxy to Gotify at a Subpath Source: https://gotify.net/docs/caddy Configure Caddy to proxy Gotify when it's accessed via a subpath. This setup includes a redirect for the base path. ```caddyfile example.com { route /gotify/* { uri strip_prefix /gotify # Set the port to the one you are using in gotify reverse_proxy localhost:1245 } redir /gotify /gotify/ } ``` -------------------------------- ### Nginx Reverse Proxy at Subpath Source: https://gotify.net/docs/nginx Configure Nginx to proxy Gotify when it's running on a subpath. This example demonstrates how to handle requests to '/gotify/' and forward them correctly, including websocket support. ```nginx upstream gotify { # Set the port to the one you are using in gotify server 192.168.178.34:8080; } server { listen 80; server_name localhost; location /gotify/ { proxy_pass http://gotify; rewrite ^/gotify(/.*) $1 break; proxy_http_version 1.1; # Ensuring it can use websockets proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; 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 http; proxy_redirect http:// $scheme://; # The proxy must preserve the host because gotify verifies the host with the origin # for WebSocket connections proxy_set_header Host $http_host; proxy_connect_timeout 1m; proxy_send_timeout 1m; proxy_read_timeout 1m; } } ``` -------------------------------- ### Run Gotify server with serve subcommand Source: https://gotify.net/docs/migrate-to-3 The Gotify binary now uses subcommands. Migrate your startup scripts to use the `serve` subcommand. The Docker image already defaults to this behavior. ```bash $ ./gotify-linux-amd64 serve ``` -------------------------------- ### Send Push Message with JavaScript (Axios) Source: https://gotify.net/docs/more-pushmsg Use this snippet to send a push notification from a Node.js environment using the Axios library. Ensure you have Axios installed (`npm install axios`). ```javascript const axios = require('axios'); const url = 'http://localhost:8008/message?token='; const bodyFormData = { title: 'Hello from Javascript', message: 'Test Push Service from Node.js', priority: 5, }; axios({ method: 'post', headers: { 'Content-Type': 'application/json', }, url: url, data: bodyFormData, }) .then((response) => console.log(response.data)) .catch((err) => console.log(err.response ? error.response.data : err)); ``` -------------------------------- ### Download Backend Dependencies Source: https://gotify.net/docs/dev-setup Download necessary tools and dependencies for the Gotify backend. This command should be run after cloning the repository. ```bash make download-tools ``` -------------------------------- ### Extract and Make Gotify Binary Executable Source: https://gotify.net/docs/install Unzip the downloaded Gotify server archive and make the binary executable. This prepares the server for execution on your system. ```bash $ unzip gotify-{PLATFORM}.zip ``` ```bash $ chmod +x gotify-{PLATFORM} ``` -------------------------------- ### List Plugin Source Files Source: https://gotify.net/docs/plugin-deploy Verify that your plugin source directory contains the necessary Go files. ```bash ls main.go go.mod go.sum ``` -------------------------------- ### Build Gotify Server with Makefile Source: https://gotify.net/docs/build Executes Makefile tasks to build the Gotify server binary. The 'make build' command builds for all supported platforms. ```bash # builds all supported platforms $ make build # builds a specific platform $ make build-linux-amd64 $ make build-linux-arm-7 $ make build-linux-arm64 $ make build-linux-386 $ make build-windows-amd64 $ make build-windows-386 ``` -------------------------------- ### Build Gotify UI Source: https://gotify.net/docs/build Builds the user interface for Gotify. Ensure you are in the 'ui' directory before running this command. ```bash (cd ui && yarn build) ``` -------------------------------- ### Docker Compose Configuration for Gotify Source: https://gotify.net/docs/install A sample docker-compose.yaml file to set up and run the gotify/server service. This includes port mapping, environment variables for default user password, and volume mounting for data persistence. ```yaml --- services: gotify: image: gotify/server ports: - 8080:80 environment: GOTIFY_DEFAULTUSER_PASS: 'admin' volumes: - './gotify_data:/app/data' # to run gotify as a dedicated user: # sudo chown -R 1234:1234 ./gotify_data # user: "1234:1234" ``` -------------------------------- ### Build Plugin for Linux 386 using Docker Source: https://gotify.net/docs/plugin-deploy Build a plugin for Linux 386 architecture using the specified Go version within a Docker container. Mounts the current directory to /proj and sets it as the working directory. ```bash docker run --rm -v "$PWD/.:/proj" -w /proj gotify/build:1.12.0-linux-386 \ go build -a -installsuffix cgo -ldflags "-w -s" -buildmode=plugin -o yourplugin-386.so /proj ``` -------------------------------- ### Gotify Database Configuration Source: https://gotify.net/docs/config Configure the database connection, including the dialect (e.g., sqlite3) and the connection string or path to the database file. ```yaml database: # for database see (configure database section) dialect: sqlite3 connection: data/gotify.db ``` -------------------------------- ### Download Gotify Server Binary Source: https://gotify.net/docs/install Download the Gotify server binary for your specific platform. Replace {VERSION} with the latest version and {PLATFORM} with your system's architecture (e.g., linux-amd64). ```bash $ wget https://github.com/gotify/server/releases/download/v{VERSION}/gotify-{PLATFORM}.zip ``` -------------------------------- ### Send Push Message with PHP cURL Source: https://gotify.net/docs/more-pushmsg This PHP example uses cURL to send a push message with a title, message, and priority. It also includes basic HTTP status code handling for the response. ```php $data = [ "title"=> "Hello World", "message"=> "Test push From PHP cURL.", "priority"=> 5, ]; $data_string = json_encode($data); $url = "http://localhost:8008/message?token="; $headers = [ "Content-Type: application/json; charset=utf-8" ]; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers ); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true ); curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); $result = curl_exec($ch); $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close ($ch); switch ($code) { case "200": echo "Your Message was Submitted"; break; case "400": echo "Bad Request"; break; case "401": echo "Unauthorized Error - Invalid Token"; break; case "403": echo "Forbidden"; break; case "404": echo "API URL Not Found"; break; default: echo "Hmm Something Went Wrong or HTTP Status Code is Missing"; } ``` -------------------------------- ### Provide Configuration Interfaces with Configurer Source: https://gotify.net/docs/plugin-write Implement the Configurer interface to offer configuration options to users. The Gotify main program handles marshaling and unmarshaling, with the REST API exposed at /plugin/:id/config. ```go package plugin import ( "errors" ) // Plugin is the plugin instance type Plugin struct { config *Config } type Config struct { GitHubUserName string } // DefaultConfig implements plugin.Configurer // The default configuration will be provided to the user for future editing. Also used for Unmarshaling. // Invoked whenever an unmarshaling is required. func (c *Plugin) DefaultConfig() interface{} { return &Config{ GitHubUserName: "jmattheis", } } // ValidateAndSetConfig will be called every time the plugin is initialized or the configuration has been changed by the user. // Plugins should validate the configuration and optionally return an error. // Parameter is guaranteed to be the same type as the return type of DefaultConfig(), so it is safe to do a hard type assertion here. // // "Validation" in this context means to check for conflicting or impossible values, such as a non-URL on a field which should only contain a URL. // In order to make sure that the plugin instance is always running in a valid state, this method should always accept the result of DefaultConfig() // // Invoked on initialization to provide initial configuration. Return nil to accept or return error to indicate that the config is obsolete. // When the configuration is marked obsolete due to an unmarshaling error or rejection on the plugin side, the plugin is disabled automatically and the user is notified to resolve the config confliction. // Invoked every time the config update API is called. Check the configuration and return nil to accept or return error to indicate that the config is invalid. // Return a short and consise error here and, if you have detailed suggestions on how to solve the problem, utilize Displayer to provide more information to the user, func (c *Plugin) ValidateAndSetConfig(c interface{}) error { config = c.(*Config) if !userNameIsValid(config.GitHubUserName) { return errors.New("the user name is not valid") } c.config = config return nil } ``` -------------------------------- ### Image Optimization Script Source: https://gotify.net/docs/optimize-images This bash script resizes images to a maximum dimension of 512 pixels and optimizes PNG files. It only processes files that have not been optimized before, indicated by the presence of a timestamp file. Ensure ImageMagick and optipng are installed. ```bash #!/usr/bin/env bash set -e DATA=/home/jm/src/gotify/server/data for FILE in "$DATA"/images/*; do if [ "$FILE" -nt "$DATA"/images-optimized ]; then EXT=$(echo "${FILE##*.}"|tr '[:upper:]' '[:lower:]') if [ "$EXT" = png -o "$EXT" = jpg -o "$EXT" = jpeg -o "$EXT" = gif ]; then convert "$FILE" -resize "512>" "$FILE" fi if [ "$EXT" = png ]; then optipng "$FILE" fi fi done touch "$DATA"/images-optimized ``` -------------------------------- ### Clone Gotify Server Repository Source: https://gotify.net/docs/dev-setup Clone the Gotify server source code from GitHub and navigate into the directory. This is the first step in setting up the development environment. ```bash git clone https://github.com/gotify/server.git && cd server ``` -------------------------------- ### Build Plugin for Linux arm64 using Docker Source: https://gotify.net/docs/plugin-deploy Build a plugin for Linux arm64 architecture using the specified Go version within a Docker container. Mounts the current directory to /proj and sets it as the working directory. ```bash docker run --rm -v "$PWD/.:/proj" -w /proj gotify/build:1.12.0-linux-arm64 \ go build -a -installsuffix cgo -ldflags "-w -s" -buildmode=plugin -o yourplugin-arm64.so /proj ``` -------------------------------- ### Traefik Docker Service Configuration Source: https://gotify.net/docs/traefik Configure the Traefik service within a Docker Compose file. This setup enables Docker provider, sets up TLS termination with Let's Encrypt, and maps necessary ports and volumes. ```yaml services: traefik: image: 'traefik:v3.2' container_name: 'traefik' command: - '--providers.docker=true' - '--providers.docker.exposedbydefault=false' - '--entryPoints.websecure.address=:443' - '--certificatesresolvers.letsencrypt.acme.tlschallenge=true' - '--certificatesresolvers.letsencrypt.acme.email=' - '--certificatesresolvers.letsencrypt.acme.storage=/letsencrypt/acme.json' ports: - '443:443' volumes: - './letsencrypt:/letsencrypt' - '/var/run/docker.sock:/var/run/docker.sock:ro' ``` -------------------------------- ### Build Plugin for Linux arm-7 using Docker Source: https://gotify.net/docs/plugin-deploy Build a plugin for Linux arm-7 architecture using the specified Go version within a Docker container. Mounts the current directory to /proj and sets it as the working directory. ```bash docker run --rm -v "$PWD/.:/proj" -w /proj gotify/build:1.12.0-linux-arm-7 \ go build -a -installsuffix cgo -ldflags "-w -s" -buildmode=plugin -o yourplugin-arm-7.so /proj ``` -------------------------------- ### Build Plugin for Linux amd64 using Docker Source: https://gotify.net/docs/plugin-deploy Build a plugin for Linux amd64 architecture using the specified Go version within a Docker container. Mounts the current directory to /proj and sets it as the working directory. ```bash docker run --rm -v "$PWD/.:/proj" -w /proj gotify/build:1.12.0-linux-amd64 \ go build -a -installsuffix cgo -ldflags "-w -s" -buildmode=plugin -o yourplugin-amd64.so /proj ``` -------------------------------- ### Build Plugin without Docker Source: https://gotify.net/docs/plugin-deploy Build a plugin using the Go toolchain directly. This method is not recommended as it may lead to compatibility issues with pre-built Gotify binaries. ```bash go build -o /path/to/gotify/plugin/dir/myplugin.so -buildmode=plugin ``` -------------------------------- ### GOTIFY_SERVER_SSL_CERTFILE Configuration Source: https://gotify.net/docs/config Specifies the path to the TLS certificate file. ```env # Path to the TLS certificate. # Type: text # Example: /etc/ssl/certs/gotify.crt # GOTIFY_SERVER_SSL_CERTFILE= ``` -------------------------------- ### Build Gotify Server without Docker Source: https://gotify.net/docs/build Compiles the Gotify server binary directly using the Go toolchain without Docker. Ensure the LD_FLAGS environment variable is set. ```bash go build -ldflags="$LD_FLAGS" -o gotify-server ``` -------------------------------- ### GOTIFY_SERVER_SSL_LETSENCRYPT_ACCEPTTOS Configuration Source: https://gotify.net/docs/config Indicates acceptance of the Let's Encrypt Terms of Service, required for automatic certificate acquisition. ```env # Accept the Let's Encrypt Terms of Service. # Type: boolean # GOTIFY_SERVER_SSL_LETSENCRYPT_ACCEPTTOS=false ``` -------------------------------- ### Enable OIDC Login with Gotify Environment Variables Source: https://gotify.net/docs/oidc Set these environment variables to enable and configure OIDC login in Gotify. Ensure the redirect URL matches your identity provider's configuration. ```bash GOTIFY_OIDC_ENABLED=true GOTIFY_OIDC_ISSUER=https://auth.example.org GOTIFY_OIDC_CLIENTID=gotify GOTIFY_OIDC_CLIENTSECRET=YOUR_CLIENT_SECRET GOTIFY_OIDC_REDIRECTURL=https://gotify.example.org/auth/oidc/callback GOTIFY_OIDC_AUTOREGISTER=true GOTIFY_OIDC_USERNAMECLAIM=preferred_username GOTIFY_OIDC_LINK_BY_USERNAME=false GOTIFY_OIDC_SCOPES=openid,profile,email ``` -------------------------------- ### Gotify Server Environment Variables Source: https://gotify.net/docs/config Set various Gotify server configurations using environment variables. Ensure proper escaping for list and map settings. ```bash GOTIFY_SERVER_PORT=80 GOTIFY_SERVER_KEEPALIVEPERIODSECONDS=0 GOTIFY_SERVER_LISTENADDR= GOTIFY_SERVER_SSL_ENABLED=false GOTIFY_SERVER_SSL_REDIRECTTOHTTPS=true GOTIFY_SERVER_SSL_LISTENADDR= GOTIFY_SERVER_SSL_PORT=443 GOTIFY_SERVER_SSL_CERTFILE= GOTIFY_SERVER_SSL_CERTKEY= GOTIFY_SERVER_SSL_LETSENCRYPT_ENABLED=false GOTIFY_SERVER_SSL_LETSENCRYPT_ACCEPTTOS=false GOTIFY_SERVER_SSL_LETSENCRYPT_CACHE=data/certs GOTIFY_SERVER_SSL_LETSENCRYPT_DIRECTORYURL= # GOTIFY_SERVER_SSL_LETSENCRYPT_HOSTS=[mydomain.tld, myotherdomain.tld] # GOTIFY_SERVER_RESPONSEHEADERS={X-Custom-Header: "custom value", x-other: value} # GOTIFY_SERVER_TRUSTEDPROXIES=[127.0.0.1,192.168.178.2/24] # GOTIFY_SERVER_CORS_ALLOWORIGINS=[.+\.example\.com, otherdomain\.com] # GOTIFY_SERVER_CORS_ALLOWMETHODS=[GET, POST] # GOTIFY_SERVER_CORS_ALLOWHEADERS=[X-Gotify-Key, Authorization] # GOTIFY_SERVER_STREAM_ALLOWEDORIGINS=[.+.example\.com, otherdomain\.com] GOTIFY_SERVER_STREAM_PINGPERIODSECONDS=45 GOTIFY_SERVER_SECURECOOKIE=false GOTIFY_DATABASE_DIALECT=sqlite3 GOTIFY_DATABASE_CONNECTION=data/gotify.db GOTIFY_DEFAULTUSER_NAME=admin GOTIFY_DEFAULTUSER_PASS=admin GOTIFY_PASSSTRENGTH=10 GOTIFY_UPLOADEDIMAGESDIR=data/images GOTIFY_PLUGINSDIR=data/plugins GOTIFY_REGISTRATION=false GOTIFY_OIDC_ENABLED=false GOTIFY_OIDC_ISSUER= GOTIFY_OIDC_CLIENTID= GOTIFY_OIDC_CLIENTSECRET= GOTIFY_OIDC_REDIRECTURL=http://gotify.example.org/auth/oidc/callback GOTIFY_OIDC_AUTOREGISTER=true GOTIFY_OIDC_USERNAMECLAIM=preferred_username ``` -------------------------------- ### Run Backend Tests with Coverage Source: https://gotify.net/docs/dev-server-and-tests Executes backend tests and generates a coverage report. The HTML report can be viewed using 'go tool cover -html=coverage.txt'. ```bash make test-coverage ``` ```bash go tool cover -html=coverage.txt ``` -------------------------------- ### Send Push Message with Golang Source: https://gotify.net/docs/more-pushmsg This Golang snippet demonstrates how to send a push message using the standard net/http package. It includes a title and message. ```go package main import ( "net/http" "net/url" ) func main() { http.PostForm("http://localhost:8008/message?token=", url.Values{"message": {"My Message"}, "title": {"My Title"}}) } ``` -------------------------------- ### GOTIFY_SERVER_SSL_CERTKEY Configuration Source: https://gotify.net/docs/config Specifies the path to the TLS private key file. ```env # Path to the TLS private key. # Type: text # Example: /etc/ssl/private/gotify.key # GOTIFY_SERVER_SSL_CERTKEY= ``` -------------------------------- ### Enable Go Modules Source: https://gotify.net/docs/plugin-deploy Explicitly enable Go modules if you are working within a GOPATH environment. ```bash export GO111MODULE=on ``` -------------------------------- ### GOTIFY_SERVER_SSL_LETSENCRYPT_ENABLED Configuration Source: https://gotify.net/docs/config Enables automatic TLS certificate acquisition from Let's Encrypt. Requires `SSL_ENABLED=true` and `LETSENCRYPT_ACCEPTTOS=true`. ```env # Obtain the TLS certificate automatically from Let's Encrypt. # Requires SSL_ENABLED=true and LETSENCRYPT_ACCEPTTOS=true. # Type: boolean # GOTIFY_SERVER_SSL_LETSENCRYPT_ENABLED=false ``` -------------------------------- ### Set Plugins Directory Source: https://gotify.net/docs/config Define the directory scanned for plugin shared libraries on startup. Leave empty to disable plugin loading. ```shell # Directory scanned for plugin shared libraries on startup. Leave empty to # disable plugin loading. # # Type: text # Example: /var/lib/gotify/plugins # GOTIFY_PLUGINSDIR=data/plugins ``` -------------------------------- ### Cross-Compile Gotify Server with CGO Source: https://gotify.net/docs/build Cross-compiles the Gotify server binary for different platforms when CGO is enabled, which is necessary for dependencies like sqlite3. Requires a CGO cross-compiler and setting GOOS and GOARCH environment variables. ```bash CGO_ENABLED=1 CC=${CROSS_GCC} CXX=${CROSS_G++} GOOS=${TARGET_GOOS} GOARCH=${TARGET_GOARCH} \ go build -ldflags="$LD_FLAGS" -o gotify-server ``` -------------------------------- ### GOTIFY_SERVER_SSL_ENABLED Configuration Source: https://gotify.net/docs/config Enables the HTTPS listener. Requires either `CERTFILE`+`CERTKEY` or `LETSENCRYPT_ENABLED=true` to be set. ```env # Enable the HTTPS listener. Requires either CERTFILE+CERTKEY or LETSENCRYPT_ENABLED=true. # Type: boolean # GOTIFY_SERVER_SSL_ENABLED=false ``` -------------------------------- ### GOTIFY_SERVER_SSL_LETSENCRYPT_HOSTS Configuration Source: https://gotify.net/docs/config Defines the hosts for which Let's Encrypt should issue certificates. Each host must resolve publicly to this server. ```env # Hosts Let's Encrypt should issue certificates for. Each host must resolve # publicly to this server. # # Type: text-list # Example: mydomain.tld,myotherdomain.tld # GOTIFY_SERVER_SSL_LETSENCRYPT_HOSTS= ``` -------------------------------- ### Gotify SSL Configuration Source: https://gotify.net/docs/config Enable and configure SSL/TLS for secure HTTPS connections. This includes redirecting HTTP traffic to HTTPS and specifying certificate files or enabling Let's Encrypt integration. ```yaml ssl: enabled: false # if https should be enabled redirecttohttps: true # redirect to https if site is accessed by http listenaddr: '' # the address to bind on, leave empty to bind on all addresses. Prefix with "unix:" to create a unix socket. Example: "unix:/tmp/gotify.sock". port: 443 # the https port certfile: # the cert file (leave empty when using letsencrypt) certkey: # the cert key (leave empty when using letsencrypt) letsencrypt: enabled: false # if the certificate should be requested from letsencrypt accepttos: false # if you accept the tos from letsencrypt cache: data/certs # the directory of the cache from letsencrypt directoryurl: # override the directory url of the ACME server # Let's Encrypt highly recommend testing against their staging environment before using their production environment. # Staging server has high rate limits for testing and debugging, issued certificates are not valid # example: https://acme-staging-v02.api.letsencrypt.org/directory hosts: # the hosts for which letsencrypt should request certificates # - mydomain.tld # - myotherdomain.tld ``` -------------------------------- ### Gotify Server Configuration Source: https://gotify.net/docs/config Configure basic server settings including keep-alive, listen address, and port. The keep-alive period defaults to 15 seconds if set to 0, and can be disabled with -1. ```yaml server: keepaliveperiodseconds: 0 # 0 = use Go default (15s); -1 = disable keepalive; set the interval in which keepalive packets will be sent. Only change this value if you know what you are doing. listenaddr: '' # the address to bind on, leave empty to bind on all addresses. Prefix with "unix:" to create a unix socket. Example: "unix:/tmp/gotify.sock". port: 80 # the port the HTTP server will listen on ``` -------------------------------- ### Set Build Flags for Gotify Server Source: https://gotify.net/docs/build Sets environment variables for Go build flags, including version, build date, commit hash, and mode. This is recommended for ensuring plugin compatibility. ```bash export LD_FLAGS="-w -s -X main.Version=$(git describe --tags | cut -c 2-) -X main.BuildDate=$(date '+%F-%T') -X main.Commit=$(git rev-parse --verify HEAD) -X main.Mode=prod"; ``` -------------------------------- ### Navigate to Plugin Source Directory Source: https://gotify.net/docs/plugin-deploy Change your current directory to the root of your plugin's source code. ```bash cd /path/to/plugin/source ``` -------------------------------- ### Basic Gotify Plugin Structure Source: https://gotify.net/docs/plugin-write Implements the minimal plugin interface with Enable and Disable methods. This forms the base for any Gotify plugin. ```go package main import ( "log" "net/url" "github.com/gotify/plugin/v2" ) // Plugin is plugin instance type Plugin struct{} // Enable implements plugin.Plugin // Invoked just after initialization if plugin is already enabled. // Invoked every time the plugin is switched to enabled. func (c *Plugin) Enable() error { return nil } // Disable implements plugin.Plugin // Invoked every time the plugin is switched to disabled. func (c *Plugin) Disable() error { return nil } ``` -------------------------------- ### Schedule Image Optimization with Cron Source: https://gotify.net/docs/optimize-images This line should be added to a cron file (e.g., /etc/cron.d/gotify) to schedule the image optimization script to run daily at 12:12 PM. ```txt 12 12 * * * root /opt/gotify/optimize-images.sh ``` -------------------------------- ### Plugin Base Implementation Source: https://gotify.net/docs/plugin-write This shows the minimal implementation of a plugin, including the Enable and Disable methods. ```APIDOC ## Plugin Interface ### Description Provides the base `Enable` and `Disable` methods for a plugin. ### Methods #### Enable() - **Description**: Invoked just after initialization if the plugin is already enabled, or every time the plugin is switched to enabled. - **Returns**: `error` #### Disable() - **Description**: Invoked every time the plugin is switched to disabled. - **Returns**: `error` ``` -------------------------------- ### Push Message with Gotify CLI Source: https://gotify.net/docs/pushmsg Send a message using the Gotify CLI with a title and priority. The CLI manages URL and token from a configuration file. ```bash $ gotify push -t "my title" -p 10 "my message" ``` -------------------------------- ### Gotify Image and Plugin Directories Source: https://gotify.net/docs/config Specify the directories for storing uploaded images and Gotify plugins. Leave the plugin directory empty to disable plugins. ```yaml uploadedimagesdir: data/images # the directory for storing uploaded images pluginsdir: data/plugins # the directory where plugin resides (leave empty to disable plugins) ``` -------------------------------- ### HAProxy Frontend and Backend Configuration Source: https://gotify.net/docs/haproxy Configure the frontend to listen on port 80 and forward requests to the backend, which points to the Gotify server. Adjust client and server timeouts as needed. ```haproxy frontend www bind 0.0.0.0:80 default_backend backend_gotify timeout client 60s timeout client-fin 30s backend backend_gotify server backend01 127.0.0.1:GOTIFY_PORT check timeout connect 10s timeout server 60s ``` -------------------------------- ### Gotify Docker Service with Traefik Labels Source: https://gotify.net/docs/traefik Configure the Gotify service to be exposed via Traefik. Labels are used to enable Traefik, define the routing rule based on the host, specify the entry point, and configure TLS using Let's Encrypt. ```yaml gotify: image: gotify/server: labels: 'traefik.enable': 'true' 'traefik.http.routers.gotify.rule': 'Host(`gotify.yourdomain.tld`)' 'traefik.http.routers.gotify.entrypoints': 'websecure' 'traefik.http.routers.gotify.tls.certresolver': 'letsencrypt' ``` -------------------------------- ### Caddyfile: Reverse Proxy to Gotify on Standalone Domain Source: https://gotify.net/docs/caddy Use this configuration when Gotify is running on a dedicated domain. Caddy automatically manages SSL certificates. ```caddyfile gotify.example.com { # Set the port to the one you are using in gotify # Websocket support, proxy headers, etc. are enabled by default reverse_proxy localhost:1245 } ``` -------------------------------- ### GOTIFY_SERVER_SSL_LETSENCRYPT_DIRECTORYURL Configuration Source: https://gotify.net/docs/config Allows overriding the ACME directory URL. Leave empty to use the Let's Encrypt production server. The staging server is useful for testing due to higher rate limits but issues untrusted certificates. ```env # Override the ACME directory URL. Leave empty to use the Let's Encrypt # production server. The staging server has higher rate limits useful for # testing but issues certificates that are not publicly trusted. # # Type: text # Example: https://acme-staging-v02.api.letsencrypt.org/directory # GOTIFY_SERVER_SSL_LETSENCRYPT_DIRECTORYURL= ``` -------------------------------- ### Push Message with Gotify CLI (Piping) Source: https://gotify.net/docs/pushmsg Pipe the message content directly to the Gotify CLI for sending. This is a convenient way to send simple messages. ```bash $ echo my message | gotify push ``` -------------------------------- ### Gotify OpenID Connect (OIDC) Configuration Source: https://gotify.net/docs/config Enable and configure OpenID Connect for external authentication. This requires specifying the issuer URL, client ID, client secret, and redirect URL, along with options for auto-registration and username claim. ```yaml oidc: enabled: false # Enable OpenID Connect login, allowing users to authenticate via an external identity provider (e.g. Keycloak, Authelia, Google). issuer: # The OIDC issuer URL. This is the base URL of your identity provider, used to discover endpoints. Example: "https://auth.example.com/realms/myrealm" clientid: # The client ID registered with your identity provider for this application. clientsecret: # The client secret for the registered client. redirecturl: http://gotify.example.org/auth/oidc/callback # The callback URL that the identity provider redirects to after authentication. Must match exactly what is configured in your identity provider. autoregister: true # If true, automatically create a new user on first OIDC login. If false, only existing users can log in via OIDC. usernameclaim: preferred_username # The OIDC claim used to determine the username. Common values: "preferred_username" or "email". ``` -------------------------------- ### Gotify Storager API Implementation Source: https://gotify.net/docs/plugin-write Implements the Storager interface to store and retrieve user-level data persistently. It handles JSON serialization and deserialization for storage. ```go // Plugin is the plugin instance type Plugin struct { storageHandler plugin.StorageHandler } // SetStorageHandler implements plugin.Storager // Invoked during initialization func (c *Plugin) SetStorageHandler(h plugin.StorageHandler) { c.storageHandler = h } type Storage struct { EnabledTimes uint `json:"enabled_times"` } func (c *Plugin) Enable() error { storage := new(Storage) storageBytes, err := c.storageHandler.Load() if err != nil { return err } if len(storageBytes) == 0 { storage.EnabledTimes = 1 storageBytes, _ = json.Marshal(storage) c.storageHandler.Save(storageBytes) } else { json.Unmarshal(storageBytes, storage) } log.Printf("This plugin has been enabled %d times.", storage.EnabledTimes) return nil } ``` -------------------------------- ### Copy Plugin to Gotify Plugins Directory Source: https://gotify.net/docs/plugin-deploy Copy the compiled plugin shared object file to the directory specified by GOTIFY_PLUGINSDIR in your Gotify configuration. ```bash cp myplugin.so "${GOTIFY_PLUGINSDIR}/myplugin.so" ``` -------------------------------- ### Gotify Registration Setting Source: https://gotify.net/docs/config Enable or disable user registration on the Gotify server. When disabled, only existing users can log in. ```yaml registration: false # enable registrations ``` -------------------------------- ### Proxy Requests to Gotify Source: https://gotify.net/docs/apache Use this configuration to proxy all incoming requests to the Gotify server. Ensure the required Apache modules (mod_proxy, mod_proxy_wstunnel, mod_proxy_http) are enabled. ```apache ServerName domain.tld Keepalive On # The proxy must preserve the host because gotify verifies the host with the origin # for WebSocket connections ProxyPreserveHost On # Proxy web socket requests to /stream ProxyPass "/stream" ws://127.0.0.1:GOTIFY_PORT/stream retry=0 timeout=60 # Proxy all other requests to / ProxyPass "/" http://127.0.0.1:GOTIFY_PORT/ retry=0 timeout=5 ProxyPassReverse / http://127.0.0.1:GOTIFY_PORT/ ``` -------------------------------- ### Run Backend Tests with Parallelism Source: https://gotify.net/docs/dev-server-and-tests Executes all backend tests with parallelism enabled. ```bash go test ./... ``` -------------------------------- ### GOTIFY_SERVER_SSL_REDIRECTTOHTTPS Configuration Source: https://gotify.net/docs/config Redirects plain HTTP requests to HTTPS. This setting is only effective when `SSL_ENABLED` is set to `true`. ```env # Redirect plain HTTP requests to HTTPS. Only effective when SSL_ENABLED=true. # Type: boolean # GOTIFY_SERVER_SSL_REDIRECTTOHTTPS=true ``` -------------------------------- ### GOTIFY_SERVER_PORT Configuration Source: https://gotify.net/docs/config Sets the port number the HTTP server listens on. ```env # Port the HTTP server listens on. # Type: number # GOTIFY_SERVER_PORT=80 ``` -------------------------------- ### Send Push Message with cURL and Markdown Source: https://gotify.net/docs/more-pushmsg Use this cURL command to send a push message with a title, markdown content (including an image), and a specific priority. Ensure Gotify is running and replace with your application token. ```bash #!/bin/bash TITLE="My Title" MESSAGE="Hello: ![](https://gotify.net/img/logo.png)" PRIORITY=5 URL="http://localhost:8008/message?token=" curl -s -S --data '{"message": "'"${MESSAGE}"'", "title": "'"${TITLE}"'", "priority":'"${PRIORITY}"'", "extras": {"client::display": {"contentType": "text/markdown"}}}' -H 'Content-Type: application/json' "$URL" ``` -------------------------------- ### GOTIFY_LOGLEVEL Configuration Source: https://gotify.net/docs/config Sets the minimum severity of log messages to emit. Supported values include trace, debug, info, warn, error, fatal, and panic. ```env # Minimum severity of log messages to emit. # Values: trace, debug, info, warn, error, fatal, panic # GOTIFY_LOGLEVEL=info ``` -------------------------------- ### Gotify Trusted Proxies Configuration Source: https://gotify.net/docs/config Configure trusted proxy IP addresses or ranges to correctly determine the client's IP address from the X-Forwarded-For header. ```yaml trustedproxies: # IPs or IP ranges of trusted proxies. Used to obtain the remote ip via the X-Forwarded-For header. (configure 127.0.0.1 to trust sockets) # - 127.0.0.1/32 # - ::1 ``` -------------------------------- ### Set Uploaded Images Directory Source: https://gotify.net/docs/config Specify the directory for storing application icons and uploaded images. This directory must be writable by the server. ```shell # Directory where application icons and other uploaded images are stored. Must # be writable by the server. # # Type: text # Example: /var/lib/gotify/images # GOTIFY_UPLOADEDIMAGESDIR=data/images ``` -------------------------------- ### Run Backend Tests with Race Detector Source: https://gotify.net/docs/dev-server-and-tests Executes backend tests with the race detector enabled to find potential data races. ```bash make test-race ``` -------------------------------- ### Convert YAML config to environment variables Source: https://gotify.net/docs/migrate-to-3 Use the `migrate-config` command to convert your existing `config.yml` to the new environment variable format. The output is printed to stdout and can be redirected to a new file. ```bash $ gotify-server migrate-config config.yml > gotify-server.env ``` ```bash $ docker run --rm -v "$(pwd)/config.yml:/app/config.yml" gotify/server:master \ migrate-config config.yml > gotify-server.env ``` -------------------------------- ### Gotify Displayer API Implementation Source: https://gotify.net/docs/plugin-write Implements the Displayer interface to show dynamic information on the plugin's page in the WebUI. It can conditionally display messages based on user context. ```go // Plugin is the plugin instance type Plugin struct { userCtx plugin.UserContext } // GetDisplay implements plugin.Displayer // Invoked when the user views the plugin settings. Plugins do not need to be enabled to handle GetDisplay calls. func (c *Plugin) GetDisplay(location *url.URL) string { if (c.userCtx.Admin) { return "You are an admin! You have super cow powers." } else { return "You are **NOT** an admin! You can do nothing:(" } } // NewGotifyPluginInstance creates a plugin instance for a user context. func NewGotifyPluginInstance(ctx plugin.UserContext) plugin.Plugin { return &Plugin{ctx} } ``` -------------------------------- ### Java 11 HTTP Client for Gotify Source: https://gotify.net/docs/more-pushmsg This Java code demonstrates sending a push message using the built-in `HttpClient`. It requires the Jackson library for JSON serialization. Add the Jackson dependency to your Maven `pom.xml`. ```xml com.fasterxml.jackson.core jackson-databind 2.12.1 ``` ```java package com.gotify.client; import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; public class GotifyClient { private static final String BASE_URL = "http://localhost:8080"; private static final String TOKEN = ""; public static void main(String[] args) throws IOException, InterruptedException { final var client = new GotifyClient(BASE_URL, TOKEN); final var message = new Message("My Title", "Hello from Java!", 10); if (client.sendMessage(message)) { System.out.println("Message sent!"); } else { System.out.println("Something went wrong :(. "); } } private final String gotifyUrl; private final HttpClient httpClient; private final ObjectMapper objectMapper; public GotifyClient(String baseUrl, String token) { this.gotifyUrl = String.format("%s/message?token=%s", baseUrl, token); this.httpClient = HttpClient.newHttpClient(); this.objectMapper = new ObjectMapper(); } private boolean sendMessage(Message message) throws IOException, InterruptedException { final var bodyData = objectMapper.writeValueAsString(message); final var request = HttpRequest.newBuilder() .uri(URI.create(gotifyUrl)) .header("Content-Type", "application/json") .POST(HttpRequest.BodyPublishers.ofString(bodyData)) .build(); final var response = httpClient.send(request, HttpResponse.BodyHandlers.ofString()); System.out.println(response.body()); return response.statusCode() >= 200 && response.statusCode() < 400; } public static class Message { private String message; private String title; private int priority; public Message(String title, String message, int priority) { this.message = message; this.priority = priority; this.title = title; } public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } public int getPriority() { return priority; } public void setPriority(int priority) { this.priority = priority; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } } } ```