repo stringlengths 6 47 | file_url stringlengths 77 269 | file_path stringlengths 5 186 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 7
values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-07 08:35:43 2026-01-07 08:55:24 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/util/sprig/url_test.go | util/sprig/url_test.go | package sprig
import (
"testing"
"github.com/stretchr/testify/assert"
)
var urlTests = map[string]map[string]any{
"proto://auth@host:80/path?query#fragment": {
"fragment": "fragment",
"host": "host:80",
"hostname": "host",
"opaque": "",
"path": "/path",
"query": "query",
"scheme": "pr... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/util/sprig/reflect.go | util/sprig/reflect.go | package sprig
import (
"fmt"
"reflect"
)
// typeIs returns true if the src is the type named in target.
// It compares the type name of src with the target string.
//
// Parameters:
// - target: The type name to check against
// - src: The value whose type will be checked
//
// Returns:
// - bool: True if the... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/util/sprig/crypto.go | util/sprig/crypto.go | package sprig
import (
"crypto/sha1"
"crypto/sha256"
"crypto/sha512"
"encoding/hex"
"fmt"
"hash/adler32"
)
// sha512sum computes the SHA-512 hash of the input string and returns it as a hex-encoded string.
// This function can be used in templates to generate secure hashes of sensitive data.
//
// Example usage... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/util/sprig/dict.go | util/sprig/dict.go | package sprig
// get retrieves a value from a map by its key.
// If the key exists, returns the corresponding value.
// If the key doesn't exist, returns an empty string.
//
// Parameters:
// - d: The map to retrieve the value from
// - key: The key to look up
//
// Returns:
// - any: The value associated with t... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/util/sprig/flow_control_test.go | util/sprig/flow_control_test.go | package sprig
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func TestFail(t *testing.T) {
const msg = "This is an error!"
tpl := fmt.Sprintf(`{{fail "%s"}}`, msg)
_, err := runRaw(tpl, nil)
assert.Error(t, err)
assert.Contains(t, err.Error(), msg)
}
| go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/util/sprig/regex.go | util/sprig/regex.go | package sprig
import (
"regexp"
)
// regexMatch checks if a string matches a regular expression pattern.
// It ignores any errors that might occur during regex compilation.
//
// Parameters:
// - regex: The regular expression pattern to match against
// - s: The string to check
//
// Returns:
// - bool: True i... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/util/sprig/numeric.go | util/sprig/numeric.go | package sprig
import (
"fmt"
"math"
"math/rand"
"reflect"
"strconv"
"strings"
)
// toFloat64 converts a value to a 64-bit float.
// It handles various input types:
// - string: parsed as a float, returns 0 if parsing fails
// - integer types: converted to float64
// - unsigned integer types: converted to float6... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/util/sprig/functions.go | util/sprig/functions.go | package sprig
import (
"path"
"path/filepath"
"reflect"
"strings"
"text/template"
"time"
)
const (
loopExecutionLimit = 10_000 // Limit the number of loop executions to prevent execution from taking too long
stringLengthLimit = 100_000 // Limit the length of strings to prevent memory issues
sliceSizeLimit ... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/util/sprig/functions_test.go | util/sprig/functions_test.go | package sprig
import (
"bytes"
"fmt"
"testing"
"text/template"
"github.com/stretchr/testify/assert"
)
func TestBase(t *testing.T) {
assert.NoError(t, runt(`{{ base "foo/bar" }}`, "bar"))
}
func TestDir(t *testing.T) {
assert.NoError(t, runt(`{{ dir "foo/bar/baz" }}`, "foo/bar"))
}
func TestIsAbs(t *testing.... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/util/sprig/doc.go | util/sprig/doc.go | /*
Package sprig provides template functions for Go.
This package contains a number of utility functions for working with data
inside of Go `html/template` and `text/template` files.
To add these functions, use the `template.Funcs()` method:
t := template.New("foo").Funcs(sprig.FuncMap())
Note that you should add ... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/util/sprig/functions_linux_test.go | util/sprig/functions_linux_test.go | package sprig
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestOsBase(t *testing.T) {
assert.NoError(t, runt(`{{ osBase "foo/bar" }}`, "bar"))
}
func TestOsDir(t *testing.T) {
assert.NoError(t, runt(`{{ osDir "foo/bar/baz" }}`, "foo/bar"))
}
func TestOsIsAbs(t *testing.T) {
assert.NoError(t,... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/util/sprig/dict_test.go | util/sprig/dict_test.go | package sprig
import (
"strings"
"testing"
)
func TestDict(t *testing.T) {
tpl := `{{$d := dict 1 2 "three" "four" 5}}{{range $k, $v := $d}}{{$k}}{{$v}}{{end}}`
out, err := runRaw(tpl, nil)
if err != nil {
t.Error(err)
}
if len(out) != 12 {
t.Errorf("Expected length 12, got %d", len(out))
}
// dict does ... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/util/sprig/reflect_test.go | util/sprig/reflect_test.go | package sprig
import (
"testing"
)
type fixtureTO struct {
Name, Value string
}
func TestTypeOf(t *testing.T) {
f := &fixtureTO{"hello", "world"}
tpl := `{{typeOf .}}`
if err := runtv(tpl, "*sprig.fixtureTO", f); err != nil {
t.Error(err)
}
}
func TestKindOf(t *testing.T) {
tpl := `{{kindOf .}}`
f := fix... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/cmd/subscribe_test.go | cmd/subscribe_test.go | package cmd
import (
"fmt"
"github.com/stretchr/testify/require"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"strings"
"testing"
)
func TestCLI_Subscribe_Default_UserPass_Subscription_Token(t *testing.T) {
message := `{"id":"RXIQBFaieLVr","time":124,"expires":1124,"event":"message","topic":"mytopic",... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/cmd/publish_windows.go | cmd/publish_windows.go | package cmd
import (
"os"
)
func processExists(pid int) bool {
_, err := os.FindProcess(pid)
return err == nil
}
| go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/cmd/token_test.go | cmd/token_test.go | package cmd
import (
"fmt"
"github.com/stretchr/testify/require"
"github.com/urfave/cli/v2"
"heckel.io/ntfy/v2/server"
"heckel.io/ntfy/v2/test"
"regexp"
"testing"
)
func TestCLI_Token_AddListRemove(t *testing.T) {
s, conf, port := newTestServerWithAuth(t)
defer test.StopServer(t, s, port)
app, stdin, stdou... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/cmd/subscribe.go | cmd/subscribe.go | package cmd
import (
"errors"
"fmt"
"github.com/urfave/cli/v2"
"heckel.io/ntfy/v2/client"
"heckel.io/ntfy/v2/log"
"heckel.io/ntfy/v2/util"
"os"
"os/exec"
"os/user"
"path/filepath"
"sort"
"strings"
)
func init() {
commands = append(commands, cmdSubscribe)
}
const (
clientRootConfigFileUnixAbsolute = ... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/cmd/publish_unix.go | cmd/publish_unix.go | //go:build darwin || linux || dragonfly || freebsd || netbsd || openbsd
package cmd
import "syscall"
func processExists(pid int) bool {
err := syscall.Kill(pid, syscall.Signal(0))
return err == nil
}
| go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/cmd/token.go | cmd/token.go | //go:build !noserver
package cmd
import (
"errors"
"fmt"
"github.com/urfave/cli/v2"
"heckel.io/ntfy/v2/user"
"heckel.io/ntfy/v2/util"
"net/netip"
"time"
)
func init() {
commands = append(commands, cmdToken)
}
var flagsToken = append([]cli.Flag{}, flagsUser...)
var cmdToken = &cli.Command{
Name: "toke... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/cmd/serve.go | cmd/serve.go | //go:build !noserver
package cmd
import (
"errors"
"fmt"
"io/fs"
"math"
"net"
"net/netip"
"net/url"
"os"
"os/signal"
"strings"
"syscall"
"time"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v2/altsrc"
"heckel.io/ntfy/v2/log"
"heckel.io/ntfy/v2/payments"
"heckel.io/ntfy/v2/server"
"heckel.io/ntf... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | true |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/cmd/publish.go | cmd/publish.go | package cmd
import (
"errors"
"fmt"
"github.com/urfave/cli/v2"
"heckel.io/ntfy/v2/client"
"heckel.io/ntfy/v2/log"
"heckel.io/ntfy/v2/util"
"io"
"os"
"os/exec"
"path/filepath"
"strings"
"time"
)
func init() {
commands = append(commands, cmdPublish)
}
var flagsPublish = append(
append([]cli.Flag{}, flags... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/cmd/tier.go | cmd/tier.go | //go:build !noserver
package cmd
import (
"errors"
"fmt"
"github.com/urfave/cli/v2"
"heckel.io/ntfy/v2/user"
"heckel.io/ntfy/v2/util"
)
func init() {
commands = append(commands, cmdTier)
}
const (
defaultMessageLimit = 5000
defaultMessageExpiryDuration = "12h"
defaultEmailLimit ... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/cmd/access.go | cmd/access.go | //go:build !noserver
package cmd
import (
"errors"
"fmt"
"github.com/urfave/cli/v2"
"heckel.io/ntfy/v2/user"
"heckel.io/ntfy/v2/util"
)
func init() {
commands = append(commands, cmdAccess)
}
const (
userEveryone = "everyone"
)
var flagsAccess = append(
append([]cli.Flag{}, flagsUser...),
&cli.BoolFlag{Nam... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/cmd/webpush.go | cmd/webpush.go | //go:build !noserver && !nowebpush
package cmd
import (
"fmt"
"os"
"github.com/SherClockHolmes/webpush-go"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v2/altsrc"
)
var flagsWebPush = append(
[]cli.Flag{},
altsrc.NewStringFlag(&cli.StringFlag{Name: "output-file", Aliases: []string{"f"}, Usage: "write VA... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/cmd/config_loader.go | cmd/config_loader.go | package cmd
import (
"fmt"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v2/altsrc"
"gopkg.in/yaml.v2"
"heckel.io/ntfy/v2/util"
"os"
)
// initConfigFileInputSourceFunc is like altsrc.InitInputSourceWithContext and altsrc.NewYamlSourceFromFlagFunc, but checks
// if the config flag is exists and only loads it... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/cmd/subscribe_windows.go | cmd/subscribe_windows.go | package cmd
const (
scriptExt = "bat"
scriptHeader = ""
clientCommandDescriptionSuffix = `The default config file for all client commands is %AppData%\ntfy\client.yml.`
)
var (
scriptLauncher = []string{"cmd.exe", "/Q", "/C"}
)
func defaultClientConfigFile() (string, error)... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/cmd/publish_test.go | cmd/publish_test.go | package cmd
import (
"fmt"
"github.com/stretchr/testify/require"
"heckel.io/ntfy/v2/test"
"heckel.io/ntfy/v2/util"
"net/http"
"net/http/httptest"
"os"
"os/exec"
"path/filepath"
"strconv"
"strings"
"testing"
"time"
)
func TestCLI_Publish_Subscribe_Poll_Real_Server(t *testing.T) {
testMessage := util.Rand... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/cmd/subscribe_unix.go | cmd/subscribe_unix.go | //go:build linux || dragonfly || freebsd || netbsd || openbsd
package cmd
const (
scriptExt = "sh"
scriptHeader = "#!/bin/sh\n"
clientCommandDescriptionSuffix = `The default config file for all client commands is /etc/ntfy/client.yml (if root user),
or ~/.config/ntfy/client.y... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/cmd/serve_test.go | cmd/serve_test.go | package cmd
import (
"fmt"
"math/rand"
"os"
"os/exec"
"path/filepath"
"testing"
"time"
"github.com/gorilla/websocket"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"heckel.io/ntfy/v2/client"
"heckel.io/ntfy/v2/test"
"heckel.io/ntfy/v2/user"
"heckel.io/ntfy/v2/util"
)
func T... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/cmd/access_test.go | cmd/access_test.go | package cmd
import (
"fmt"
"github.com/stretchr/testify/require"
"github.com/urfave/cli/v2"
"heckel.io/ntfy/v2/server"
"heckel.io/ntfy/v2/test"
"testing"
)
func TestCLI_Access_Show(t *testing.T) {
s, conf, port := newTestServerWithAuth(t)
defer test.StopServer(t, s, port)
app, _, stdout, _ := newTestApp()
... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/cmd/app_test.go | cmd/app_test.go | package cmd
import (
"bytes"
"encoding/json"
"github.com/urfave/cli/v2"
"heckel.io/ntfy/v2/client"
"heckel.io/ntfy/v2/log"
"os"
"strings"
"testing"
)
// This only contains helpers so far
func TestMain(m *testing.M) {
log.SetLevel(log.ErrorLevel)
os.Exit(m.Run())
}
func newTestApp() (*cli.App, *bytes.Buffe... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/cmd/config_loader_test.go | cmd/config_loader_test.go | package cmd
import (
"github.com/stretchr/testify/require"
"os"
"path/filepath"
"testing"
)
func TestNewYamlSourceFromFile(t *testing.T) {
filename := filepath.Join(t.TempDir(), "server.yml")
contents := `
# Normal options
listen-https: ":10443"
# Note the underscore!
listen_http: ":1080"
# OMG this is allowe... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/cmd/subscribe_darwin.go | cmd/subscribe_darwin.go | package cmd
const (
scriptExt = "sh"
scriptHeader = "#!/bin/sh\n"
clientCommandDescriptionSuffix = `The default config file for all client commands is /etc/ntfy/client.yml (if root user),
or "~/Library/Application Support/ntfy/client.yml" for all other users.`
)
var (
script... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/cmd/user.go | cmd/user.go | //go:build !noserver
package cmd
import (
"crypto/subtle"
"errors"
"fmt"
"heckel.io/ntfy/v2/server"
"heckel.io/ntfy/v2/user"
"os"
"strings"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v2/altsrc"
"heckel.io/ntfy/v2/util"
)
const (
tierReset = "-"
)
func init() {
commands = append(commands, cmdUser... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/cmd/app.go | cmd/app.go | // Package cmd provides the ntfy CLI application
package cmd
import (
"fmt"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v2/altsrc"
"heckel.io/ntfy/v2/log"
"os"
"regexp"
)
const (
categoryClient = "Client commands"
categoryServer = "Server commands"
)
var commands = make([]*cli.Command, 0)
var flagsDef... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/cmd/webpush_test.go | cmd/webpush_test.go | package cmd
import (
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
"github.com/urfave/cli/v2"
"heckel.io/ntfy/v2/server"
)
func TestCLI_WebPush_GenerateKeys(t *testing.T) {
app, _, stdout, _ := newTestApp()
require.Nil(t, runWebPushCommand(app, server.NewConfig(), "keys"))
require.Contains(... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/cmd/tier_test.go | cmd/tier_test.go | package cmd
import (
"github.com/stretchr/testify/require"
"github.com/urfave/cli/v2"
"heckel.io/ntfy/v2/server"
"heckel.io/ntfy/v2/test"
"testing"
)
func TestCLI_Tier_AddListChangeDelete(t *testing.T) {
s, conf, port := newTestServerWithAuth(t)
defer test.StopServer(t, s, port)
app, _, stdout, _ := newTestA... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/cmd/user_test.go | cmd/user_test.go | package cmd
import (
"github.com/stretchr/testify/require"
"github.com/urfave/cli/v2"
"heckel.io/ntfy/v2/server"
"heckel.io/ntfy/v2/test"
"heckel.io/ntfy/v2/user"
"os"
"path/filepath"
"testing"
)
func TestCLI_User_Add(t *testing.T) {
s, conf, port := newTestServerWithAuth(t)
defer test.StopServer(t, s, port... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/tools/fbsend/main.go | tools/fbsend/main.go | //go:build !nofirebase
package main
import (
"context"
firebase "firebase.google.com/go/v4"
"firebase.google.com/go/v4/messaging"
"flag"
"fmt"
"google.golang.org/api/option"
"os"
"strings"
)
func main() {
conffile := flag.String("config", "/etc/fbsend/fbsend.json", "config file")
flag.Parse()
if flag.NArg... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/tools/loadgen/main.go | tools/loadgen/main.go | package main
import (
"bufio"
"context"
"fmt"
"net/http"
"os"
"time"
)
func main() {
baseURL := "https://staging.ntfy.sh"
if len(os.Args) > 1 {
baseURL = os.Args[1]
}
for i := 0; i < 2000; i++ {
go subscribe(i, baseURL)
}
time.Sleep(5 * time.Second)
for i := 0; i < 2000; i++ {
go func(worker int) {... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/user/manager_test.go | user/manager_test.go | package user
import (
"database/sql"
"fmt"
"github.com/stretchr/testify/require"
"golang.org/x/crypto/bcrypt"
"heckel.io/ntfy/v2/util"
"net/netip"
"path/filepath"
"strings"
"testing"
"time"
)
const minBcryptTimingMillis = int64(40) // Ideally should be >100ms, but this should also run on a Raspberry Pi with... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | true |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/user/types_test.go | user/types_test.go | package user
import (
"github.com/stretchr/testify/require"
"testing"
)
func TestPermission(t *testing.T) {
require.Equal(t, PermissionReadWrite, NewPermission(true, true))
require.Equal(t, PermissionRead, NewPermission(true, false))
require.Equal(t, PermissionWrite, NewPermission(false, true))
require.Equal(t,... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/user/types.go | user/types.go | package user
import (
"errors"
"heckel.io/ntfy/v2/log"
"heckel.io/ntfy/v2/payments"
"net/netip"
"strings"
"time"
)
// User is a struct that represents a user
type User struct {
ID string
Name string
Hash string // Password hash (bcrypt)
Token string // Only set if token was used... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/user/util.go | user/util.go | package user
import (
"golang.org/x/crypto/bcrypt"
"heckel.io/ntfy/v2/util"
"regexp"
"strings"
)
var (
allowedUsernameRegex = regexp.MustCompile(`^[-_.+@a-zA-Z0-9]+$`) // Does not include Everyone (*)
allowedTopicRegex = regexp.MustCompile(`^[-_A-Za-z0-9]{1,64}$`) // No '*'
allowedTopicPatternRe... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/user/manager.go | user/manager.go | // Package user deals with authentication and authorization against topics
package user
import (
"database/sql"
"encoding/json"
"errors"
"fmt"
"github.com/mattn/go-sqlite3"
"golang.org/x/crypto/bcrypt"
"heckel.io/ntfy/v2/log"
"heckel.io/ntfy/v2/payments"
"heckel.io/ntfy/v2/util"
"net/netip"
"path/filepath"
... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | true |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/test/util.go | test/util.go | package test
import (
"net"
"strconv"
"testing"
"time"
)
// WaitForPortUp waits up to 7s for a port to come up and fails t if that fails
func WaitForPortUp(t *testing.T, port int) {
success := false
for i := 0; i < 500; i++ {
startTime := time.Now()
conn, _ := net.DialTimeout("tcp", net.JoinHostPort("127.0.... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/test/server.go | test/server.go | package test
import (
"fmt"
"heckel.io/ntfy/v2/server"
"math/rand"
"net/http"
"path/filepath"
"testing"
)
// StartServer starts a server.Server with a random port and waits for the server to be up
func StartServer(t *testing.T) (*server.Server, int) {
return StartServerWithConfig(t, server.NewConfig())
}
// S... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/test/test.go | test/test.go | // Package test provides test helpers for unit and integration tests.
// This code is not meant to be used outside of tests.
package test
| go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/examples/publish-go/main.go | examples/publish-go/main.go | package main
import (
"log"
"net/http"
"strings"
)
func main() {
// Without additional headers (priority, tags, title), it's a one liner.
// Check out https://ntfy.sh/mytopic in your browser after running this.
http.Post("https://ntfy.sh/mytopic", "text/plain", strings.NewReader("Backup successful 😀"))
// If... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/examples/subscribe-go/main.go | examples/subscribe-go/main.go | package main
import (
"bufio"
"log"
"net/http"
)
func main() {
resp, err := http.Get("https://ntfy.sh/phil_alerts/json")
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
scanner := bufio.NewScanner(resp.Body)
for scanner.Scan() {
println(scanner.Text())
}
}
| go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/server/server_matrix_test.go | server/server_matrix_test.go | package server
import (
"net/http"
"net/http/httptest"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
func TestMatrix_NewRequestFromMatrixJSON_Success(t *testing.T) {
baseURL := "https://ntfy.sh"
maxLength := 4096
body := `{"notification":{"content":{"body":"I'm floating in a most peculiar way."... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/server/actions.go | server/actions.go | package server
import (
"encoding/json"
"errors"
"fmt"
"heckel.io/ntfy/v2/util"
"regexp"
"strings"
"unicode/utf8"
)
const (
actionIDLength = 10
actionEOF = rune(0)
actionsMax = 3
)
const (
actionView = "view"
actionBroadcast = "broadcast"
actionHTTP = "http"
)
var (
actionsAll ... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/server/smtp_server_test.go | server/smtp_server_test.go | package server
import (
"bufio"
"github.com/emersion/go-smtp"
"github.com/stretchr/testify/require"
"io"
"net"
"net/http"
"strings"
"testing"
"time"
)
func TestSmtpBackend_Multipart(t *testing.T) {
email := `EHLO example.com
MAIL FROM: phil@example.com
RCPT TO: ntfy-mytopic@ntfy.sh
DATA
MIME-Version: 1.0
Da... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | true |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/server/actions_test.go | server/actions_test.go | package server
import (
"github.com/stretchr/testify/require"
"testing"
)
func TestParseActions(t *testing.T) {
actions, err := parseActions("[]")
require.Nil(t, err)
require.Empty(t, actions)
// Basic test
actions, err = parseActions("action=http, label=Open door, url=https://door.lan/open; view, Show portal... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/server/server_payments_test.go | server/server_payments_test.go | //go:build !nopayments
package server
import (
"encoding/json"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"github.com/stripe/stripe-go/v74"
"golang.org/x/time/rate"
"heckel.io/ntfy/v2/payments"
"heckel.io/ntfy/v2/user"
"heckel.io/ntfy/v2/util"
"io"
"net/netip"
"path/filepath"
... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/server/server_firebase.go | server/server_firebase.go | //go:build !nofirebase
package server
import (
"context"
"encoding/json"
"errors"
firebase "firebase.google.com/go/v4"
"firebase.google.com/go/v4/messaging"
"fmt"
"google.golang.org/api/option"
"heckel.io/ntfy/v2/user"
"heckel.io/ntfy/v2/util"
"strings"
)
const (
// FirebaseAvailable is a constant used to... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/server/server_manager.go | server/server_manager.go | package server
import (
"heckel.io/ntfy/v2/log"
"heckel.io/ntfy/v2/util"
"strings"
)
func (s *Server) execManager() {
// WARNING: Make sure to only selectively lock with the mutex, and be aware that this
// there is no mutex for the entire function.
// Prune all the things
s.pruneVisitors()
s.pruneT... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/server/message_cache_test.go | server/message_cache_test.go | package server
import (
"database/sql"
"fmt"
"github.com/stretchr/testify/assert"
"net/netip"
"path/filepath"
"sync"
"testing"
"time"
"github.com/stretchr/testify/require"
)
func TestSqliteCache_Messages(t *testing.T) {
testCacheMessages(t, newSqliteTestCache(t))
}
func TestMemCache_Messages(t *testing.T)... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/server/server_payments_dummy.go | server/server_payments_dummy.go | //go:build nopayments
package server
import (
"net/http"
)
type stripeAPI interface {
CancelSubscription(id string) (string, error)
}
func newStripeAPI() stripeAPI {
return nil
}
func (s *Server) fetchStripePrices() (map[string]int64, error) {
return nil, errHTTPNotFound
}
func (s *Server) handleBillingTiersG... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/server/types.go | server/types.go | package server
import (
"net/http"
"net/netip"
"time"
"heckel.io/ntfy/v2/log"
"heckel.io/ntfy/v2/user"
"heckel.io/ntfy/v2/util"
)
// List of possible events
const (
openEvent = "open"
keepaliveEvent = "keepalive"
messageEvent = "message"
pollRequestEvent = "poll_request"
)
const (
messageIDL... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/server/server_twilio.go | server/server_twilio.go | package server
import (
"bytes"
"encoding/xml"
"fmt"
"heckel.io/ntfy/v2/log"
"heckel.io/ntfy/v2/user"
"heckel.io/ntfy/v2/util"
"io"
"net/http"
"net/url"
"strings"
)
const (
twilioCallFormat = `
<Response>
<Pause length="1"/>
<Say loop="3">
You have a message from notify on topic %s. Message:
<break t... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/server/server_twilio_test.go | server/server_twilio_test.go | package server
import (
"github.com/stretchr/testify/require"
"heckel.io/ntfy/v2/user"
"heckel.io/ntfy/v2/util"
"io"
"net/http"
"net/http/httptest"
"sync/atomic"
"testing"
)
func TestServer_Twilio_Call_Add_Verify_Call_Delete_Success(t *testing.T) {
var called, verified atomic.Bool
var code atomic.Pointer[st... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/server/server_test.go | server/server_test.go | package server
import (
"bufio"
"context"
"crypto/rand"
_ "embed"
"encoding/base64"
"encoding/json"
"fmt"
"golang.org/x/crypto/bcrypt"
"heckel.io/ntfy/v2/user"
"io"
"net/http"
"net/http/httptest"
"net/netip"
"os"
"path/filepath"
"runtime/debug"
"strings"
"sync"
"sync/atomic"
"testing"
"time"
"gi... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | true |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/server/errors.go | server/errors.go | package server
import (
"encoding/json"
"fmt"
"heckel.io/ntfy/v2/log"
"net/http"
)
// errHTTP is a generic HTTP error for any non-200 HTTP error
type errHTTP struct {
Code int `json:"code,omitempty"`
HTTPCode int `json:"http"`
Message string `json:"error"`
Link string `json:"link,omitempty"`
c... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/server/server_payments.go | server/server_payments.go | //go:build !nopayments
package server
import (
"bytes"
"errors"
"fmt"
"github.com/stripe/stripe-go/v74"
portalsession "github.com/stripe/stripe-go/v74/billingportal/session"
"github.com/stripe/stripe-go/v74/checkout/session"
"github.com/stripe/stripe-go/v74/customer"
"github.com/stripe/stripe-go/v74/price"
"... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/server/config.go | server/config.go | package server
import (
"io/fs"
"net/netip"
"time"
"heckel.io/ntfy/v2/user"
)
// Defines default config settings (excluding limits, see below)
const (
DefaultListenHTTP = ":80"
DefaultConfigFile = "/etc/ntfy/server.yml"
DefaultTemplateDir ... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/server/smtp_sender_test.go | server/smtp_sender_test.go | package server
import (
"github.com/stretchr/testify/require"
"testing"
)
func TestFormatMail_Basic(t *testing.T) {
actual, _ := formatMail("https://ntfy.sh", "1.2.3.4", "ntfy@ntfy.sh", "phil@example.com", &message{
ID: "abc",
Time: 1640382204,
Event: "message",
Topic: "alerts",
Message: "A s... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/server/server_account.go | server/server_account.go | package server
import (
"encoding/json"
"errors"
"heckel.io/ntfy/v2/log"
"heckel.io/ntfy/v2/user"
"heckel.io/ntfy/v2/util"
"net/http"
"net/netip"
"strings"
"time"
)
const (
syncTopicAccountSyncEvent = "sync"
tokenExpiryDuration = 72 * time.Hour // Extend tokens by this much
)
func (s *Server) handle... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/server/server_webpush_test.go | server/server_webpush_test.go | //go:build !nowebpush
package server
import (
"encoding/json"
"fmt"
"github.com/SherClockHolmes/webpush-go"
"github.com/stretchr/testify/require"
"heckel.io/ntfy/v2/user"
"heckel.io/ntfy/v2/util"
"io"
"net/http"
"net/http/httptest"
"net/netip"
"path/filepath"
"strings"
"sync/atomic"
"testing"
"time"
)
... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/server/webpush_store_test.go | server/webpush_store_test.go | package server
import (
"fmt"
"github.com/stretchr/testify/require"
"net/netip"
"path/filepath"
"testing"
"time"
)
func TestWebPushStore_UpsertSubscription_SubscriptionsForTopic(t *testing.T) {
webPush := newTestWebPushStore(t)
defer webPush.Close()
require.Nil(t, webPush.UpsertSubscription(testWebPushEndpo... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/server/util.go | server/util.go | package server
import (
"context"
"errors"
"fmt"
"io"
"mime"
"net/http"
"net/netip"
"regexp"
"strings"
"heckel.io/ntfy/v2/util"
)
var (
mimeDecoder mime.WordDecoder
// priorityHeaderIgnoreRegex matches specific patterns of the "Priority" header (RFC 9218), so that it can be ignored
priorityHeaderIgnore... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/server/message_cache.go | server/message_cache.go | package server
import (
"database/sql"
"encoding/json"
"errors"
"fmt"
"net/netip"
"path/filepath"
"strings"
"sync"
"time"
_ "github.com/mattn/go-sqlite3" // SQLite driver
"heckel.io/ntfy/v2/log"
"heckel.io/ntfy/v2/util"
)
var (
errUnexpectedMessageType = errors.New("unexpected message type")
errMessage... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/server/file_cache.go | server/file_cache.go | package server
import (
"errors"
"fmt"
"heckel.io/ntfy/v2/log"
"heckel.io/ntfy/v2/util"
"io"
"os"
"path/filepath"
"regexp"
"sync"
)
var (
fileIDRegex = regexp.MustCompile(fmt.Sprintf(`^[-_A-Za-z0-9]{%d}$`, messageIDLength))
errInvalidFileID = errors.New("invalid file ID")
errFileExists = errors.Ne... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/server/server_admin.go | server/server_admin.go | package server
import (
"errors"
"heckel.io/ntfy/v2/user"
"net/http"
)
func (s *Server) handleUsersGet(w http.ResponseWriter, r *http.Request, v *visitor) error {
users, err := s.userManager.Users()
if err != nil {
return err
}
grants, err := s.userManager.AllGrants()
if err != nil {
return err
}
usersR... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/server/server_middleware.go | server/server_middleware.go | package server
import (
"net/http"
"heckel.io/ntfy/v2/util"
)
type contextKey int
const (
contextRateVisitor contextKey = iota + 2586
contextTopic
contextMatrixPushKey
)
func (s *Server) limitRequests(next handleFunc) handleFunc {
return func(w http.ResponseWriter, r *http.Request, v *visitor) error {
if u... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/server/smtp_server.go | server/smtp_server.go | package server
import (
"bytes"
"encoding/base64"
"errors"
"fmt"
"io"
"mime"
"mime/multipart"
"mime/quotedprintable"
"net"
"net/http"
"net/http/httptest"
"net/mail"
"regexp"
"strings"
"sync"
"github.com/emersion/go-smtp"
"github.com/microcosm-cc/bluemonday"
)
var (
errInvalidDomain = error... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/server/server_webpush.go | server/server_webpush.go | //go:build !nowebpush
package server
import (
"encoding/json"
"fmt"
"net/http"
"regexp"
"strings"
"github.com/SherClockHolmes/webpush-go"
"heckel.io/ntfy/v2/log"
"heckel.io/ntfy/v2/user"
)
const (
// WebPushAvailable is a constant used to indicate that WebPush support is available.
// It can be disabled w... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/server/log.go | server/log.go | package server
import (
"fmt"
"github.com/emersion/go-smtp"
"github.com/gorilla/websocket"
"heckel.io/ntfy/v2/log"
"heckel.io/ntfy/v2/util"
"net/http"
"strings"
"unicode/utf8"
)
// Log tags
const (
tagStartup = "startup"
tagHTTP = "http"
tagPublish = "publish"
tagSubscribe = "subscrib... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/server/config_test.go | server/config_test.go | package server_test
import (
"github.com/stretchr/testify/assert"
"heckel.io/ntfy/v2/server"
"testing"
)
func TestConfig_New(t *testing.T) {
c := server.NewConfig()
assert.Equal(t, ":80", c.ListenHTTP)
assert.Equal(t, server.DefaultKeepaliveInterval, c.KeepaliveInterval)
}
| go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/server/server_admin_test.go | server/server_admin_test.go | package server
import (
"github.com/stretchr/testify/require"
"heckel.io/ntfy/v2/user"
"heckel.io/ntfy/v2/util"
"sync/atomic"
"testing"
"time"
)
func TestUser_AddRemove(t *testing.T) {
s := newTestServer(t, newTestConfigWithAuthFile(t))
defer s.closeDatabases()
// Create admin, tier
require.Nil(t, s.userMa... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/server/server_account_test.go | server/server_account_test.go | package server
import (
"fmt"
"github.com/stretchr/testify/require"
"heckel.io/ntfy/v2/log"
"heckel.io/ntfy/v2/user"
"heckel.io/ntfy/v2/util"
"io"
"net/netip"
"path/filepath"
"strings"
"testing"
"time"
)
func TestAccount_Signup_Success(t *testing.T) {
conf := newTestConfigWithAuthFile(t)
conf.EnableSignu... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/server/server_firebase_test.go | server/server_firebase_test.go | //go:build !nofirebase
package server
import (
"encoding/json"
"errors"
"fmt"
"heckel.io/ntfy/v2/user"
"net/netip"
"strings"
"sync"
"testing"
"firebase.google.com/go/v4/messaging"
"github.com/stretchr/testify/require"
)
type testAuther struct {
Allow bool
}
var _ user.Auther = (*testAuther)(nil)
func (... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/server/server_metrics.go | server/server_metrics.go | package server
import (
"github.com/prometheus/client_golang/prometheus"
)
var (
metricMessagesPublishedSuccess prometheus.Counter
metricMessagesPublishedFailure prometheus.Counter
metricMessagesCached prometheus.Gauge
metricMessagePublishDurationMillis prometheus.Gauge
metricFirebasePubli... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/server/server.go | server/server.go | package server
import (
"bytes"
"context"
"crypto/sha256"
"embed"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"io"
"net"
"net/http"
"net/http/pprof"
"net/netip"
"net/url"
"os"
"path"
"path/filepath"
"regexp"
"sort"
"strconv"
"strings"
"sync"
"text/template"
"time"
"unicode/utf8"
"github... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | true |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/server/server_webpush_dummy.go | server/server_webpush_dummy.go | //go:build nowebpush
package server
import (
"net/http"
)
const (
// WebPushAvailable is a constant used to indicate that WebPush support is available.
// It can be disabled with the 'nowebpush' build tag.
WebPushAvailable = false
)
func (s *Server) handleWebPushUpdate(w http.ResponseWriter, r *http.Request, v ... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/server/topic.go | server/topic.go | package server
import (
"math/rand"
"sync"
"time"
"heckel.io/ntfy/v2/log"
"heckel.io/ntfy/v2/util"
)
const (
// topicExpungeAfter defines how long a topic is active before it is removed from memory.
// This must be larger than matrixRejectPushKeyForUnifiedPushTopicWithoutRateVisitorAfter to give
// time for ... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/server/server_firebase_dummy.go | server/server_firebase_dummy.go | //go:build nofirebase
package server
import (
"errors"
"heckel.io/ntfy/v2/user"
)
const (
// FirebaseAvailable is a constant used to indicate that Firebase support is available.
// It can be disabled with the 'nofirebase' build tag.
FirebaseAvailable = false
)
var (
errFirebaseNotAvailable = errors.New("... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/server/topic_test.go | server/topic_test.go | package server
import (
"math/rand"
"sync/atomic"
"testing"
"time"
"github.com/stretchr/testify/require"
)
func TestTopic_CancelSubscribersExceptUser(t *testing.T) {
subFn := func(v *visitor, msg *message) error {
return nil
}
canceled1 := atomic.Bool{}
cancelFn1 := func() {
canceled1.Store(true)
}
ca... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/server/server_manager_test.go | server/server_manager_test.go | package server
import (
"github.com/stretchr/testify/require"
"testing"
)
func TestServer_Manager_Prune_Messages_Without_Attachments_DoesNotPanic(t *testing.T) {
// Tests that the manager runs without attachment-cache-dir set, see #617
c := newTestConfig(t)
c.AttachmentCacheDir = ""
s := newTestServer(t, c)
/... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/server/server_matrix.go | server/server_matrix.go | package server
import (
"bytes"
"encoding/json"
"fmt"
"heckel.io/ntfy/v2/util"
"io"
"net/http"
"strings"
"time"
)
// Matrix Push Gateway / UnifiedPush / ntfy integration:
//
// ntfy implements a Matrix Push Gateway (as defined in https://spec.matrix.org/v1.2/push-gateway-api/),
// in combination with UnifiedP... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/server/visitor.go | server/visitor.go | package server
import (
"fmt"
"net/netip"
"sync"
"time"
"golang.org/x/time/rate"
"heckel.io/ntfy/v2/log"
"heckel.io/ntfy/v2/user"
"heckel.io/ntfy/v2/util"
)
const (
// oneDay is an approximation of a day as a time.Duration
oneDay = 24 * time.Hour
// visitorExpungeAfter defines how long a visitor is activ... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/server/util_test.go | server/util_test.go | package server
import (
"bytes"
"crypto/rand"
"fmt"
"heckel.io/ntfy/v2/user"
"net/http"
"net/netip"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
func TestReadBoolParam(t *testing.T) {
r, _ := http.NewRequest("GET", "https://ntfy.sh/mytopic?up=1&firebase=no", nil)
up := readBoolParam(r, fals... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/server/webpush_store.go | server/webpush_store.go | package server
import (
"database/sql"
"errors"
"heckel.io/ntfy/v2/util"
"net/netip"
"time"
_ "github.com/mattn/go-sqlite3" // SQLite driver
)
const (
subscriptionIDPrefix = "wps_"
subscriptionIDLength = 10
subscriptionEndpointLimitPerSubscriberIP = 10
)
var (
errWe... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/server/smtp_sender.go | server/smtp_sender.go | package server
import (
_ "embed" // required by go:embed
"encoding/json"
"fmt"
"mime"
"net"
"net/smtp"
"strings"
"sync"
"time"
"heckel.io/ntfy/v2/log"
"heckel.io/ntfy/v2/util"
)
type mailer interface {
Send(v *visitor, m *message, to string) error
Counts() (total int64, success int64, failure int64)
}
... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/server/file_cache_test.go | server/file_cache_test.go | package server
import (
"bytes"
"fmt"
"github.com/stretchr/testify/require"
"heckel.io/ntfy/v2/util"
"os"
"strings"
"testing"
)
var (
oneKilobyteArray = make([]byte, 1024)
)
func TestFileCache_Write_Success(t *testing.T) {
dir, c := newTestFileCache(t)
size, err := c.Write("abcdefghijkl", strings.NewReader... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/client/client.go | client/client.go | // Package client provides a ntfy client to publish and subscribe to topics
package client
import (
"bufio"
"context"
"encoding/json"
"errors"
"fmt"
"heckel.io/ntfy/v2/log"
"heckel.io/ntfy/v2/util"
"io"
"net/http"
"regexp"
"strings"
"sync"
"time"
)
const (
// MessageEvent identifies a message event
Mes... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/client/config.go | client/config.go | package client
import (
"gopkg.in/yaml.v2"
"heckel.io/ntfy/v2/log"
"os"
)
const (
// DefaultBaseURL is the base URL used to expand short topic names
DefaultBaseURL = "https://ntfy.sh"
)
// Config is the config struct for a Client
type Config struct {
DefaultHost string `yaml:"default-host"`
DefaultUs... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/client/client_test.go | client/client_test.go | package client_test
import (
"fmt"
"github.com/stretchr/testify/require"
"heckel.io/ntfy/v2/client"
"heckel.io/ntfy/v2/log"
"heckel.io/ntfy/v2/test"
"os"
"testing"
"time"
)
func TestMain(m *testing.M) {
log.SetLevel(log.ErrorLevel)
os.Exit(m.Run())
}
func TestClient_Publish_Subscribe(t *testing.T) {
s, po... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/client/config_test.go | client/config_test.go | package client_test
import (
"github.com/stretchr/testify/require"
"heckel.io/ntfy/v2/client"
"os"
"path/filepath"
"testing"
)
func TestConfig_Load(t *testing.T) {
filename := filepath.Join(t.TempDir(), "client.yml")
require.Nil(t, os.WriteFile(filename, []byte(`
default-host: http://localhost
default-user: ph... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
binwiederhier/ntfy | https://github.com/binwiederhier/ntfy/blob/e18d64933fdfad2710ad8a930e1f880c2714cb52/client/options.go | client/options.go | package client
import (
"fmt"
"heckel.io/ntfy/v2/util"
"net/http"
"strings"
"time"
)
// RequestOption is a generic request option that can be added to Client calls
type RequestOption = func(r *http.Request) error
// PublishOption is an option that can be passed to the Client.Publish call
type PublishOption = Re... | go | Apache-2.0 | e18d64933fdfad2710ad8a930e1f880c2714cb52 | 2026-01-07T08:37:03.915928Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.