funcy

package module
v0.25.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 3, 2026 License: MIT Imports: 16 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

funcy

Tools to make sserverless functions a little simpler.

Why

I build so-called serverless apps on Scaleway and similar, and their build process is a tad peculiar. Sharing code between functions can get complicated, so this is a repository of functions I commonly use in this process.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Base6424 added in v0.8.0

func Base6424(src string) string

Base6424 is used by some password hashing algorithms.

func GenerateString added in v0.8.0

func GenerateString(n int) string

GenerateString of length n.

func GenerateToken added in v0.8.0

func GenerateToken(username string) string

GenerateToken creates a token for the user session.

Types

type Client

type Client struct {
	// Client for S3 operations.
	*s3.Client
	// W is the HTTP response writer.
	W http.ResponseWriter
	// R is the HTTP request.
	R *http.Request
	// Conn is the PostgreSQL connection.
	Conn *pgx.Conn
}

Client is a wrapper around the S3 client and authentication tokens.

func NewClient

func NewClient(w http.ResponseWriter, r *http.Request) *Client

NewClient creates a client.

func (*Client) Authenticate added in v0.8.0

func (cl *Client) Authenticate(username, password string, asAdmin bool) bool

Authenticate checks the user's password and updates the session if valid, and the user is an admin.

func (*Client) CheckAdmin added in v0.11.0

func (cl *Client) CheckAdmin(username string) bool

CheckAdmin checks if a user is an admin.

func (*Client) ClearCookie added in v0.4.0

func (cl *Client) ClearCookie(name string)

ClearCookie in HTTP response.

func (*Client) ClearSession added in v0.16.0

func (cl *Client) ClearSession()

ClearSession removes the session cookies of the current user.

func (*Client) GetConfig added in v0.19.0

func (cl *Client) GetConfig(key string) string

GetConfig returns a key's value from the config table.

func (*Client) GetCookie added in v0.8.0

func (cl *Client) GetCookie(name string) string

GetCookie from HTTP request.

func (*Client) GetFile

func (cl *Client) GetFile(fn string) []byte

GetFile from storage.

func (*Client) InvalidateAdminSessions added in v0.17.0

func (cl *Client) InvalidateAdminSessions(username string)

InvalidateAdminSessions removes all admin sessions for a user.

func (*Client) InvalidateSessions added in v0.17.0

func (cl *Client) InvalidateSessions(username string)

InvalidateSessions removes all sessions for a user.

func (*Client) IsAdmin added in v0.8.0

func (cl *Client) IsAdmin() bool

IsAdmin checks if the user is an admin.

func (*Client) IsAuthenticated added in v0.8.0

func (cl *Client) IsAuthenticated(asAdmin bool) bool

IsAuthenticated checks if the user is logged in.

func (*Client) LoadTemplate added in v0.18.0

func (cl *Client) LoadTemplate(fn string, data any) []byte

LoadTemplate from S3 storage.

func (*Client) LoadTemplates added in v0.19.2

func (cl *Client) LoadTemplates(files []string, data any) []byte

LoadTemplates from S3 storage.

func (*Client) PutFile

func (cl *Client) PutFile(fn string, data []byte)

PutFile to storage.

func (*Client) Query added in v0.19.2

func (cl *Client) Query(sql string, args ...any) (pgx.Rows, error)

Query is a wrapper around the pgx.Query function.

func (*Client) QueryRow added in v0.19.2

func (cl *Client) QueryRow(sql string, args ...any) pgx.Row

QueryRow is a wrapper around the pgx.QueryRow function.

func (*Client) Redirect added in v0.10.0

func (cl *Client) Redirect(url string, code int)

Redirect to URL.

func (*Client) SetCookie added in v0.3.0

func (cl *Client) SetCookie(name, value string)

SetCookie in HTTP response.

func (*Client) SetHeader added in v0.9.0

func (cl *Client) SetHeader(name, value string)

SetHeader in HTTP response.

func (*Client) UpdateAdminSession added in v0.19.2

func (cl *Client) UpdateAdminSession(username string)

UpdateAdminSession by extending the expiry.

func (*Client) UpdateSession added in v0.19.2

func (cl *Client) UpdateSession(username string)

UpdateSession for a user by extending the expiry.

func (*Client) Write added in v0.2.0

func (cl *Client) Write(s string)

Write string to HTTP.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址